열차 목업의 내부 확인용 프로젝트
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
 
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
 
 
public class MoveCamera : Singleton<MoveCamera>
{
    /// <summary>
    /// 카메라 시점 변경 속도
    /// </summary>
    public float CameraRotationSpeed = 4;
    ///// <summary>
    ///// 마우스 휠 줌 속도
    ///// </summary>
    //public float ZoomSpeewd = 5000.0f;
    ///// <summary>
    ///// 줌 최솟값, 작을 수록 확대할 수 있는 수치가 커짐
    ///// </summary>
    //public float MinZoomValue = 10;
    ///// <summary>
    ///// 줌 최대값, 클 수록 축소할 수 있는 수치가 커짐
    ///// </summary>
    //public float MaxZoomValue = 60;
    /// <summary>
    /// 카메라 이동 속도
    /// </summary>
    [Range(1f, 10f)]
    public float CameraMoveSpeed = 4;
 
 
 
    /// <summary>
    /// 마우스를 움직였을때의 x,y 좌표값
    /// </summary>
    [SerializeField]
    float mouseY = 0;
    [SerializeField]
    float mouseX = 0;
    //bool mouseOverCanvas = false;
 
    /// <summary>
    /// 마우스 왼쪽버튼 클릭에 대한 컨트롤
    /// </summary>
    private ButtonControl mouseLeftButton;
 
   
    [SerializeField]
    private float m_CanMoveDistance = 3f;
 
 
    [SerializeField]
    /// <summary>
    /// 포인트 이동 시 초기 위치 값 저장
    /// </summary>
    private Vector3 m_CameraInitOffset;
 
 
    public override void Awake()
    {
    
    }
    void Start()
    {
        mouseLeftButton = Mouse.current.leftButton;
 
 
        MouseInitialize(transform);
 
    }
 
    void Update()
    {
        CameraInputMove();
 
        if (mouseLeftButton.isPressed && !IsPointerOverCanvas())
        {
 
 
            Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
 
 
            mouseY += Input.GetAxis("Mouse Y") * CameraRotationSpeed;
 
            mouseY = Mathf.Clamp(mouseY, -90, 90);
            mouseX += Input.GetAxis("Mouse X") * CameraRotationSpeed;
 
            transform.localEulerAngles = new Vector3(-mouseY, mouseX, 0);
 
 
 
 
 
        }
 
 
 
    }
 
 
    bool IsPointerOverCanvas()
    {
        if (EventSystem.current == null) return false;
 
        PointerEventData eventData = new PointerEventData(EventSystem.current);
        eventData.position = Input.mousePosition;
 
        var results = new List<RaycastResult>();
        EventSystem.current.RaycastAll(eventData, results);
 
        return results.Count > 0;
    }
 
 
    public void SetCameraInitOffset(Vector3 pos)
    {
        m_CameraInitOffset = pos;
    }
 
 
    float getMouseY(float x)
    {
        if (x > 90)
        {
            if (x > 270)
            { //360도 까지만 있다는 전제하에
                return (x - 360);
            }
            return (180 - (x));
        }
        else if (x < -90)
        {
            if (x < -270)
            {
                return (x + 360);
            }
            return (180 + (x));
        }
        else
        {
            return x;
        }
 
    }
 
 
 
    public void MouseInitialize(Transform CameraTransform)
    {
        mouseX = CameraTransform.localEulerAngles.y;
        mouseY = -getMouseY(CameraTransform.localEulerAngles.x);
    }
 
    public void MouseInitialize()
    {
        mouseX = 0;
        mouseY = 0;
    }
 
 
 
 
    private void CameraInputMove()
    {
 
        Vector3 directionMovePos(Vector3 direction)
        {
            return direction * CameraMoveSpeed * Time.deltaTime;
        }
        Vector3 movePosition = Vector3.zero;
        if (Input.GetKey(InputManager.Forward)) movePosition += directionMovePos(transform.forward);
        if (Input.GetKey(InputManager.Backword)) movePosition -= directionMovePos(transform.forward);
        if (Input.GetKey(InputManager.Right)) movePosition += directionMovePos(transform.right);
        if (Input.GetKey(InputManager.Left)) movePosition -= directionMovePos(transform.right);
        if (Input.GetKey(InputManager.Up)) movePosition += directionMovePos(transform.up);
        if (Input.GetKey(InputManager.Down)) movePosition -= directionMovePos(transform.up);
 
        transform.position += movePosition;
 
        if(transform.position.y < 0)
        {
            movePosition =new Vector3(transform.position.x, 0, transform.position.z);
            transform.position = movePosition; 
        }
    
 
 
 
    }
}