yyl
2025-06-09 b9751b2f076ee050fe5b685e91ae4fc4469b1015
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//--------------------------------------------------------
//    [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;
        }
    }
 
 
}