| | |
| | | using System.Collections; |
| | | using UnityEngine.UI; |
| | | |
| | | namespace vnxbqy.UI |
| | | [RequireComponent(typeof(RectTransform))] |
| | | public class UILinerMove : MonoBehaviour |
| | | { |
| | | [RequireComponent(typeof(RectTransform))] |
| | | public class UILinerMove : MonoBehaviour |
| | | [SerializeField] float m_Duration; |
| | | public float duration { |
| | | get { return m_Duration; } |
| | | set { m_Duration = value; } |
| | | } |
| | | |
| | | [SerializeField] Vector2 m_From; |
| | | public Vector2 from { |
| | | get { return m_From; } |
| | | set { m_From = value; } |
| | | } |
| | | |
| | | [SerializeField] Vector2 m_To; |
| | | public Vector2 to { |
| | | get { return m_To; } |
| | | set { m_To = value; } |
| | | } |
| | | |
| | | float timer = float.MaxValue; |
| | | RectTransform rectTransform { get { return this.transform as RectTransform; } } |
| | | |
| | | public void Begin() |
| | | { |
| | | [SerializeField] float m_Duration; |
| | | public float duration { |
| | | get { return m_Duration; } |
| | | set { m_Duration = value; } |
| | | } |
| | | |
| | | [SerializeField] Vector2 m_From; |
| | | public Vector2 from { |
| | | get { return m_From; } |
| | | set { m_From = value; } |
| | | } |
| | | |
| | | [SerializeField] Vector2 m_To; |
| | | public Vector2 to { |
| | | get { return m_To; } |
| | | set { m_To = value; } |
| | | } |
| | | |
| | | float timer = float.MaxValue; |
| | | RectTransform rectTransform { get { return this.transform as RectTransform; } } |
| | | |
| | | public void Begin() |
| | | if (duration < 0f) |
| | | { |
| | | if (duration < 0f) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (!this.gameObject.activeInHierarchy) |
| | | { |
| | | Stop(); |
| | | } |
| | | else |
| | | { |
| | | timer = 0f; |
| | | rectTransform.anchoredPosition = from; |
| | | } |
| | | return; |
| | | } |
| | | |
| | | public void Stop() |
| | | if (!this.gameObject.activeInHierarchy) |
| | | { |
| | | timer = float.MaxValue; |
| | | rectTransform.anchoredPosition = to; |
| | | Stop(); |
| | | } |
| | | |
| | | private void OnDisable() |
| | | else |
| | | { |
| | | if (timer < duration) |
| | | { |
| | | Stop(); |
| | | } |
| | | timer = 0f; |
| | | rectTransform.anchoredPosition = from; |
| | | } |
| | | } |
| | | |
| | | private void LateUpdate() |
| | | public void Stop() |
| | | { |
| | | timer = float.MaxValue; |
| | | rectTransform.anchoredPosition = to; |
| | | } |
| | | |
| | | private void OnDisable() |
| | | { |
| | | if (timer < duration) |
| | | { |
| | | if (timer < duration) |
| | | { |
| | | timer += Time.deltaTime; |
| | | var t = Mathf.Clamp01(timer / duration); |
| | | rectTransform.anchoredPosition = Vector2.Lerp(from, to, t); |
| | | } |
| | | Stop(); |
| | | } |
| | | } |
| | | |
| | | private void LateUpdate() |
| | | { |
| | | if (timer < duration) |
| | | { |
| | | timer += Time.deltaTime; |
| | | var t = Mathf.Clamp01(timer / duration); |
| | | rectTransform.anchoredPosition = Vector2.Lerp(from, to, t); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |