Skip to content

Commit

Permalink
Implement DisableInEditModeAttribute & Drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
arimger committed Jul 28, 2024
1 parent e879517 commit 015d5dd
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using UnityEditor;
using UnityEngine;

namespace Toolbox.Editor.Drawers
{
public class DisableInEditModeAttributeDrawer : ToolboxConditionDrawer<DisableInEditModeAttribute>
{
protected override PropertyCondition OnGuiValidateSafe(SerializedProperty property, DisableInEditModeAttribute attribute)
{
return !EditorApplication.isPlayingOrWillChangePlaymode ? PropertyCondition.Disabled : PropertyCondition.Valid;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Assets/Editor Toolbox/EditorSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Diagnostics;

namespace UnityEngine
{
/// <summary>
/// Marks serialized field as read-only but only in the EditMode.
///
/// <para>Supported types: all.</para>
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
[Conditional("UNITY_EDITOR")]
public class DisableInEditModeAttribute : ToolboxConditionAttribute
{ }
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 8 additions & 23 deletions Assets/Examples/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1530,6 +1530,7 @@ MonoBehaviour:
var39: 18
var55: 0
var56: 0
veryVeryVeryVeryVeryLongName: 0
var57: 0
--- !u!4 &1438743619
Transform:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions Assets/Examples/Scripts/SampleBehaviour3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)]
Expand All @@ -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;
}

0 comments on commit 015d5dd

Please sign in to comment.