From 047efd15559d7c62666f00392a987dccdc36d500 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 18 May 2021 22:37:34 +0800 Subject: +misc --- .../EditorGUIHelper/Editor/EditorGUIHelper.cs | 13 +++ .../EditorGUIHelper/Editor/EditorGUIHelper.cs.meta | 11 +++ .../EditorGUIHelper/Editor/EditorHandlesHelper.cs | 99 ++++++++++++++++++++++ .../Editor/EditorHandlesHelper.cs.meta | 11 +++ 4 files changed, 134 insertions(+) create mode 100644 UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorGUIHelper.cs create mode 100644 UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorGUIHelper.cs.meta create mode 100644 UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorHandlesHelper.cs create mode 100644 UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorHandlesHelper.cs.meta (limited to 'UnityCollection/Assets/Tools/EditorGUIHelper/Editor') diff --git a/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorGUIHelper.cs b/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorGUIHelper.cs new file mode 100644 index 0000000..3ccde08 --- /dev/null +++ b/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorGUIHelper.cs @@ -0,0 +1,13 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public static class EditorGUIHelper +{ + static EditorGUIHelper() + { + + } + + +} diff --git a/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorGUIHelper.cs.meta b/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorGUIHelper.cs.meta new file mode 100644 index 0000000..5b4bd6b --- /dev/null +++ b/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorGUIHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4d503328ed0e74c4993f51b243402640 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorHandlesHelper.cs b/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorHandlesHelper.cs new file mode 100644 index 0000000..4bf4b8f --- /dev/null +++ b/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorHandlesHelper.cs @@ -0,0 +1,99 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +// Scene视图中的自定义handles +public static class EditorHandlesHelper +{ + static int s_ValueScaleHandleHash; + + // limit value 数据 + static float s_StartScale; + static float s_ValueDrag; + static float s_ScaleDrawLength; + + static EditorHandlesHelper() + { + s_ValueScaleHandleHash = "ValueScaleHandleHash".GetHashCode(); + } + + #region 单一handle + + // 控制数值的handle + public static float ScaleValueHandle(float value, Vector3 position, Quaternion rotation, float size, Handles.CapFunction capFunc, float snap) + { + int controlID = GUIUtility.GetControlID(s_ValueScaleHandleHash, FocusType.Keyboard); + int id = controlID; + 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; + s_StartScale = value; + s_ValueDrag = 0f; + current.Use(); + EditorGUIUtility.SetWantsMouseJumping(1); + } + break; + case EventType.MouseUp: + if (GUIUtility.hotControl == id && (current.button == 0 || current.button == 2)) + { + GUIUtility.hotControl = 0; + s_ScaleDrawLength = 1f; + current.Use(); + EditorGUIUtility.SetWantsMouseJumping(0); + } + break; + case EventType.MouseDrag: + if (GUIUtility.hotControl == id) + { + s_ValueDrag += HandleUtility.niceMouseDelta * 0.01f; + value = (Handles.SnapValue(s_ValueDrag, snap) + 1f) * s_StartScale; + s_ScaleDrawLength = value / s_StartScale; + GUI.changed = true; + current.Use(); + } + break; + case EventType.KeyDown: + if (GUIUtility.hotControl == id && current.keyCode == KeyCode.Escape) + { + value = s_StartScale; + s_ScaleDrawLength = 1f; + GUIUtility.hotControl = 0; + GUI.changed = true; + current.Use(); + } + break; + case EventType.Repaint: + { + Color color = Color.white; + if (id == GUIUtility.keyboardControl) + { + color = Handles.color; + Handles.color = Handles.selectedColor; + } + capFunc(id, position, rotation, size * 0.15f, EventType.Repaint); + if (id == GUIUtility.keyboardControl) + { + Handles.color = color; + } + break; + } + case EventType.Layout: + HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position, size * 0.15f)); + break; + } + return value; + } + + #endregion + + #region 复合handle + + #endregion + +} diff --git a/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorHandlesHelper.cs.meta b/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorHandlesHelper.cs.meta new file mode 100644 index 0000000..9214902 --- /dev/null +++ b/UnityCollection/Assets/Tools/EditorGUIHelper/Editor/EditorHandlesHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 769f17c75b56df84ba523a8dcfa021dc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0