private void BeginDecoratorDrawers() { if (!hasToolboxDecoratorDrawer) { return; } for (var i = 0; i < decoratorAttributes.Count; i++) { ToolboxDrawerModule.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiBegin(decoratorAttributes[i]); } }
private void CloseDecoratorDrawers() { if (!hasToolboxDecoratorDrawer) { return; } for (var i = decoratorAttributes.Count - 1; i >= 0; i--) { ToolboxDrawerModule.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiClose(decoratorAttributes[i]); } }
/// <summary> /// Draw property using built-in layout system and cached <see cref="ToolboxAttributeDrawer"/>s. /// </summary> public void OnGuiLayout() { //depending on previously gained data we can provide more action //using custom attributes and information about native drawers //we can use associated ToolboxDrawers or/and draw property in the default way //begin all needed decorator drawers in the proper order if (hasToolboxDecoratorDrawer) { for (var i = 0; i < decoratorAttributes.Length; i++) { ToolboxDrawerModule.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiBegin(decoratorAttributes[i]); } } //handle condition attribute(only one allowed) var conditionState = PropertyCondition.Valid; if (hasToolboxConditionDrawer) { conditionState = ToolboxDrawerModule.GetConditionDrawer(conditionAttribute)?.OnGuiValidate(property, conditionAttribute) ?? conditionState; } if (conditionState == PropertyCondition.NonValid) { goto Finish; } //disable property field if it is needed if (conditionState == PropertyCondition.Disabled) { EditorGUI.BeginDisabledGroup(true); } //get toolbox drawer for the property or draw it in the default way if (hasToolboxPropertyDrawer && (!hasNativePropertyDrawer || isArray)) { //NOTE: attribute-related drawers have priority if (hasToolboxPropertyAttributeDrawer) { //draw target property using the associated attribute var propertyDrawer = isArray ? ToolboxDrawerModule.GetListPropertyDrawer(propertyAttribute.GetType()) : ToolboxDrawerModule.GetSelfPropertyDrawer(propertyAttribute.GetType()); propertyDrawer?.OnGui(property, label, propertyAttribute); } else { //draw target property using the associated type drawer ToolboxDrawerModule.GetTargetTypeDrawer(type)?.OnGui(property, label); } } else { if (hasToolboxPropertyDrawer) { //TODO: warning //NOTE: since property has a custom drawer it will override any Toolbox-related one } OnGuiDefault(); } //end disabled state check if (conditionState == PropertyCondition.Disabled) { EditorGUI.EndDisabledGroup(); } Finish: //end all needed decorator drawers in the proper order if (hasToolboxDecoratorDrawer) { for (var i = decoratorAttributes.Length - 1; i >= 0; i--) { ToolboxDrawerModule.GetDecoratorDrawer(decoratorAttributes[i])?.OnGuiEnd(decoratorAttributes[i]); } } }