summaryrefslogtreecommitdiff
path: root/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUI.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-15 07:24:10 +0800
committerchai <chaifix@163.com>2020-10-15 07:24:10 +0800
commite846c64d6f927879cb8a095e62d773a8d7b3c9f4 (patch)
tree7882744bbf2b6c7096ec15fb300f088c5a0807c5 /Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUI.cs
parentcd12e74241678ee3c0752484d310b202187ba24c (diff)
*ability system
Diffstat (limited to 'Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUI.cs')
-rw-r--r--Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUI.cs196
1 files changed, 196 insertions, 0 deletions
diff --git a/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUI.cs b/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUI.cs
new file mode 100644
index 00000000..4219fa75
--- /dev/null
+++ b/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUI.cs
@@ -0,0 +1,196 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using UnityEngine;
+using UnityEditor;
+
+using UniToolsEditor;
+
+namespace AdvancedInspector
+{
+ public static class ExtraGUI
+ {
+ private static Texture knob;
+
+ private static Texture Knob
+ {
+ get
+ {
+ if (knob == null)
+ {
+ knob = Helper.Load(EditorResources.Knob);
+ knob.filterMode = FilterMode.Trilinear;
+ }
+
+ return knob;
+ }
+ }
+
+ private static Texture knobBack;
+
+ private static Texture KnobBack
+ {
+ get
+ {
+ if (knobBack == null)
+ knobBack = Helper.Load(EditorResources.KnobBack);
+
+ return knobBack;
+ }
+ }
+
+ private static Vector2 mousePosition;
+
+ public static float FloatAngle(Rect rect, float value)
+ {
+ return FloatAngle(rect, value, -1, -1, -1);
+ }
+
+ public static float FloatAngle(Rect rect, float value, float snap)
+ {
+ return FloatAngle(rect, value, snap, -1, -1);
+ }
+
+ public static float FloatAngle(Rect rect, float value, float snap, float min, float max)
+ {
+ int id = GUIUtility.GetControlID(FocusType.Passive, rect);
+
+ Rect knobRect = new Rect(rect.x, rect.y, rect.height, rect.height);
+
+ float delta;
+ if (min != max)
+ delta = ((max - min) / 360);
+ else
+ delta = 1;
+
+ if (Event.current != null)
+ {
+ if (Event.current.type == EventType.MouseDown && knobRect.Contains(Event.current.mousePosition))
+ {
+ GUIUtility.hotControl = id;
+ mousePosition = Event.current.mousePosition;
+ }
+ else if (Event.current.type == EventType.MouseUp && GUIUtility.hotControl == id)
+ GUIUtility.hotControl = 0;
+ else if (Event.current.type == EventType.MouseDrag && GUIUtility.hotControl == id)
+ {
+ Vector2 move = mousePosition - Event.current.mousePosition;
+ value += delta * (-move.x - move.y);
+
+ if (snap > 0)
+ {
+ float mod = value % snap;
+
+ if (mod < (delta * 3) || Mathf.Abs(mod - snap) < (delta * 3))
+ value = Mathf.Round(value / snap) * snap;
+ }
+
+ mousePosition = Event.current.mousePosition;
+ GUI.changed = true;
+ }
+ }
+
+ GUI.DrawTexture(knobRect, KnobBack);
+ Matrix4x4 matrix = GUI.matrix;
+
+ if (min != max)
+ GUIUtility.RotateAroundPivot(value * (360 / (max - min)), knobRect.center);
+ else
+ GUIUtility.RotateAroundPivot(value, knobRect.center);
+
+ GUI.DrawTexture(knobRect, Knob);
+ GUI.matrix = matrix;
+
+ Rect label = new Rect(rect.x + rect.height + 9, rect.y + (rect.height / 2) - 9, rect.height, 18);
+ value = EditorGUI.FloatField(label, value);
+
+ if (min != max)
+ value = Mathf.Clamp(value, min, max);
+
+ return value;
+ }
+
+ public static int IntAngle(Rect rect, int value)
+ {
+ return IntAngle(rect, value, -1, -1, -1);
+ }
+
+ public static int IntAngle(Rect rect, int value, int snap)
+ {
+ return IntAngle(rect, value, snap, -1, -1);
+ }
+
+ public static int IntAngle(Rect rect, int value, int snap, int min, int max)
+ {
+ int id = GUIUtility.GetControlID(FocusType.Passive, rect);
+
+ Rect knobRect = new Rect(rect.x, rect.y, rect.height, rect.height);
+
+ int delta;
+ if (min != max)
+ delta = ((max - min) / 360);
+ else
+ delta = 1;
+
+ if (Event.current != null)
+ {
+ if (Event.current.type == EventType.MouseDown && knobRect.Contains(Event.current.mousePosition))
+ {
+ GUIUtility.hotControl = id;
+ mousePosition = Event.current.mousePosition;
+ }
+ else if (Event.current.type == EventType.MouseUp && GUIUtility.hotControl == id)
+ GUIUtility.hotControl = 0;
+ else if (Event.current.type == EventType.MouseDrag && GUIUtility.hotControl == id)
+ {
+ Vector2 move = mousePosition - Event.current.mousePosition;
+ value += delta * (-(int)move.x - (int)move.y);
+
+ if (snap > 0)
+ {
+ float mod = value % snap;
+
+ if (mod < (delta * 3) || Mathf.Abs(mod - snap) < (delta * 3))
+ value = (int)Mathf.Round(value / snap) * snap;
+ }
+
+ mousePosition = Event.current.mousePosition;
+ GUI.changed = true;
+ }
+ }
+
+ GUI.DrawTexture(knobRect, KnobBack);
+ Matrix4x4 matrix = GUI.matrix;
+
+ if (min != max)
+ GUIUtility.RotateAroundPivot(value * (360 / (max - min)), knobRect.center);
+ else
+ GUIUtility.RotateAroundPivot(value, knobRect.center);
+
+ GUI.DrawTexture(knobRect, Knob);
+ GUI.matrix = matrix;
+
+ Rect label = new Rect(rect.x + rect.height + 9, rect.y + (rect.height / 2) - 9, rect.height, 18);
+ value = EditorGUI.IntField(label, value);
+
+ if (min != max)
+ value = Mathf.Clamp(value, min, max);
+
+ return value;
+ }
+
+ public static int CycleButton(Rect rect, int selected, GUIContent[] contents, GUIStyle style)
+ {
+ if (GUI.Button(rect, contents[selected], style))
+ {
+ selected++;
+ if (selected >= contents.Length)
+ selected = 0;
+ }
+
+ return selected;
+ }
+ }
+}