forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisc.cs
More file actions
154 lines (147 loc) · 4.89 KB
/
Disc.cs
File metadata and controls
154 lines (147 loc) · 4.89 KB
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
using System;
using UnityEditor;
using UnityEngine;
namespace UnityEditorInternal
{
internal class Disc
{
private static Vector2 s_StartMousePosition;
private static Vector2 s_CurrentMousePosition;
private static Vector3 s_StartPosition;
private static Vector3 s_StartAxis;
private static Quaternion s_StartRotation;
private static float s_RotationDist;
public static Quaternion Do(int id, Quaternion rotation, Vector3 position, Vector3 axis, float size, bool cutoffPlane, float snap)
{
if (Mathf.Abs(Vector3.Dot(Camera.current.transform.forward, axis)) > 0.999f)
{
cutoffPlane = false;
}
Event current = Event.current;
switch (current.GetTypeForControl(id))
{
case EventType.MouseDown:
if ((HandleUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2))
{
GUIUtility.keyboardControl = id;
GUIUtility.hotControl = id;
Tools.LockHandlePosition();
if (cutoffPlane)
{
Vector3 normalized = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
Disc.s_StartPosition = HandleUtility.ClosestPointToArc(position, axis, normalized, 180f, size);
}
else
{
Disc.s_StartPosition = HandleUtility.ClosestPointToDisc(position, axis, size);
}
Disc.s_RotationDist = 0f;
Disc.s_StartRotation = rotation;
Disc.s_StartAxis = axis;
Disc.s_CurrentMousePosition = (Disc.s_StartMousePosition = Event.current.mousePosition);
current.Use();
EditorGUIUtility.SetWantsMouseJumping(1);
}
break;
case EventType.MouseUp:
if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2))
{
Tools.UnlockHandlePosition();
GUIUtility.hotControl = 0;
current.Use();
EditorGUIUtility.SetWantsMouseJumping(0);
}
break;
case EventType.MouseDrag:
if (GUIUtility.hotControl == id)
{
bool flag = EditorGUI.actionKey && current.shift;
if (flag)
{
if (HandleUtility.ignoreRaySnapObjects == null)
{
Handles.SetupIgnoreRaySnapObjects();
}
object obj = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition));
if (obj != null && (double)Vector3.Dot(axis.normalized, rotation * Vector3.forward) < 0.999)
{
Vector3 vector = ((RaycastHit)obj).point - position;
Vector3 forward = vector - Vector3.Dot(vector, axis.normalized) * axis.normalized;
rotation = Quaternion.LookRotation(forward, rotation * Vector3.up);
}
}
else
{
Vector3 normalized2 = Vector3.Cross(axis, position - Disc.s_StartPosition).normalized;
Disc.s_CurrentMousePosition += current.delta;
Disc.s_RotationDist = HandleUtility.CalcLineTranslation(Disc.s_StartMousePosition, Disc.s_CurrentMousePosition, Disc.s_StartPosition, normalized2) / size * 30f;
Disc.s_RotationDist = Handles.SnapValue(Disc.s_RotationDist, snap);
rotation = Quaternion.AngleAxis(Disc.s_RotationDist * -1f, Disc.s_StartAxis) * Disc.s_StartRotation;
}
GUI.changed = true;
current.Use();
}
break;
case EventType.KeyDown:
if (current.keyCode == KeyCode.Escape && GUIUtility.hotControl == id)
{
Tools.UnlockHandlePosition();
EditorGUIUtility.SetWantsMouseJumping(0);
}
break;
case EventType.Repaint:
{
Color color = Color.white;
if (id == GUIUtility.keyboardControl)
{
color = Handles.color;
Handles.color = Handles.selectedColor;
}
if (GUIUtility.hotControl == id)
{
Color color2 = Handles.color;
Vector3 normalized3 = (Disc.s_StartPosition - position).normalized;
Handles.color = Handles.secondaryColor;
Handles.DrawLine(position, position + normalized3 * size * 1.1f);
float angle = Mathf.Repeat(-Disc.s_RotationDist - 180f, 360f) - 180f;
Vector3 a = Quaternion.AngleAxis(angle, axis) * normalized3;
Handles.DrawLine(position, position + a * size * 1.1f);
Handles.color = Handles.secondaryColor * new Color(1f, 1f, 1f, 0.2f);
Handles.DrawSolidArc(position, axis, normalized3, angle, size);
Handles.color = color2;
}
if (cutoffPlane)
{
Vector3 normalized4 = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
Handles.DrawWireArc(position, axis, normalized4, 180f, size);
}
else
{
Handles.DrawWireDisc(position, axis, size);
}
if (id == GUIUtility.keyboardControl)
{
Handles.color = color;
}
break;
}
case EventType.Layout:
{
float distance;
if (cutoffPlane)
{
Vector3 normalized5 = Vector3.Cross(axis, Camera.current.transform.forward).normalized;
distance = HandleUtility.DistanceToArc(position, axis, normalized5, 180f, size) / 2f;
}
else
{
distance = HandleUtility.DistanceToDisc(position, axis, size) / 2f;
}
HandleUtility.AddControl(id, distance);
break;
}
}
return rotation;
}
}
}