열차 목업의 내부 확인용 프로젝트
smchoi
2024-07-24 ff74c0073046f0e086eb7d355950bda39937c92c
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Unity.VisualScripting;
using UnityEngine;
 
public class UIAnimation : MonoBehaviour, IUIShow
{
    public Vector2 Direction;
    public float Speed = 500f;
    private RectTransform myRect;
    private bool run;
    private bool isHide;
    private Vector2 defaultPos;
    private Vector2 dir;
 
        void Start()
        {
            myRect = GetComponent<RectTransform>();
        run = false;
 
        defaultPos = transform.position;
        
 
        if (SceneTypeManager.Inst.IsVRMode)
        {
            Hide();
        }
    }
 
    float GetTargetPos(float dir, float pos, float sizeDelta)
    {
        float targetPos = 0;
        if (dir > 0)
        {
            targetPos = pos - sizeDelta / 2;
        }
        else if (dir < 0)
        {
            targetPos = pos + sizeDelta / 2;
        }
 
        return targetPos;
    }
                   
    bool IsStop(float dir, float pos, float oldPos)
    {
        bool stop = false;
        if (dir > 0)
        {
            if (pos >= oldPos)
            {
                stop = true;
            }
        }
        else if (dir < 0)
        {
            if (pos <= oldPos)
            {
                stop = true;
            }
        }
        else
        {
            stop = true;
        }
        return stop;
    }
 
    void Update()
    {
        if (run)
        {
            if (!isHide)
            {
                dir = Direction;
                myRect.anchoredPosition += dir * Speed * Time.deltaTime;
 
                float targetPosX = GetTargetPos(Direction.x, transform.position.x, myRect.sizeDelta.x);
                float targetPosY = GetTargetPos(Direction.y, transform.position.y, myRect.sizeDelta.y);
                if (targetPosX < 0 || targetPosY < 0 || targetPosX > Screen.width || targetPosY > Screen.height)
                {
                    run = false;
                    isHide = true;
                }
            }
            else
            {
                dir = Direction * -1;
                myRect.anchoredPosition += dir * Speed * Time.deltaTime;
 
                bool stopX = IsStop(dir.x, transform.position.x, defaultPos.x);
                bool stopY = IsStop(dir.y, transform.position.y, defaultPos.y);
 
                if (stopX && stopY)
                {
                    run = false;
                    transform.position = defaultPos;
                    isHide = false;
                }
            }
        }
    }
 
    public void Show()
    {
        if (run) {
            run = false;
            isHide = true;
        }
 
        if (isHide)
        {
            run = true;
        }
    }
 
    public void Hide()
    {
        if (run) {
            run = false;
            isHide = false;
        }
 
        if (!isHide)
        {
            run = true;
        }
    }
 
    public void Stop()
    {
        if (run)
        {
            run = false;
        }
    }
}