Skip to content

Commit 080c399

Browse files
committed
Possibility to apply property condition state (disabled/hidden) to associated decorators [WIP]
1 parent 5b2f6e4 commit 080c399

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

Assets/Editor Toolbox/Editor/ToolboxPropertyHandler.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ private void DrawProperty(SerializedProperty property, GUIContent label)
293293
}
294294
}
295295

296-
private void BeginDecoratorDrawers()
296+
private void BeginDecoratorDrawers(PropertyCondition conditionState = PropertyCondition.Valid)
297297
{
298298
if (!hasToolboxDecoratorDrawer)
299299
{
@@ -302,11 +302,33 @@ private void BeginDecoratorDrawers()
302302

303303
for (var i = 0; i < decoratorAttributes.Count; i++)
304304
{
305-
ToolboxDrawerModule.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiBegin(decoratorAttributes[i]);
305+
var attribute = decoratorAttributes[i];
306+
var drawer = ToolboxDrawerModule.GetDecoratorDrawer(attribute);
307+
if (drawer == null)
308+
{
309+
continue;
310+
}
311+
312+
if (attribute.ApplyCondition)
313+
{
314+
var isValid = conditionState != PropertyCondition.NonValid;
315+
var disable = conditionState == PropertyCondition.Disabled;
316+
if (isValid)
317+
{
318+
using (new EditorGUI.DisabledScope(disable))
319+
{
320+
drawer.OnGuiBegin(attribute);
321+
}
322+
}
323+
}
324+
else
325+
{
326+
drawer.OnGuiBegin(attribute);
327+
}
306328
}
307329
}
308330

309-
private void CloseDecoratorDrawers()
331+
private void CloseDecoratorDrawers(PropertyCondition conditionState = PropertyCondition.Valid)
310332
{
311333
if (!hasToolboxDecoratorDrawer)
312334
{
@@ -363,11 +385,10 @@ public void OnGuiLayout(SerializedProperty property, GUIContent label)
363385
//using custom attributes and information about native drawers
364386
//we can use all associated and allowed ToolboxDrawers (for each type)
365387

366-
//begin all needed decorator drawers in the proper order
367-
BeginDecoratorDrawers();
368-
369388
//handle condition attribute and draw property if possible
370389
var conditionState = Validate(property);
390+
//begin all needed decorator drawers in the proper order
391+
BeginDecoratorDrawers(conditionState);
371392
var isValid = conditionState != PropertyCondition.NonValid;
372393
var disable = conditionState == PropertyCondition.Disabled;
373394
if (isValid)
@@ -382,7 +403,7 @@ public void OnGuiLayout(SerializedProperty property, GUIContent label)
382403
}
383404

384405
//close all needed decorator drawers in the proper order
385-
CloseDecoratorDrawers();
406+
CloseDecoratorDrawers(conditionState);
386407
}
387408

388409
/// <summary>

Assets/Examples/Scripts/SampleBehaviour4.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ public class SampleBehaviour4 : MonoBehaviour
88
{
99
[Label("Help", skinStyle: SkinStyle.Box)]
1010

11+
[Disable]
1112
[Help("Very useful warning", UnityMessageType.Warning)]
12-
[Help("This error example", UnityMessageType.Error)]
13+
[Help("This error example", UnityMessageType.Error, ApplyCondition = true)]
1314
[Help("Simple information", UnityMessageType.Info)]
1415
public int var0;
1516

0 commit comments

Comments
 (0)