열차 목업의 내부 확인용 프로젝트
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Animations;
 
public class ActionButton : MonoBehaviour
{
    /// <summary>
    /// ¾Ö´Ï¸ÞÀ̼Ǡ½ÇÇà ¿©ºÎ
    /// </summary>
    public bool Run;
 
    /// <summary>
    /// ¾Ö´Ï¸ÞÀ̼Ǡ¼Óµµ
    /// </summary>
    public float Speed;
 
    /// <summary>
    /// ¾Ö´Ï¸ÞÀ̼Ǡ¸ñÇ¥ È¸Àü°ª(Euler) ¶Ç´Â ¸ñÇ¥ ÁÂÇ¥
    /// </summary>
    public Vector3 TargetRot;
 
    /// <summary>
    /// À̵¿ ¾Ö´Ï¸ÞÀ̼Ǡ¿©ºÎ
    /// true¸é À̵¿ false¸é È¸Àü ¾Ö´Ï¸ÞÀ̼Ç
    /// </summary>
    public bool isFixed;
 
 
    private Quaternion targetRot;
 
    private Quaternion initRot;
 
    private Vector3 targetPos;
 
    private Vector3 initPos;
 
    private float t;
 
    /// <summary>
    /// ¾Ö´Ï¸ÞÀ̼ǠÁ¾·á ¿©ºÎ
    /// </summary>
    private bool isEnd;
 
    /// <summary>
    /// ¾Ö´Ï¸ÞÀ̼ǠÁ¾·á¸¦ ½ÃÀÛ°ªÀ¸·Î(VR¿¡¼­¸¸)
    /// </summary>
    public bool VREndStart;
 
    void Start()
    {
       
            targetPos = TargetRot;
            initPos = transform.localPosition;
        
 
 
        Initialize();
    }
 
    void Initialize()
    {
        if (VREndStart && SceneTypeManager.Inst.IsVRMode)
        {
            EndInit();
        }
        else
        {
            Init();
        }
    }
 
 
 
 
    void EndInit()
    {
        if (!isFixed)
        {
            transform.localRotation = targetRot;
 
        }
        else
        {
            transform.localPosition = targetPos;
 
        }
        isEnd = true;
    }
 
    void Init()
    {
        if (!isFixed)
        {
            transform.localRotation = initRot;
 
        }
        else
        {
            transform.localPosition = initPos;
 
        }
        isEnd = false;
    }
 
    public void Play()
    {
        if (Run)
        {
            isEnd = !isEnd;
            t = 0;
        }
 
        Run = true;
    }
 
    void InitValues(bool end)
    {
        Run = false;
        isEnd = end;
        t = 0;
    }
 
 
    void Update()
    {
        if (Run)
        {
            t += Speed * Time.deltaTime;
            if (!isFixed)
            {
                if (isEnd)
                {
                    // Ãʱâ È¸Àü°ª±îÁö ¾Ö´Ï¸ÞÀ̼Ç
                    transform.localRotation = Quaternion.Slerp(transform.localRotation, initRot, t);
                    if (transform.localRotation == initRot)
                    {
                        InitValues(false);
                    }
                }
                else
                {
                    // ¸ñÇ¥ È¸Àü°ª±îÁö ¾Ö´Ï¸ÞÀ̼Ç
                    transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRot, t);
                    if (transform.localRotation == targetRot)
                    {
                        InitValues(true);
 
                    }
                }
            }
            else
            {
                if (isEnd)
                {
                    // Ãʱâ ÁÂÇ¥±îÁö ¾Ö´Ï¸ÞÀ̼Ç
                    transform.localPosition = Vector3.Lerp(transform.localPosition, initPos, t);
                    if (transform.localPosition == initPos)
                    {
                        InitValues(false);
                    }
                }
                else
                {
                    // ¸ñÇ¥ ÁÂÇ¥±îÁö ¾Ö´Ï¸ÞÀ̼Ç
                    transform.localPosition = Vector3.Lerp(transform.localPosition, targetPos, t);
                    if (transform.localPosition == targetPos)
                    {
                        InitValues(true);
                    }
                }
            }
        }
    }
}