From 7d7cb55a4ed740124bea5343b757c301f5f2c16a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Wed, 6 Dec 2023 01:32:11 +0100 Subject: [PATCH 1/6] Fix displaying MinMax sliders in indented rects; support for Vector2Int in the MinMaxSliderAttribute --- .../Regular/MinMaxSliderAttributeDrawer.cs | 36 +++++++++++++--- .../DynamicMinMaxSliderAttributeDrawer.cs | 42 ++++++++++++++++--- .../Editor Toolbox/Editor/ToolboxEditorGui.cs | 22 ++++++---- Assets/Examples/Scenes/SampleScene.unity | 4 +- Assets/Examples/Scripts/SampleBehaviour1.cs | 4 +- 5 files changed, 85 insertions(+), 23 deletions(-) diff --git a/Assets/Editor Toolbox/Editor/Drawers/Regular/MinMaxSliderAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Regular/MinMaxSliderAttributeDrawer.cs index b657574b..dec424bb 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Regular/MinMaxSliderAttributeDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Regular/MinMaxSliderAttributeDrawer.cs @@ -10,26 +10,49 @@ public class MinMaxSliderAttributeDrawer : PropertyDrawerBase { protected override float GetPropertyHeightSafe(SerializedProperty property, GUIContent label) { - return base.GetPropertyHeightSafe(property, label); + return EditorGUIUtility.singleLineHeight; } protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label) { var minValue = Attribute.MinValue; var maxValue = Attribute.MaxValue; - var xValue = property.vector2Value.x; - var yValue = property.vector2Value.y; + + var xValue = 0.0f; + var yValue = 0.0f; + switch (property.propertyType) + { + case SerializedPropertyType.Vector2: + xValue = property.vector2Value.x; + yValue = property.vector2Value.y; + break; + case SerializedPropertyType.Vector2Int: + xValue = property.vector2IntValue.x; + yValue = property.vector2IntValue.y; + break; + } label = EditorGUI.BeginProperty(position, label, property); EditorGUI.BeginChangeCheck(); + position = EditorGUI.PrefixLabel(position, label); using (new ZeroIndentScope()) { - ToolboxEditorGui.DrawMinMaxSlider(position, label, ref xValue, ref yValue, minValue, maxValue); + ToolboxEditorGui.DrawMinMaxSlider(position, ref xValue, ref yValue, minValue, maxValue); } if (EditorGUI.EndChangeCheck()) { - property.vector2Value = new Vector2(xValue, yValue); + switch (property.propertyType) + { + case SerializedPropertyType.Vector2: + property.vector2Value = new Vector2(xValue, yValue); + break; + case SerializedPropertyType.Vector2Int: + var intXValue = Mathf.RoundToInt(xValue); + var intYValue = Mathf.RoundToInt(yValue); + property.vector2IntValue = new Vector2Int(intXValue, intYValue); + break; + } } EditorGUI.EndProperty(); @@ -38,7 +61,8 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU public override bool IsPropertyValid(SerializedProperty property) { - return property.propertyType == SerializedPropertyType.Vector2; + return property.propertyType == SerializedPropertyType.Vector2 || + property.propertyType == SerializedPropertyType.Vector2Int; } diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelf/DynamicMinMaxSliderAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelf/DynamicMinMaxSliderAttributeDrawer.cs index bd10fbe7..95df5eb1 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelf/DynamicMinMaxSliderAttributeDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelf/DynamicMinMaxSliderAttributeDrawer.cs @@ -1,20 +1,49 @@ -using UnityEditor; +using UnityEditor; using UnityEngine; namespace Toolbox.Editor.Drawers { + using Toolbox.Editor.Internal; + public class DynamicMinMaxSliderAttributeDrawer : DynamicMinMaxBaseDrawer { protected override void OnGuiSafe(SerializedProperty property, GUIContent label, float minValue, float maxValue) { - var xValue = property.vector2Value.x; - var yValue = property.vector2Value.y; + var xValue = 0.0f; + var yValue = 0.0f; + switch (property.propertyType) + { + case SerializedPropertyType.Vector2: + xValue = property.vector2Value.x; + yValue = property.vector2Value.y; + break; + case SerializedPropertyType.Vector2Int: + xValue = property.vector2IntValue.x; + yValue = property.vector2IntValue.y; + break; + } + ToolboxEditorGui.BeginProperty(property, ref label, out var position); + position = EditorGUI.PrefixLabel(position, label); EditorGUI.BeginChangeCheck(); - ToolboxEditorGui.DrawMinMaxSlider(position, label, ref xValue, ref yValue, minValue, maxValue); + using (new ZeroIndentScope()) + { + ToolboxEditorGui.DrawMinMaxSlider(position, ref xValue, ref yValue, minValue, maxValue); + } + if (EditorGUI.EndChangeCheck()) { - property.vector2Value = new Vector2(xValue, yValue); + switch (property.propertyType) + { + case SerializedPropertyType.Vector2: + property.vector2Value = new Vector2(xValue, yValue); + break; + case SerializedPropertyType.Vector2Int: + var intXValue = Mathf.RoundToInt(xValue); + var intYValue = Mathf.RoundToInt(yValue); + property.vector2IntValue = new Vector2Int(intXValue, intYValue); + break; + } } ToolboxEditorGui.CloseProperty(); @@ -23,7 +52,8 @@ protected override void OnGuiSafe(SerializedProperty property, GUIContent label, public override bool IsPropertyValid(SerializedProperty property) { - return property.propertyType == SerializedPropertyType.Vector2; + return property.propertyType == SerializedPropertyType.Vector2 || + property.propertyType == SerializedPropertyType.Vector2Int; } } } \ No newline at end of file diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs index 05704986..c8f0aa5e 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs @@ -199,21 +199,14 @@ public static void DrawTexture(Rect rect, Texture texture, ScaleMode scaleMode, GUI.DrawTexture(rect, texture, scaleMode, alphaBlend); } - public static void DrawMinMaxSlider(Rect rect, string label, ref float xValue, ref float yValue, float minValue, float maxValue) + public static void DrawMinMaxSlider(Rect rect, ref float xValue, ref float yValue, float minValue, float maxValue) { - DrawMinMaxSlider(rect, new GUIContent(label), ref xValue, ref yValue, minValue, maxValue); - } - - public static void DrawMinMaxSlider(Rect rect, GUIContent label, ref float xValue, ref float yValue, float minValue, float maxValue) - { - rect = EditorGUI.PrefixLabel(rect, label); - var fieldWidth = EditorGUIUtility.fieldWidth; var minFieldRect = new Rect(rect.xMin, rect.y, fieldWidth, rect.height); var maxFieldRect = new Rect(rect.xMax - fieldWidth, rect.y, fieldWidth, rect.height); //set slider rect between min and max fields + additional padding - var spacing = 8.0f; + const float spacing = 8.0f; var sliderRect = Rect.MinMaxRect(minFieldRect.xMax + spacing, rect.yMin, maxFieldRect.xMin - spacing, @@ -229,6 +222,17 @@ public static void DrawMinMaxSlider(Rect rect, GUIContent label, ref float xValu yValue = Mathf.Clamp(yValue, Mathf.Max(minValue, xValue), maxValue); } + public static void DrawMinMaxSlider(Rect rect, string label, ref float xValue, ref float yValue, float minValue, float maxValue) + { + DrawMinMaxSlider(rect, new GUIContent(label), ref xValue, ref yValue, minValue, maxValue); + } + + public static void DrawMinMaxSlider(Rect rect, GUIContent label, ref float xValue, ref float yValue, float minValue, float maxValue) + { + rect = EditorGUI.PrefixLabel(rect, label); + DrawMinMaxSlider(rect, ref xValue, ref yValue, minValue, maxValue); + } + public static void BoldLabel(Rect rect, string label) { BoldLabel(rect, new GUIContent(label)); diff --git a/Assets/Examples/Scenes/SampleScene.unity b/Assets/Examples/Scenes/SampleScene.unity index 67b4dcab..e487326b 100644 --- a/Assets/Examples/Scenes/SampleScene.unity +++ b/Assets/Examples/Scenes/SampleScene.unity @@ -1009,7 +1009,8 @@ MonoBehaviour: m_EditorClassIdentifier: targetTag: Untagged progressBar: 25.4 - var2: {x: 30.418846, y: 60.78535} + minMaxVector: {x: 0, y: 0} + minMaxVectorInt: {x: 0, y: 0} var8: {fileID: 977748987} preview: {fileID: 5059060190599569102, guid: 5573ca52cac7c2d4cb2536e37e9be1f1, type: 3} var10: 2.16 @@ -1027,6 +1028,7 @@ MonoBehaviour: prefabReference: {fileID: 0} bigNumber: 12345678 currency: 20.41 + veryVeryVeryVeryVeryLongName: 0 --- !u!4 &959025299 Transform: m_ObjectHideFlags: 2 diff --git a/Assets/Examples/Scripts/SampleBehaviour1.cs b/Assets/Examples/Scripts/SampleBehaviour1.cs index 16636ae9..afec37b6 100644 --- a/Assets/Examples/Scripts/SampleBehaviour1.cs +++ b/Assets/Examples/Scripts/SampleBehaviour1.cs @@ -17,7 +17,9 @@ public class SampleBehaviour1 : MonoBehaviour [Label("MinMax Slider", skinStyle: SkinStyle.Box)] [MinMaxSlider(10.0f, 100.0f)] - public Vector2 var2; + public Vector2 minMaxVector; + [MinMaxSlider(1, 8)] + public Vector2Int minMaxVectorInt; [Label("Asset Preview", skinStyle: SkinStyle.Box)] From 977a05dda777c0b20cf8ec28cdf75f9048d6f0be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Sat, 9 Dec 2023 01:55:28 +0100 Subject: [PATCH 2/6] Possibility to interact with ProgressBars (optionally) --- .../Regular/ProgressBarAttributeDrawer.cs | 65 ++++++++++++++++++- .../Regular/ProgressBarAttribute.cs | 2 + Assets/Examples/Scenes/SampleScene.unity | 7 +- Assets/Examples/Scripts/SampleBehaviour1.cs | 6 +- ProjectSettings/ProjectSettings.asset | 2 +- 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/Assets/Editor Toolbox/Editor/Drawers/Regular/ProgressBarAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Regular/ProgressBarAttributeDrawer.cs index 404c03fe..dffbddf2 100644 --- a/Assets/Editor Toolbox/Editor/Drawers/Regular/ProgressBarAttributeDrawer.cs +++ b/Assets/Editor Toolbox/Editor/Drawers/Regular/ProgressBarAttributeDrawer.cs @@ -6,6 +6,61 @@ namespace Toolbox.Editor.Drawers [CustomPropertyDrawer(typeof(ProgressBarAttribute))] public class ProgressBarAttributeDrawer : PropertyDrawerBase { + private static readonly int drawerHash = nameof(ProgressBarAttributeDrawer).GetHashCode(); + + private void HandleGuiEvents(SerializedProperty property, Rect progressBarRect) + { + var mousePosition = Event.current.mousePosition; + var id = GUIUtility.GetControlID(drawerHash, FocusType.Passive, progressBarRect); + switch (Event.current.GetTypeForControl(id)) + { + case EventType.MouseDown: + if (progressBarRect.Contains(mousePosition)) + { + GUIUtility.hotControl = id; + SetProgressValue(property, progressBarRect, mousePosition.x); + Event.current.Use(); + } + break; + case EventType.MouseDrag: + if (GUIUtility.hotControl == id) + { + SetProgressValue(property, progressBarRect, mousePosition.x); + Event.current.Use(); + } + break; + case EventType.MouseUp: + if (GUIUtility.hotControl == id) + { + GUIUtility.hotControl = 0; + Event.current.Use(); + } + break; + } + } + + private void SetProgressValue(SerializedProperty property, Rect progressBarRect, float xPosition) + { + var minValue = Attribute.MinValue; + var maxValue = Attribute.MaxValue; + + var range = progressBarRect.xMax - progressBarRect.xMin; + xPosition = Mathf.Clamp(xPosition - progressBarRect.xMin, 0, range); + + var fill = Mathf.Clamp01(xPosition / range); + var newValue = (maxValue - minValue) * fill + minValue; + + switch (property.propertyType) + { + case SerializedPropertyType.Integer: + property.intValue = Mathf.RoundToInt(newValue); + break; + case SerializedPropertyType.Float: + property.floatValue = newValue; + break; + } + } + protected override float GetPropertyHeightSafe(SerializedProperty property, GUIContent label) { return Style.barHeight; @@ -51,8 +106,14 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU position.y -= Style.textOffset; //finally draw the progress bar label EditorGUI.DropShadowLabel(position, labelText); - } + if (!attribute.IsInteractable) + { + return; + } + + HandleGuiEvents(property, position); + } public override bool IsPropertyValid(SerializedProperty property) { @@ -60,10 +121,8 @@ public override bool IsPropertyValid(SerializedProperty property) property.propertyType == SerializedPropertyType.Integer; } - private ProgressBarAttribute Attribute => attribute as ProgressBarAttribute; - private static class Style { internal static readonly float rowHeight = EditorGUIUtility.singleLineHeight; diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Regular/ProgressBarAttribute.cs b/Assets/Editor Toolbox/Runtime/Attributes/Regular/ProgressBarAttribute.cs index 9452f0fd..0db77f9c 100644 --- a/Assets/Editor Toolbox/Runtime/Attributes/Regular/ProgressBarAttribute.cs +++ b/Assets/Editor Toolbox/Runtime/Attributes/Regular/ProgressBarAttribute.cs @@ -34,5 +34,7 @@ public Color Color } public string HexColor { get; set; } + + public bool IsInteractable { get; set; } } } \ No newline at end of file diff --git a/Assets/Examples/Scenes/SampleScene.unity b/Assets/Examples/Scenes/SampleScene.unity index e487326b..823015b9 100644 --- a/Assets/Examples/Scenes/SampleScene.unity +++ b/Assets/Examples/Scenes/SampleScene.unity @@ -1008,9 +1008,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: targetTag: Untagged - progressBar: 25.4 - minMaxVector: {x: 0, y: 0} - minMaxVectorInt: {x: 0, y: 0} + progressBar1: 9.159664 + progressBar2: 25.4 + minMaxVector: {x: 10, y: 73.893524} + minMaxVectorInt: {x: 2, y: 7} var8: {fileID: 977748987} preview: {fileID: 5059060190599569102, guid: 5573ca52cac7c2d4cb2536e37e9be1f1, type: 3} var10: 2.16 diff --git a/Assets/Examples/Scripts/SampleBehaviour1.cs b/Assets/Examples/Scripts/SampleBehaviour1.cs index afec37b6..64be1c9f 100644 --- a/Assets/Examples/Scripts/SampleBehaviour1.cs +++ b/Assets/Examples/Scripts/SampleBehaviour1.cs @@ -11,8 +11,10 @@ public class SampleBehaviour1 : MonoBehaviour [Label("Progress Bar", skinStyle: SkinStyle.Box)] - [ProgressBar(minValue: -10.0f, maxValue: 50.0f, HexColor = "#234DEA")] - public float progressBar = 25.4f; + [ProgressBar(minValue: -10.0f, maxValue: 50.0f, HexColor = "#234DEA", IsInteractable = true)] + public float progressBar1 = 25.4f; + [ProgressBar(minValue: -10.0f, maxValue: 50.0f, HexColor = "#32A852", IsInteractable = false)] + public float progressBar2 = 25.4f; [Label("MinMax Slider", skinStyle: SkinStyle.Box)] diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index bc3d140f..3a8ee156 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -153,7 +153,7 @@ PlayerSettings: androidSupportedAspectRatio: 1 androidMaxAspectRatio: 2.1 applicationIdentifier: - Standalone: com.BroWarCollective.EditorToolbox + Standalone: com.BroWar-Collective.Editor-Toolbox buildNumber: Standalone: 0 iPhone: 0 From 2fbe20432e61bc82a4fa958e7e9861df2d5e9c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Sat, 9 Dec 2023 01:55:36 +0100 Subject: [PATCH 3/6] Minor refactor changes --- Assets/Editor Toolbox/Editor/ToolboxEditorSceneView.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/Editor Toolbox/Editor/ToolboxEditorSceneView.cs b/Assets/Editor Toolbox/Editor/ToolboxEditorSceneView.cs index 3303d9ac..deaab494 100644 --- a/Assets/Editor Toolbox/Editor/ToolboxEditorSceneView.cs +++ b/Assets/Editor Toolbox/Editor/ToolboxEditorSceneView.cs @@ -40,16 +40,16 @@ private static List GetObjectsUnderCursor() private static void UpdateEventCallback() { #if UNITY_2019_1_OR_NEWER - UnityEditor.SceneView.duringSceneGui -= SceneViewDuringSceneGUI; + UnityEditor.SceneView.duringSceneGui -= SceneViewDuringSceneGui; if (UseToolboxSceneView) { - UnityEditor.SceneView.duringSceneGui += SceneViewDuringSceneGUI; + UnityEditor.SceneView.duringSceneGui += SceneViewDuringSceneGui; } #endif } - private static void SceneViewDuringSceneGUI(UnityEditor.SceneView sceneView) + private static void SceneViewDuringSceneGui(UnityEditor.SceneView sceneView) { if (Event.current.type != EventType.KeyDown || Event.current.keyCode != SelectorKey) From 9c2fc2cedf00c17b3a45293475b1a36d18843f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Sun, 10 Dec 2023 14:41:36 +0100 Subject: [PATCH 4/6] Update documentation --- Assets/Editor Toolbox/README.md | 33 ++++++++++++++++++- .../Attributes/Regular/LabelWidthAttribute.cs | 5 +-- README.md | 33 ++++++++++++++++++- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/Assets/Editor Toolbox/README.md b/Assets/Editor Toolbox/README.md index 4fd891f0..b00c1d4c 100644 --- a/Assets/Editor Toolbox/README.md +++ b/Assets/Editor Toolbox/README.md @@ -85,6 +85,7 @@ Regular drawers have priority over Toolbox drawers and they cannot be mixed. #### TagSelectorAttribute +Supported types: **string**. ```csharp [TagSelector] public string var1; @@ -94,8 +95,9 @@ public string var1; #### ProgressBarAttribute +Supported types: **int**, **float**, **double**. ```csharp -[ProgressBar("Name", minValue: 0.0f, maxValue: 100.0f, HexColor = "#EB7D34")] +[ProgressBar("Name", minValue: 0.0f, maxValue: 100.0f, HexColor = "#EB7D34", IsInteractable = true)] public float var1 = 80.0f; ``` @@ -104,6 +106,7 @@ public float var1 = 80.0f; #### MinMaxSliderAttribute +Supported types: **Vector2, Vector2Int**. ```csharp [MinMaxSlider(0.5f, 71.7f)] public Vector2 var1; @@ -113,6 +116,7 @@ public Vector2 var1; #### AssetPreviewAttribute +Supported types: UnityEngine.**Object**. ```csharp [AssetPreview] public GameObject var1; @@ -124,11 +128,13 @@ public Component var2; #### SuffixAttribute +Supported types: **all**. ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/suffix.png) #### EnumTogglesAttribute +Supported types: **Enums**. ```csharp [System.Flags] public enum FlagExample @@ -154,22 +160,27 @@ public FlagExample enumFlag = FlagExample.Flag1 | FlagExample.Flag2 | FlagExampl #### NotNullAttribute +Supported types: UnityEngine.**Object**. ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull2.png) #### DirectoryAttribute +Supported types: **string**. ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory2.png) #### SceneNameAttribute +Supported types: **string**. ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename2.png) #### PresetAttribute +Supported types: **all**. +Remark: can be used only within classes, structs are not supported. ```csharp private readonly int[] presetValues = new[] { 1, 2, 3, 4, 5 }; @@ -189,6 +200,7 @@ public int presetTarget; #### SearchableEnumAttribute +Supported types: **Enums**. ```csharp [SearchableEnum] public KeyCode enumSearch; @@ -198,6 +210,7 @@ public KeyCode enumSearch; #### ClampAttribute +Supported types: **int, float, double**. ```csharp [Clamp(minValue = 1.5f, maxValue = 11.3f)] public double var1; @@ -205,6 +218,7 @@ public double var1; #### PasswordAttribute +Supported types: **string**. ```csharp [Password] public string password; @@ -214,16 +228,24 @@ public string password; #### ChildObjectOnlyAttribute +Supported types: **GameObject, Component**. + #### SceneObjectOnlyAttribute +Supported types: **GameObject, Component**. + #### PrefabObjectOnlyAttribute +Supported types: **GameObject, Component**. + #### LeftToggleAttribute +Supported types: **bool**. ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/lefttoggle.png) #### FormattedNumberAttribute +Supported types: **int, float, double**. ```csharp [FormattedNumber] public int bigNumber; @@ -233,6 +255,7 @@ public int bigNumber; #### LabelWidthAttribute +Supported types: **all**. ```csharp [LabelWidth(220.0f)] public int veryVeryVeryVeryVeryLongName; @@ -240,6 +263,14 @@ public int veryVeryVeryVeryVeryLongName; ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/labelwidth.png) +#### LayerAttribute + +Supported types: **int**. +```csharp +[Layer] +public int var1; +``` + --- ### Toolbox Drawers diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Regular/LabelWidthAttribute.cs b/Assets/Editor Toolbox/Runtime/Attributes/Regular/LabelWidthAttribute.cs index b5195dea..363fa555 100644 --- a/Assets/Editor Toolbox/Runtime/Attributes/Regular/LabelWidthAttribute.cs +++ b/Assets/Editor Toolbox/Runtime/Attributes/Regular/LabelWidthAttribute.cs @@ -4,8 +4,9 @@ namespace UnityEngine { /// - /// Change field label width. - /// Label width + /// Change field's label width. + /// + /// Supported types: all. /// [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] [Conditional("UNITY_EDITOR")] diff --git a/README.md b/README.md index 4fd891f0..b00c1d4c 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ Regular drawers have priority over Toolbox drawers and they cannot be mixed. #### TagSelectorAttribute +Supported types: **string**. ```csharp [TagSelector] public string var1; @@ -94,8 +95,9 @@ public string var1; #### ProgressBarAttribute +Supported types: **int**, **float**, **double**. ```csharp -[ProgressBar("Name", minValue: 0.0f, maxValue: 100.0f, HexColor = "#EB7D34")] +[ProgressBar("Name", minValue: 0.0f, maxValue: 100.0f, HexColor = "#EB7D34", IsInteractable = true)] public float var1 = 80.0f; ``` @@ -104,6 +106,7 @@ public float var1 = 80.0f; #### MinMaxSliderAttribute +Supported types: **Vector2, Vector2Int**. ```csharp [MinMaxSlider(0.5f, 71.7f)] public Vector2 var1; @@ -113,6 +116,7 @@ public Vector2 var1; #### AssetPreviewAttribute +Supported types: UnityEngine.**Object**. ```csharp [AssetPreview] public GameObject var1; @@ -124,11 +128,13 @@ public Component var2; #### SuffixAttribute +Supported types: **all**. ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/suffix.png) #### EnumTogglesAttribute +Supported types: **Enums**. ```csharp [System.Flags] public enum FlagExample @@ -154,22 +160,27 @@ public FlagExample enumFlag = FlagExample.Flag1 | FlagExample.Flag2 | FlagExampl #### NotNullAttribute +Supported types: UnityEngine.**Object**. ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull2.png) #### DirectoryAttribute +Supported types: **string**. ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory2.png) #### SceneNameAttribute +Supported types: **string**. ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename2.png) #### PresetAttribute +Supported types: **all**. +Remark: can be used only within classes, structs are not supported. ```csharp private readonly int[] presetValues = new[] { 1, 2, 3, 4, 5 }; @@ -189,6 +200,7 @@ public int presetTarget; #### SearchableEnumAttribute +Supported types: **Enums**. ```csharp [SearchableEnum] public KeyCode enumSearch; @@ -198,6 +210,7 @@ public KeyCode enumSearch; #### ClampAttribute +Supported types: **int, float, double**. ```csharp [Clamp(minValue = 1.5f, maxValue = 11.3f)] public double var1; @@ -205,6 +218,7 @@ public double var1; #### PasswordAttribute +Supported types: **string**. ```csharp [Password] public string password; @@ -214,16 +228,24 @@ public string password; #### ChildObjectOnlyAttribute +Supported types: **GameObject, Component**. + #### SceneObjectOnlyAttribute +Supported types: **GameObject, Component**. + #### PrefabObjectOnlyAttribute +Supported types: **GameObject, Component**. + #### LeftToggleAttribute +Supported types: **bool**. ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/lefttoggle.png) #### FormattedNumberAttribute +Supported types: **int, float, double**. ```csharp [FormattedNumber] public int bigNumber; @@ -233,6 +255,7 @@ public int bigNumber; #### LabelWidthAttribute +Supported types: **all**. ```csharp [LabelWidth(220.0f)] public int veryVeryVeryVeryVeryLongName; @@ -240,6 +263,14 @@ public int veryVeryVeryVeryVeryLongName; ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/labelwidth.png) +#### LayerAttribute + +Supported types: **int**. +```csharp +[Layer] +public int var1; +``` + --- ### Toolbox Drawers From ed500bb237ba03b0c8fa7f75639626cb1aeddd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Sun, 10 Dec 2023 15:10:14 +0100 Subject: [PATCH 5/6] Implement 'Revert Prefab Name' option in the GameObject/Prefabs context menu --- .../Editor/Utilities/PrefabUtility.cs | 41 +++++++++++++++++++ .../Editor/Utilities/PrefabUtility.cs.meta | 11 +++++ 2 files changed, 52 insertions(+) create mode 100644 Assets/Editor Toolbox/Editor/Utilities/PrefabUtility.cs create mode 100644 Assets/Editor Toolbox/Editor/Utilities/PrefabUtility.cs.meta diff --git a/Assets/Editor Toolbox/Editor/Utilities/PrefabUtility.cs b/Assets/Editor Toolbox/Editor/Utilities/PrefabUtility.cs new file mode 100644 index 00000000..60395862 --- /dev/null +++ b/Assets/Editor Toolbox/Editor/Utilities/PrefabUtility.cs @@ -0,0 +1,41 @@ +using UnityEditor; + +namespace Toolbox.Editor.Utilities +{ + public static class PrefabUtility + { + [MenuItem("GameObject/Prefab/Revert Prefab Name", true, -100)] + public static bool ValidateRevertPrefabName() + { + var gameObjects = Selection.gameObjects; + for (int i = 0; i < gameObjects.Length; i++) + { + var gameObject = gameObjects[i]; + if (UnityEditor.PrefabUtility.IsAnyPrefabInstanceRoot(gameObject)) + { + return true; + } + } + + return false; + } + + [MenuItem("GameObject/Prefab/Revert Prefab Name", false, -100)] + public static void RevertPrefabName() + { + var gameObjects = Selection.gameObjects; + Undo.RecordObjects(gameObjects, "Revert Prefab Name"); + for (int i = 0; i < gameObjects.Length; i++) + { + var gameObject = gameObjects[i]; + var prefabObject = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(gameObject); + if (prefabObject == null) + { + continue; + } + + gameObject.name = prefabObject.name; + } + } + } +} \ No newline at end of file diff --git a/Assets/Editor Toolbox/Editor/Utilities/PrefabUtility.cs.meta b/Assets/Editor Toolbox/Editor/Utilities/PrefabUtility.cs.meta new file mode 100644 index 00000000..190dd1c0 --- /dev/null +++ b/Assets/Editor Toolbox/Editor/Utilities/PrefabUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f171f01987720294989f82500c6d02aa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 193cfac4dc36bc0659d152f859bf8edccddc1601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Matkowski?= Date: Sun, 10 Dec 2023 15:10:58 +0100 Subject: [PATCH 6/6] Update: README.md, package.json, CHANGELOG.md --- Assets/Editor Toolbox/CHANGELOG.md | 9 +++++++++ Assets/Editor Toolbox/README.md | 17 +++++++++++++++++ Assets/Editor Toolbox/package.json | 2 +- README.md | 17 +++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Assets/Editor Toolbox/CHANGELOG.md b/Assets/Editor Toolbox/CHANGELOG.md index f625e43c..cf21d2d8 100644 --- a/Assets/Editor Toolbox/CHANGELOG.md +++ b/Assets/Editor Toolbox/CHANGELOG.md @@ -1,3 +1,12 @@ +## 0.12.7 [10.12.2023] + +### Changed: +- Possibility to interact with ProgressBarDrawer (added IsInteractable property to the ProgressBarAttribute) +- MinMaxAttribute now supports Vector2Int + +### Added: +- 'Revert Prefab Name' option for prefabs in the GameObject/Prefabs context menu + ## 0.12.6 [19.10.2023] ### Changed: diff --git a/Assets/Editor Toolbox/README.md b/Assets/Editor Toolbox/README.md index b00c1d4c..f79899ec 100644 --- a/Assets/Editor Toolbox/README.md +++ b/Assets/Editor Toolbox/README.md @@ -86,6 +86,7 @@ Regular drawers have priority over Toolbox drawers and they cannot be mixed. #### TagSelectorAttribute Supported types: **string**. + ```csharp [TagSelector] public string var1; @@ -96,6 +97,7 @@ public string var1; #### ProgressBarAttribute Supported types: **int**, **float**, **double**. + ```csharp [ProgressBar("Name", minValue: 0.0f, maxValue: 100.0f, HexColor = "#EB7D34", IsInteractable = true)] public float var1 = 80.0f; @@ -107,6 +109,7 @@ public float var1 = 80.0f; #### MinMaxSliderAttribute Supported types: **Vector2, Vector2Int**. + ```csharp [MinMaxSlider(0.5f, 71.7f)] public Vector2 var1; @@ -117,6 +120,7 @@ public Vector2 var1; #### AssetPreviewAttribute Supported types: UnityEngine.**Object**. + ```csharp [AssetPreview] public GameObject var1; @@ -129,12 +133,14 @@ public Component var2; #### SuffixAttribute Supported types: **all**. + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/suffix.png) #### EnumTogglesAttribute Supported types: **Enums**. + ```csharp [System.Flags] public enum FlagExample @@ -161,6 +167,7 @@ public FlagExample enumFlag = FlagExample.Flag1 | FlagExample.Flag2 | FlagExampl #### NotNullAttribute Supported types: UnityEngine.**Object**. + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull2.png) @@ -168,18 +175,21 @@ Supported types: UnityEngine.**Object**. #### DirectoryAttribute Supported types: **string**. + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory2.png) #### SceneNameAttribute Supported types: **string**. + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename2.png) #### PresetAttribute Supported types: **all**. + Remark: can be used only within classes, structs are not supported. ```csharp private readonly int[] presetValues = new[] { 1, 2, 3, 4, 5 }; @@ -201,6 +211,7 @@ public int presetTarget; #### SearchableEnumAttribute Supported types: **Enums**. + ```csharp [SearchableEnum] public KeyCode enumSearch; @@ -211,6 +222,7 @@ public KeyCode enumSearch; #### ClampAttribute Supported types: **int, float, double**. + ```csharp [Clamp(minValue = 1.5f, maxValue = 11.3f)] public double var1; @@ -219,6 +231,7 @@ public double var1; #### PasswordAttribute Supported types: **string**. + ```csharp [Password] public string password; @@ -241,11 +254,13 @@ Supported types: **GameObject, Component**. #### LeftToggleAttribute Supported types: **bool**. + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/lefttoggle.png) #### FormattedNumberAttribute Supported types: **int, float, double**. + ```csharp [FormattedNumber] public int bigNumber; @@ -256,6 +271,7 @@ public int bigNumber; #### LabelWidthAttribute Supported types: **all**. + ```csharp [LabelWidth(220.0f)] public int veryVeryVeryVeryVeryLongName; @@ -266,6 +282,7 @@ public int veryVeryVeryVeryVeryLongName; #### LayerAttribute Supported types: **int**. + ```csharp [Layer] public int var1; diff --git a/Assets/Editor Toolbox/package.json b/Assets/Editor Toolbox/package.json index 2cf1cbe4..1f7a7391 100644 --- a/Assets/Editor Toolbox/package.json +++ b/Assets/Editor Toolbox/package.json @@ -1,7 +1,7 @@ { "name": "com.browar.editor-toolbox", "displayName": "Editor Toolbox", - "version": "0.12.6", + "version": "0.12.7", "unity": "2018.1", "description": "Tools, custom attributes, drawers, hierarchy overlay, and other extensions for the Unity Editor.", "keywords": [ diff --git a/README.md b/README.md index b00c1d4c..f79899ec 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Regular drawers have priority over Toolbox drawers and they cannot be mixed. #### TagSelectorAttribute Supported types: **string**. + ```csharp [TagSelector] public string var1; @@ -96,6 +97,7 @@ public string var1; #### ProgressBarAttribute Supported types: **int**, **float**, **double**. + ```csharp [ProgressBar("Name", minValue: 0.0f, maxValue: 100.0f, HexColor = "#EB7D34", IsInteractable = true)] public float var1 = 80.0f; @@ -107,6 +109,7 @@ public float var1 = 80.0f; #### MinMaxSliderAttribute Supported types: **Vector2, Vector2Int**. + ```csharp [MinMaxSlider(0.5f, 71.7f)] public Vector2 var1; @@ -117,6 +120,7 @@ public Vector2 var1; #### AssetPreviewAttribute Supported types: UnityEngine.**Object**. + ```csharp [AssetPreview] public GameObject var1; @@ -129,12 +133,14 @@ public Component var2; #### SuffixAttribute Supported types: **all**. + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/suffix.png) #### EnumTogglesAttribute Supported types: **Enums**. + ```csharp [System.Flags] public enum FlagExample @@ -161,6 +167,7 @@ public FlagExample enumFlag = FlagExample.Flag1 | FlagExample.Flag2 | FlagExampl #### NotNullAttribute Supported types: UnityEngine.**Object**. + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/notnull2.png) @@ -168,18 +175,21 @@ Supported types: UnityEngine.**Object**. #### DirectoryAttribute Supported types: **string**. + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/directory2.png) #### SceneNameAttribute Supported types: **string**. + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename1.png)\ ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/scenename2.png) #### PresetAttribute Supported types: **all**. + Remark: can be used only within classes, structs are not supported. ```csharp private readonly int[] presetValues = new[] { 1, 2, 3, 4, 5 }; @@ -201,6 +211,7 @@ public int presetTarget; #### SearchableEnumAttribute Supported types: **Enums**. + ```csharp [SearchableEnum] public KeyCode enumSearch; @@ -211,6 +222,7 @@ public KeyCode enumSearch; #### ClampAttribute Supported types: **int, float, double**. + ```csharp [Clamp(minValue = 1.5f, maxValue = 11.3f)] public double var1; @@ -219,6 +231,7 @@ public double var1; #### PasswordAttribute Supported types: **string**. + ```csharp [Password] public string password; @@ -241,11 +254,13 @@ Supported types: **GameObject, Component**. #### LeftToggleAttribute Supported types: **bool**. + ![inspector](https://github.com/arimger/Unity-Editor-Toolbox/blob/develop/Docs/lefttoggle.png) #### FormattedNumberAttribute Supported types: **int, float, double**. + ```csharp [FormattedNumber] public int bigNumber; @@ -256,6 +271,7 @@ public int bigNumber; #### LabelWidthAttribute Supported types: **all**. + ```csharp [LabelWidth(220.0f)] public int veryVeryVeryVeryVeryLongName; @@ -266,6 +282,7 @@ public int veryVeryVeryVeryVeryLongName; #### LayerAttribute Supported types: **int**. + ```csharp [Layer] public int var1;