|  |  |  | 
|---|
|  |  |  | using System.Collections; | 
|---|
|  |  |  | using UnityEngine.UI; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace vnxbqy.UI | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class UISmoothMove : MonoBehaviour | 
|---|
|  |  |  | { | 
|---|
|  |  |  | [SerializeField] Vector2 m_To; | 
|---|
|  |  |  | public Vector2 to { | 
|---|
|  |  |  | get { return m_To; } | 
|---|
|  |  |  | set { m_To = value; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class UISmoothMove : MonoBehaviour | 
|---|
|  |  |  | [SerializeField] float m_Smooth = 0.2f; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Vector2 refPosition = Vector2.zero; | 
|---|
|  |  |  | RectTransform rectTransform { get { return this.transform as RectTransform; } } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bool show = false; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void Begin() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | [SerializeField] Vector2 m_To; | 
|---|
|  |  |  | public Vector2 to { | 
|---|
|  |  |  | get { return m_To; } | 
|---|
|  |  |  | set { m_To = value; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | refPosition = Vector2.zero; | 
|---|
|  |  |  | show = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [SerializeField] float m_Smooth = 0.2f; | 
|---|
|  |  |  | public void Stop() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | show = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Vector2 refPosition = Vector2.zero; | 
|---|
|  |  |  | RectTransform rectTransform { get { return this.transform as RectTransform; } } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bool show = false; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void Begin() | 
|---|
|  |  |  | private void LateUpdate() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (Vector2.Distance(rectTransform.anchoredPosition, to) > 1f) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | refPosition = Vector2.zero; | 
|---|
|  |  |  | show = true; | 
|---|
|  |  |  | if (show) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var newPosition = Vector2.SmoothDamp(rectTransform.anchoredPosition, to, ref refPosition, m_Smooth, 1000, Time.deltaTime); | 
|---|
|  |  |  | rectTransform.anchoredPosition = newPosition; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void Stop() | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | show = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void LateUpdate() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (Vector2.Distance(rectTransform.anchoredPosition, to) > 1f) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (show) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var newPosition = Vector2.SmoothDamp(rectTransform.anchoredPosition, to, ref refPosition, m_Smooth, 1000, Time.deltaTime); | 
|---|
|  |  |  | rectTransform.anchoredPosition = newPosition; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | show = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|