diff options
Diffstat (limited to 'Assets/Plugins/Editor/AdvancedInspector/ExtraGUI')
4 files changed, 271 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; + } + } +} diff --git a/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUI.cs.meta b/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUI.cs.meta new file mode 100644 index 00000000..82b25bc2 --- /dev/null +++ b/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUI.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e020a2d8f59a2864999a0b1bce4e072e +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUILayout.cs b/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUILayout.cs new file mode 100644 index 00000000..608a45f5 --- /dev/null +++ b/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUILayout.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using UnityEngine; +using UnityEditor; + +namespace AdvancedInspector +{ + public static class ExtraGUILayout + { + public static float FloatAngle(float value) + { + return FloatAngle(value, -1, -1, -1); + } + + public static float FloatAngle(float value, float snap) + { + return FloatAngle(value, snap, -1, -1); + } + + public static float FloatAngle(float value, float snap, float min, float max) + { + Rect rect = GUILayoutUtility.GetRect(128, 512, 32, 32); + rect.x += 8; + return ExtraGUI.FloatAngle(rect, value, snap, min, max); + } + + public static int IntAngle(int value) + { + return IntAngle(value, -1, -1, -1); + } + + public static int IntAngle(int value, int snap) + { + return IntAngle(value, snap, -1, -1); + } + + public static int IntAngle(int value, int snap, int min, int max) + { + Rect rect = GUILayoutUtility.GetRect(128, 512, 32, 32); + rect.x += 8; + return ExtraGUI.IntAngle(rect, value, snap, min, max); + } + + public static int CycleButton(int selected, GUIContent[] contents, GUIStyle style) + { + if (GUILayout.Button(contents[selected], style)) + { + selected++; + if (selected >= contents.Length) + selected = 0; + } + + return selected; + } + } +} diff --git a/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUILayout.cs.meta b/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUILayout.cs.meta new file mode 100644 index 00000000..37dfd46d --- /dev/null +++ b/Assets/Plugins/Editor/AdvancedInspector/ExtraGUI/ExtraGUILayout.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5a5c459bbc6263843ad47a5a586832ce +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: |