Skip to content

Commit 015d5dd

Browse files
committed
Implement DisableInEditModeAttribute & Drawer
1 parent e879517 commit 015d5dd

File tree

7 files changed

+71
-30
lines changed

7 files changed

+71
-30
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace Toolbox.Editor.Drawers
5+
{
6+
public class DisableInEditModeAttributeDrawer : ToolboxConditionDrawer<DisableInEditModeAttribute>
7+
{
8+
protected override PropertyCondition OnGuiValidateSafe(SerializedProperty property, DisableInEditModeAttribute attribute)
9+
{
10+
return !EditorApplication.isPlayingOrWillChangePlaymode ? PropertyCondition.Disabled : PropertyCondition.Valid;
11+
}
12+
}
13+
}

Assets/Editor Toolbox/Editor/Drawers/Toolbox/Condition/DisableInEditModeAttributeDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor Toolbox/EditorSettings.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ MonoBehaviour:
7575
conditionDrawerHandlers:
7676
- typeReference: Toolbox.Editor.Drawers.DisableAttributeDrawer, Toolbox.Editor
7777
- typeReference: Toolbox.Editor.Drawers.DisableIfAttributeDrawer, Toolbox.Editor
78+
- typeReference: Toolbox.Editor.Drawers.DisableInEditModeAttributeDrawer, Toolbox.Editor
7879
- typeReference: Toolbox.Editor.Drawers.DisableInPlayModeAttributeDrawer, Toolbox.Editor
7980
- typeReference: Toolbox.Editor.Drawers.EnableIfAttributeDrawer, Toolbox.Editor
8081
- typeReference: Toolbox.Editor.Drawers.HideAttributeDrawer, Toolbox.Editor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace UnityEngine
5+
{
6+
/// <summary>
7+
/// Marks serialized field as read-only but only in the EditMode.
8+
///
9+
/// <para>Supported types: all.</para>
10+
/// </summary>
11+
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
12+
[Conditional("UNITY_EDITOR")]
13+
public class DisableInEditModeAttribute : ToolboxConditionAttribute
14+
{ }
15+
}

Assets/Editor Toolbox/Runtime/Attributes/Property/Toolbox/ConditionAttributes/DisableInEditModeAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Examples/Scenes/SampleScene.unity

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,9 +1027,9 @@ MonoBehaviour:
10271027
sceneReference: {fileID: 0}
10281028
childReference: {fileID: 0}
10291029
prefabReference: {fileID: 0}
1030+
notPrefabReference: {fileID: 0}
10301031
bigNumber: 12345678
10311032
currency: 20.41
1032-
veryVeryVeryVeryVeryLongName: 0
10331033
--- !u!4 &959025299
10341034
Transform:
10351035
m_ObjectHideFlags: 2
@@ -1530,6 +1530,7 @@ MonoBehaviour:
15301530
var39: 18
15311531
var55: 0
15321532
var56: 0
1533+
veryVeryVeryVeryVeryLongName: 0
15331534
var57: 0
15341535
--- !u!4 &1438743619
15351536
Transform:
@@ -1574,23 +1575,6 @@ MonoBehaviour:
15741575
m_Script: {fileID: 11500000, guid: c48a231d0fb97494d948757fb057b3ea, type: 3}
15751576
m_Name:
15761577
m_EditorClassIdentifier:
1577-
gos1:
1578-
- {fileID: 0}
1579-
gos2:
1580-
- {fileID: 0}
1581-
- {fileID: 0}
1582-
- {fileID: 0}
1583-
- {fileID: 0}
1584-
- {fileID: 0}
1585-
- {fileID: 0}
1586-
- {fileID: 0}
1587-
- {fileID: 0}
1588-
- {fileID: 0}
1589-
- {fileID: 0}
1590-
go1: {fileID: 1670253091}
1591-
go2: {fileID: 0}
1592-
go3: 0
1593-
go4: 0
15941578
var1: 25.4
15951579
var2: {fileID: 977748988}
15961580
var3: 0
@@ -1701,16 +1685,17 @@ MonoBehaviour:
17011685
stringValue: sho
17021686
var33: 0
17031687
objectValue: {fileID: 0}
1704-
var36: 0
1688+
var34: 0
17051689
floatValue: 0.46
1706-
var37: 0
1707-
enumValue: 97
17081690
var35: 0
1709-
var41: 00000000000000000000000000000000
1691+
enumValue: 97
1692+
var36: 0
1693+
var37:
1694+
var38: 0
17101695
var39: 0
17111696
var40: 2
1697+
var41: 0
17121698
var42: 0
1713-
var43: 0
17141699
--- !u!1 &1972418676
17151700
GameObject:
17161701
m_ObjectHideFlags: 0

Assets/Examples/Scripts/SampleBehaviour3.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public string GetStringValue()
2121
[Help("Assign any GameObject")]
2222
public GameObject objectValue;
2323
[HideIf(nameof(ObjectValue), false)]
24-
public int var36;
24+
public int var34;
2525

2626
private GameObject ObjectValue
2727
{
@@ -33,22 +33,27 @@ private GameObject ObjectValue
3333
[Help("Set value to > 0.5")]
3434
public float floatValue = 1.0f;
3535
[EnableIf(nameof(floatValue), 0.5f, Comparison = UnityComparisonMethod.Greater)]
36-
public int var37;
36+
public int var35;
3737

3838
[Label("Disable If", skinStyle: SkinStyle.Box)]
3939

4040
public KeyCode enumValue = KeyCode.A;
4141
[DisableIf(nameof(enumValue), KeyCode.A)]
42-
public int var35;
42+
public int var36;
4343

4444
[Label("Disable", skinStyle: SkinStyle.Box)]
4545

4646
[Disable]
47-
public int[] var41= new int[4];
47+
public int[] var37 = new int[4];
4848

49-
[Label("Disable In Playmode", skinStyle: SkinStyle.Box)]
49+
[Label("Disable In Play Mode", skinStyle: SkinStyle.Box)]
5050

5151
[DisableInPlayMode]
52+
public int var38;
53+
54+
[Label("Disable In Edit Mode", skinStyle: SkinStyle.Box)]
55+
56+
[DisableInEditMode]
5257
public int var39;
5358

5459
[Label("Show Warning If", skinStyle: SkinStyle.Box)]
@@ -59,10 +64,10 @@ private GameObject ObjectValue
5964
[Label("Show Disabled If", skinStyle: SkinStyle.Box)]
6065

6166
[ShowDisabledIf(nameof(var40), 3, Comparison = UnityComparisonMethod.LessEqual)]
62-
public int var42;
67+
public int var41;
6368

6469
[Label("Hide Disabled If", skinStyle: SkinStyle.Box)]
6570

6671
[HideDisabledIf(nameof(var40), 3, Comparison = UnityComparisonMethod.GreaterEqual)]
67-
public int var43;
72+
public int var42;
6873
}

0 commit comments

Comments
 (0)