//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, April 09, 2018
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
|
|
public class UISmoothMove : MonoBehaviour
|
{
|
[SerializeField] Vector2 m_To;
|
public Vector2 to {
|
get { return m_To; }
|
set { m_To = value; }
|
}
|
|
[SerializeField] float m_Smooth = 0.2f;
|
|
Vector2 refPosition = Vector2.zero;
|
RectTransform rectTransform { get { return this.transform as RectTransform; } }
|
|
bool show = false;
|
|
public void Begin()
|
{
|
refPosition = Vector2.zero;
|
show = true;
|
}
|
|
public void Stop()
|
{
|
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;
|
}
|
}
|
|
|
}
|