diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Condition/DisableInEditModeAttributeDrawer.cs b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Condition/DisableInEditModeAttributeDrawer.cs new file mode 100644 index 00000000..da06462e --- /dev/null +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Condition/DisableInEditModeAttributeDrawer.cs @@ -0,0 +1,13 @@ +using UnityEditor; +using UnityEngine; + +namespace Toolbox.Editor.Drawers +{ + public class DisableInEditModeAttributeDrawer : ToolboxConditionDrawer + { + protected override PropertyCondition OnGuiValidateSafe(SerializedProperty property, DisableInEditModeAttribute attribute) + { + return !EditorApplication.isPlayingOrWillChangePlaymode ? PropertyCondition.Disabled : PropertyCondition.Valid; + } + } +} \ No newline at end of file diff --git a/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Condition/DisableInEditModeAttributeDrawer.cs.meta b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Condition/DisableInEditModeAttributeDrawer.cs.meta new file mode 100644 index 00000000..5a25dde5 --- /dev/null +++ b/Assets/Editor Toolbox/Editor/Drawers/Toolbox/Condition/DisableInEditModeAttributeDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d5c4b58349e74f54a956ec5617c5f6a5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Editor Toolbox/EditorSettings.asset b/Assets/Editor Toolbox/EditorSettings.asset index 1f90d876..e3bc1311 100644 --- a/Assets/Editor Toolbox/EditorSettings.asset +++ b/Assets/Editor Toolbox/EditorSettings.asset @@ -75,6 +75,7 @@ MonoBehaviour: conditionDrawerHandlers: - typeReference: Toolbox.Editor.Drawers.DisableAttributeDrawer, Toolbox.Editor - typeReference: Toolbox.Editor.Drawers.DisableIfAttributeDrawer, Toolbox.Editor + - typeReference: Toolbox.Editor.Drawers.DisableInEditModeAttributeDrawer, Toolbox.Editor - typeReference: Toolbox.Editor.Drawers.DisableInPlayModeAttributeDrawer, Toolbox.Editor - typeReference: Toolbox.Editor.Drawers.EnableIfAttributeDrawer, Toolbox.Editor - typeReference: Toolbox.Editor.Drawers.HideAttributeDrawer, Toolbox.Editor diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/ConditionAttributes/DisableInEditModeAttribute.cs b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/ConditionAttributes/DisableInEditModeAttribute.cs new file mode 100644 index 00000000..4b6c7b45 --- /dev/null +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/ConditionAttributes/DisableInEditModeAttribute.cs @@ -0,0 +1,15 @@ +using System; +using System.Diagnostics; + +namespace UnityEngine +{ + /// + /// Marks serialized field as read-only but only in the EditMode. + /// + /// Supported types: all. + /// + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] + [Conditional("UNITY_EDITOR")] + public class DisableInEditModeAttribute : ToolboxConditionAttribute + { } +} \ No newline at end of file diff --git a/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/ConditionAttributes/DisableInEditModeAttribute.cs.meta b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/ConditionAttributes/DisableInEditModeAttribute.cs.meta new file mode 100644 index 00000000..56ba97d1 --- /dev/null +++ b/Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/ConditionAttributes/DisableInEditModeAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1fb36dd13fa8079488cdaa422d7653b1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Examples/Scenes/SampleScene.unity b/Assets/Examples/Scenes/SampleScene.unity index ffb9dbfe..071a9441 100644 --- a/Assets/Examples/Scenes/SampleScene.unity +++ b/Assets/Examples/Scenes/SampleScene.unity @@ -1027,9 +1027,9 @@ MonoBehaviour: sceneReference: {fileID: 0} childReference: {fileID: 0} prefabReference: {fileID: 0} + notPrefabReference: {fileID: 0} bigNumber: 12345678 currency: 20.41 - veryVeryVeryVeryVeryLongName: 0 --- !u!4 &959025299 Transform: m_ObjectHideFlags: 2 @@ -1530,6 +1530,7 @@ MonoBehaviour: var39: 18 var55: 0 var56: 0 + veryVeryVeryVeryVeryLongName: 0 var57: 0 --- !u!4 &1438743619 Transform: @@ -1574,23 +1575,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c48a231d0fb97494d948757fb057b3ea, type: 3} m_Name: m_EditorClassIdentifier: - gos1: - - {fileID: 0} - gos2: - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - - {fileID: 0} - go1: {fileID: 1670253091} - go2: {fileID: 0} - go3: 0 - go4: 0 var1: 25.4 var2: {fileID: 977748988} var3: 0 @@ -1701,16 +1685,17 @@ MonoBehaviour: stringValue: sho var33: 0 objectValue: {fileID: 0} - var36: 0 + var34: 0 floatValue: 0.46 - var37: 0 - enumValue: 97 var35: 0 - var41: 00000000000000000000000000000000 + enumValue: 97 + var36: 0 + var37: + var38: 0 var39: 0 var40: 2 + var41: 0 var42: 0 - var43: 0 --- !u!1 &1972418676 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Examples/Scripts/SampleBehaviour3.cs b/Assets/Examples/Scripts/SampleBehaviour3.cs index 89014731..c785f834 100644 --- a/Assets/Examples/Scripts/SampleBehaviour3.cs +++ b/Assets/Examples/Scripts/SampleBehaviour3.cs @@ -21,7 +21,7 @@ public string GetStringValue() [Help("Assign any GameObject")] public GameObject objectValue; [HideIf(nameof(ObjectValue), false)] - public int var36; + public int var34; private GameObject ObjectValue { @@ -33,22 +33,27 @@ private GameObject ObjectValue [Help("Set value to > 0.5")] public float floatValue = 1.0f; [EnableIf(nameof(floatValue), 0.5f, Comparison = UnityComparisonMethod.Greater)] - public int var37; + public int var35; [Label("Disable If", skinStyle: SkinStyle.Box)] public KeyCode enumValue = KeyCode.A; [DisableIf(nameof(enumValue), KeyCode.A)] - public int var35; + public int var36; [Label("Disable", skinStyle: SkinStyle.Box)] [Disable] - public int[] var41= new int[4]; + public int[] var37 = new int[4]; - [Label("Disable In Playmode", skinStyle: SkinStyle.Box)] + [Label("Disable In Play Mode", skinStyle: SkinStyle.Box)] [DisableInPlayMode] + public int var38; + + [Label("Disable In Edit Mode", skinStyle: SkinStyle.Box)] + + [DisableInEditMode] public int var39; [Label("Show Warning If", skinStyle: SkinStyle.Box)] @@ -59,10 +64,10 @@ private GameObject ObjectValue [Label("Show Disabled If", skinStyle: SkinStyle.Box)] [ShowDisabledIf(nameof(var40), 3, Comparison = UnityComparisonMethod.LessEqual)] - public int var42; + public int var41; [Label("Hide Disabled If", skinStyle: SkinStyle.Box)] [HideDisabledIf(nameof(var40), 3, Comparison = UnityComparisonMethod.GreaterEqual)] - public int var43; + public int var42; } \ No newline at end of file