using Cysharp.Threading.Tasks; using DG.Tweening; using TMPro; using UnityEngine; public class UIScrollNoticeController : UITipsBase { //UI GameObj ///Auto Gen Start/// public TMP_Text Text_Content; ///Auto Gen End/// // deal with input data public override void PreLoad(object data = null) { } // Use this for initialization public override void OnInit() { //bind UI GameObj UIScrollNoticeBinder.GetComponents(this); var panel = Text_Content.transform.parent.gameObject; var rect = panel.GetComponent(); if (rect != null) { rect.anchorMax = new(1, 1); rect.anchorMin = new(1, 1); rect.pivot = new(0, 0.5f); rect.anchoredPosition = new Vector2(0, -195); } } //invoke when open window protected override void OnShowWindow(object data = null) { base.OnShowWindow(data); SetContent(data as string); AsynScrollAnim(); } //invoke when reload window protected override void OnReloadWindow(object data = null) { } //invoke when close window protected override void OnHideWindow() { } //invoke when destroy public override void OnRelease() { base.OnRelease(); ScrollNoticeManager.Instance.ShowFinished(); } protected override void SetContent(string content) { Text_Content.text = content; } async void AsynScrollAnim() { float duration = 0; var panel = Text_Content.transform.parent.gameObject; var rect = panel.GetComponent(); if (rect == null) { DebugUtil.LogError("ScrollAnim rect is null"); return; } float time = (Screen.width + rect.rect.width) / 100f;//20f; while (true) { duration += Time.deltaTime; float progress = duration / time; if (duration >= time) { CloseWindow(); break; } rect.anchorMax = new Vector2(1 - progress, 1); rect.anchorMin = new Vector2(1 - progress, 1); rect.pivot = new Vector2(progress, 0.5f); await UniTask.Yield(); } } }