| | |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | [RequireComponent(typeof(CanvasGroup))] |
| | | public class ScrollTipDetail : MonoBehaviour |
| | | using DG.Tweening; |
| | | [RequireComponent(typeof(CanvasGroup))] |
| | | public class ScrollTipDetail : MonoBehaviour |
| | | { |
| | | |
| | | RichText text; |
| | | |
| | | CanvasGroup canvasGroup; |
| | | [HideInInspector] |
| | | public ScrollTip.ScrollTipState presentState = ScrollTip.ScrollTipState.Move; |
| | | private float m_Time = 0; |
| | | private Vector3 pos = Vector3.zero; |
| | | |
| | | private float m_TipShowTime; |
| | | private float m_TipHideTime; |
| | | private float m_TipDistance; |
| | | |
| | | private void Awake() |
| | | { |
| | | canvasGroup = GetComponent<CanvasGroup>(); |
| | | text = transform.Find("Text").GetComponent<RichText>(); |
| | | } |
| | | |
| | | RichText text; |
| | | public void ShowTip(SystemHintData _hint) |
| | | { |
| | | text.SetExtenalData(_hint.extentionData); |
| | | text.text = _hint.message; |
| | | } |
| | | |
| | | CanvasGroup canvasGroup; |
| | | [HideInInspector] |
| | | public ScrollTip.ScrollTipState presentState = ScrollTip.ScrollTipState.Idle; |
| | | private float m_Time = 0; |
| | | private Vector3 pos = Vector3.zero; |
| | | public void SetTipConfig(float _showTime,float _hideTime,float _dis) |
| | | { |
| | | m_TipShowTime = _showTime; |
| | | m_TipHideTime = _hideTime; |
| | | m_TipDistance = _dis; |
| | | } |
| | | |
| | | private float m_TipShowTime; |
| | | private float m_TipHideTime; |
| | | private float m_TipDistance; |
| | | public void Play(ScrollTip.ScrollTipState state) |
| | | { |
| | | m_Time = 0; |
| | | canvasGroup.alpha = 1; |
| | | pos = transform.localPosition; |
| | | presentState = state; |
| | | //LateUpdate 改成dotwweing |
| | | Sequence tween = DOTween.Sequence();; |
| | | tween.Append(transform.DOLocalMove(pos.SetY(pos.y + m_TipDistance), ScrollTip.tipMoveTime)).SetEase(Ease.Linear); |
| | | tween.AppendInterval(m_TipShowTime); |
| | | tween.Append(canvasGroup.DOFade(0, m_TipHideTime)).SetEase(Ease.Linear); |
| | | tween.Play(); |
| | | tween.OnComplete(() => |
| | | { |
| | | presentState = ScrollTip.ScrollTipState.None; |
| | | ScrollTip.Release(this, false); |
| | | ScrollTip.OnTipComplete(); |
| | | }); |
| | | } |
| | | |
| | | private void Awake() |
| | | { |
| | | canvasGroup = GetComponent<CanvasGroup>(); |
| | | text = transform.Find("Text").GetComponent<RichText>(); |
| | | } |
| | | |
| | | public void ShowTip(SystemHintData _hint) |
| | | { |
| | | text.SetExtenalData(_hint.extentionData); |
| | | text.text = _hint.message; |
| | | } |
| | | |
| | | public void SetTipConfig(float _showTime,float _hideTime,float _dis) |
| | | { |
| | | m_TipShowTime = _showTime; |
| | | m_TipHideTime = _hideTime; |
| | | m_TipDistance = _dis; |
| | | } |
| | | |
| | | public void Play(ScrollTip.ScrollTipState state) |
| | | { |
| | | m_Time = 0; |
| | | canvasGroup.alpha = 1; |
| | | pos = transform.localPosition; |
| | | presentState = state; |
| | | } |
| | | |
| | | private void LateUpdate() |
| | | { |
| | | m_Time += Time.deltaTime; |
| | | switch (presentState) { |
| | | case ScrollTip.ScrollTipState.Idle: { |
| | | m_Time = Mathf.Min(m_Time, m_TipShowTime); |
| | | if (m_Time >= m_TipShowTime) { |
| | | m_Time = 0; |
| | | var index = ScrollTip.m_ActiveTips.IndexOf(this); |
| | | if (index == 0) { |
| | | presentState = ScrollTip.ScrollTipState.Hide; |
| | | } |
| | | else { |
| | | presentState = ScrollTip.ScrollTipState.None; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | case ScrollTip.ScrollTipState.Move: { |
| | | m_Time = Mathf.Min(m_Time, ScrollTip.tipMoveTime); |
| | | transform.localPosition = Vector3.Lerp(pos, pos.SetY(pos.y + m_TipDistance), m_Time / ScrollTip.tipMoveTime); |
| | | if (m_Time >= ScrollTip.tipMoveTime) { |
| | | m_Time = 0; |
| | | presentState = ScrollTip.ScrollTipState.Idle; |
| | | ScrollTip.OnTipComplete(); |
| | | } |
| | | } |
| | | break; |
| | | case ScrollTip.ScrollTipState.Hide: { |
| | | m_Time = Mathf.Min(m_Time, m_TipHideTime); |
| | | canvasGroup.alpha = 1 - m_Time / m_TipHideTime; |
| | | if (m_Time >= m_TipHideTime) { |
| | | m_Time = 0; |
| | | presentState = ScrollTip.ScrollTipState.None; |
| | | ScrollTip.Release(this); |
| | | ScrollTip.OnTipComplete(); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | // private void LateUpdate() |
| | | // { |
| | | // m_Time += Time.deltaTime; |
| | | // switch (presentState) { |
| | | // case ScrollTip.ScrollTipState.Idle: { |
| | | // m_Time = Mathf.Min(m_Time, m_TipShowTime); |
| | | // if (m_Time >= m_TipShowTime) { |
| | | // m_Time = 0; |
| | | // var index = ScrollTip.m_ActiveTips.IndexOf(this); |
| | | // if (index == 0) { |
| | | // presentState = ScrollTip.ScrollTipState.Hide; |
| | | // } |
| | | // else { |
| | | // presentState = ScrollTip.ScrollTipState.None; |
| | | // } |
| | | // } |
| | | // } |
| | | // break; |
| | | // case ScrollTip.ScrollTipState.Move: { |
| | | // m_Time = Mathf.Min(m_Time, ScrollTip.tipMoveTime); |
| | | // transform.localPosition = Vector3.Lerp(pos, pos.SetY(pos.y + m_TipDistance), m_Time / ScrollTip.tipMoveTime); |
| | | // if (m_Time >= ScrollTip.tipMoveTime) { |
| | | // m_Time = 0; |
| | | // presentState = ScrollTip.ScrollTipState.Idle; |
| | | // ScrollTip.OnTipComplete(); |
| | | // } |
| | | // } |
| | | // break; |
| | | // case ScrollTip.ScrollTipState.Hide: { |
| | | // m_Time = Mathf.Min(m_Time, m_TipHideTime); |
| | | // canvasGroup.alpha = 1 - m_Time / m_TipHideTime; |
| | | // if (m_Time >= m_TipHideTime) { |
| | | // m_Time = 0; |
| | | // presentState = ScrollTip.ScrollTipState.None; |
| | | // ScrollTip.Release(this); |
| | | // ScrollTip.OnTipComplete(); |
| | | // } |
| | | // } |
| | | // break; |
| | | // } |
| | | // } |
| | | } |