//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Friday, October 27, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class MarqueeWin : Window { [SerializeField] RectTransform m_ContainerMarquee; [SerializeField] RichText marqueeText; [SerializeField] RectTransform marqueeBg; [SerializeField] TweenCurve tweenCurve; [SerializeField] UIEffect m_Effect; #region 参数 Vector3 fromPos; Vector3 toPos; float m_Time; float duration; int presentCnt = 0; int loopCnt = 1; #endregion [SerializeField] float speed = 5.0f; Coroutine cacheCoroutine = null; #region Built-in protected override void BindController() { fromPos = marqueeText.rectTransform.localPosition; } protected override void AddListeners() { } protected override void OnPreOpen() { m_Time = 0; ServerTipDetails.OnTweening = false; presentCnt = 0; m_ContainerMarquee.SetActive(false); if (cacheCoroutine != null) { StopCoroutine(cacheCoroutine); cacheCoroutine = null; } } protected override void OnActived() { base.OnActived(); m_Effect.Play(); cacheCoroutine = StartCoroutine(Co_StartTween()); } protected override void OnAfterOpen() { //BeginMarquee(); } protected override void OnPreClose() { ServerTipDetails.OnTweening = false; presentCnt = 0; if (cacheCoroutine != null) { StopCoroutine(cacheCoroutine); cacheCoroutine = null; } } protected override void OnAfterClose() { } IEnumerator Co_StartTween() { yield return WaitingForSecondConst.WaitMS500; m_ContainerMarquee.SetActive(true); BeginMarquee(); } protected override void LateUpdate() { base.LateUpdate(); if (ServerTipDetails.OnTweening) { m_Time += Time.deltaTime; if (m_Time <= duration) { float progress = tweenCurve.Evaluate(m_Time / duration); marqueeText.rectTransform.localPosition = Vector3.Lerp(fromPos, toPos, progress); } else { OnTweenComp(); } } } #endregion void BeginMarquee() { if (presentCnt == 0) { var _hint = ServerTipDetails.RequireMarquee(); if (_hint != null) { presentCnt = 0; marqueeText.SetExtenalData(_hint.extentionData); marqueeText.text = _hint.message; } else { CloseImmediately(); return; } } presentCnt++; marqueeText.rectTransform.localPosition = fromPos; toPos = fromPos; float width = marqueeText.preferredWidth; toPos.x = fromPos.x - marqueeBg.rect.width - width; duration = (width + marqueeBg.rect.width) / speed; ServerTipDetails.OnTweening = true; } void OnTweenComp() { m_Time = 0; ServerTipDetails.OnTweening = false; if (presentCnt >= loopCnt) { presentCnt = 0; } BeginMarquee(); } } }