diff --git a/Assets/Plugins/Editor/Vexe/Drawers/API/Core/RecursiveDrawer.cs b/Assets/Plugins/Editor/Vexe/Drawers/API/Core/RecursiveDrawer.cs index f835e35..8e05564 100644 --- a/Assets/Plugins/Editor/Vexe/Drawers/API/Core/RecursiveDrawer.cs +++ b/Assets/Plugins/Editor/Vexe/Drawers/API/Core/RecursiveDrawer.cs @@ -29,6 +29,7 @@ public class RecursiveDrawer : ObjectDrawer private Func _getDraggedObject; private Func, Action, string, Tab> _newTypeTab; private Func, string, Tab> _newUnityTab; + private bool _disablePicker, _autoAlloc; protected override void Initialize() { @@ -112,12 +113,29 @@ protected override void Initialize() ArrayUtility.Add(ref systemTypes, memberType); _tabs[idx] = _newTypeTab(() => systemTypes, TryCreateInstance, "System Type"); + + var display = attributes.GetAttribute(); + if (display != null) + { + _autoAlloc = (display.ObjOpt & Obj.AutoAlloc) != 0; + _disablePicker = (display.ObjOpt & Obj.DisablePicker) != 0; + } } public override void OnGUI() { using (gui.Horizontal()) { + if (_autoAlloc && memberValue == null) + { + if (memberType.IsA()) + Debug.Log("Cannot automatically allocate memory for UnityObject member: " + member.NiceName); + else if (memberType.IsAbstract) + Debug.Log("Cannot automatically allocate memory for abstract member: " + member.NiceName); + else + memberValue = memberType.ActivatorInstance(); + } + var isEmpty = string.IsNullOrEmpty(displayText); var label = isEmpty ? string.Empty : displayText + " " + (foldout ? "^" : ">"); var value = member.Value; @@ -172,7 +190,7 @@ public override void OnGUI() { var mb = unityObj as MonoBehaviour; if (mb != null) - { + { var monoscript = MonoScript.FromMonoBehaviour(mb); var scriptPath = AssetDatabase.GetAssetPath(monoscript); UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(scriptPath, 0); @@ -195,12 +213,15 @@ public override void OnGUI() gui.Cursor(thumbRect, MouseCursor.Link); // Selection/thumb button - { + { if (e.IsMouseContained(thumbRect) && e.IsMouseDown()) { if (e.IsLMB()) { - SelectionWindow.Show("Select a `" + memberTypeName + "` object", _tabs); + if (_disablePicker) + memberValue = memberType.ActivatorInstance(); + else + SelectionWindow.Show("Select a `" + memberTypeName + "` object", _tabs); } else if (e.IsRMB()) { diff --git a/Assets/Plugins/Vexe/Runtime/Types/Attributes/API/DisplayAttribute.cs b/Assets/Plugins/Vexe/Runtime/Types/Attributes/API/DisplayAttribute.cs index aeb665d..5673a87 100644 --- a/Assets/Plugins/Vexe/Runtime/Types/Attributes/API/DisplayAttribute.cs +++ b/Assets/Plugins/Vexe/Runtime/Types/Attributes/API/DisplayAttribute.cs @@ -56,12 +56,22 @@ public float Order /// public Dict DictOpt; + /// + /// Customizes the dispaly of class/struct fields + /// + public Obj ObjOpt; + public float? DisplayOrder; public DisplayAttribute() { } + public DisplayAttribute(Obj objOpt) + { + this.ObjOpt = objOpt; + } + public DisplayAttribute(Seq seqOpt) { this.SeqOpt = seqOpt; @@ -83,6 +93,20 @@ public DisplayAttribute(string formatLabel) } } + [Flags] + public enum Obj + { + /// + /// Automatically tries to allocate value for the member if it was null + /// + AutoAlloc = 1, + + /// + /// Makes it not possible to show the selection window changing the object type + /// + DisablePicker = 1 << 1, + } + [Flags] public enum Dict {