forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreviewGUI.cs
More file actions
128 lines (119 loc) · 4.5 KB
/
PreviewGUI.cs
File metadata and controls
128 lines (119 loc) · 4.5 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
using System;
using UnityEditor;
using UnityEngine;
internal class PreviewGUI
{
private static Rect s_Position;
private static Vector2 s_ScrollPos;
private static Rect s_ViewRect;
private static int sliderHash = "Slider".GetHashCode();
internal static void BeginScrollView(Rect position, Vector2 scrollPosition, Rect viewRect, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar)
{
s_ScrollPos = scrollPosition;
s_ViewRect = viewRect;
s_Position = position;
GUIClip.Push(position, new Vector2(Mathf.Round((-scrollPosition.x - viewRect.x) - ((viewRect.width - position.width) * 0.5f)), Mathf.Round((-scrollPosition.y - viewRect.y) - ((viewRect.height - position.height) * 0.5f))), Vector2.zero, false);
}
public static int CycleButton(int selected, GUIContent[] options)
{
Styles.Init();
return EditorGUILayout.CycleButton(selected, options, Styles.preButton);
}
public static Vector2 Drag2D(Vector2 scrollPosition, Rect position)
{
int controlID = GUIUtility.GetControlID(sliderHash, FocusType.Passive);
Event current = Event.current;
EventType typeForControl = current.GetTypeForControl(controlID);
if (typeForControl != EventType.MouseDown)
{
if (typeForControl != EventType.MouseDrag)
{
if (typeForControl == EventType.MouseUp)
{
if (GUIUtility.hotControl == controlID)
{
GUIUtility.hotControl = 0;
}
EditorGUIUtility.SetWantsMouseJumping(0);
}
return scrollPosition;
}
}
else
{
if (position.Contains(current.mousePosition) && (position.width > 50f))
{
GUIUtility.hotControl = controlID;
current.Use();
EditorGUIUtility.SetWantsMouseJumping(1);
}
return scrollPosition;
}
if (GUIUtility.hotControl == controlID)
{
scrollPosition -= (Vector2) (((current.delta * (!current.shift ? ((float) 1) : ((float) 3))) / Mathf.Min(position.width, position.height)) * 140f);
scrollPosition.y = Mathf.Clamp(scrollPosition.y, -90f, 90f);
current.Use();
GUI.changed = true;
}
return scrollPosition;
}
public static Vector2 EndScrollView()
{
GUIClip.Pop();
Rect rect = s_Position;
Rect rect2 = s_Position;
Rect rect3 = s_ViewRect;
Vector2 vector = s_ScrollPos;
switch (Event.current.type)
{
case EventType.Layout:
GUIUtility.GetControlID(sliderHash, FocusType.Passive);
GUIUtility.GetControlID(sliderHash, FocusType.Passive);
return vector;
case EventType.Used:
return vector;
}
bool flag = false;
bool flag2 = false;
if (flag2 || (rect3.width > rect.width))
{
flag2 = true;
}
if (flag || (rect3.height > rect.height))
{
flag = true;
}
int controlID = GUIUtility.GetControlID(sliderHash, FocusType.Passive);
if (flag2)
{
GUIStyle sliderStyle = "PreHorizontalScrollbar";
GUIStyle thumbStyle = "PreHorizontalScrollbarThumb";
float num2 = (rect3.width - rect.width) * 0.5f;
vector.x = GUI.Slider(new Rect(rect2.x, rect2.yMax - sliderStyle.fixedHeight, rect.width - (!flag ? 0f : sliderStyle.fixedHeight), sliderStyle.fixedHeight), vector.x, rect.width + num2, -num2, rect3.width, sliderStyle, thumbStyle, true, controlID);
}
else
{
vector.x = 0f;
}
controlID = GUIUtility.GetControlID(sliderHash, FocusType.Passive);
if (flag)
{
GUIStyle style3 = "PreVerticalScrollbar";
GUIStyle style4 = "PreVerticalScrollbarThumb";
float num3 = (rect3.height - rect.height) * 0.5f;
vector.y = GUI.Slider(new Rect(rect.xMax - style3.fixedWidth, rect.y, style3.fixedWidth, rect.height), vector.y, rect.height + num3, -num3, rect3.height, style3, style4, false, controlID);
return vector;
}
vector.y = 0f;
return vector;
}
internal class Styles
{
public static GUIStyle preButton;
public static void Init()
{
preButton = "preButton";
}
}
}