public void ManageMembers(out bool valueChanged) { if (m_membersCache == null || m_membersCache.Count == 0) { valueChanged = false; return; } m_drawnGroups.Clear(); m_drawnFoldableGroups.Clear(); valueChanged = false; for (short i = 0; i < m_membersCache.Count; i++) { var mightyMember = m_membersCache[i]; mightyMember.DrawIndex = i; if (!valueChanged) { EditorGUI.BeginChangeCheck(); } ManageGroups(mightyMember, ref valueChanged); valueChanged = valueChanged || EditorGUI.EndChangeCheck() || MightyEditorUtilities.HasEditorChanged(); } }
public override void OnInspectorAbort(MightyDrawer drawer) { if (!MightyEditorUtilities.HasEditorChanged() || drawer == null) { return; } drawer.ApplyAutoValues(); drawer.RefreshAllDrawers(); }
public override void OnInspectorAbort(MightyDrawer drawer) { if (MightyEditorUtilities.HasEditorChanged() && drawer != null) { drawer.ApplyAutoValues(); drawer.RefreshAllDrawers(); } GUILayout.BeginVertical(); }
public void ApplyAutoValue() { if (!TryGetAttribute(out BaseAutoValueAttribute attribute)) { return; } var drawer = MightyDrawersDatabase.GetDrawerForAttribute <IAutoValueDrawer>(attribute.GetType()); var state = drawer.InitProperty(this, attribute); if (!state.isOk) { MightyGUIUtilities.DrawHelpBox(state.message); } else { MightyEditorUtilities.RegisterChange(); } }
public static async void ApplyAutoValuesAsync() { AutoValuesWindowUtilities.Open(); await Task.Delay(50); var mightyEditors = MightyEditorUtilities.GetMightyEditors().ToArray(); AutoValuesWindowUtilities.DisplayCount(mightyEditors.Length); for (var i = 0; i < mightyEditors.Length; i++) { AutoValuesWindowUtilities.SetIndex(i); await Task.Yield(); mightyEditors[i].ApplyAutoValues(); } AutoValuesWindowUtilities.Close(); MightyDebugUtilities.MightyDebug("Auto Values Applied"); }
public void BeginOnGUI() { MightyEditorUtilities.ResetChange(); if (m_classMember != null) { if (m_classMember.TryGetAttributes(out BaseClassAttribute[] attributes)) { foreach (var attribute in attributes) { ((IClassDrawer)attribute.Drawer).BeginDrawClass(m_classMember, attribute); } } } if ((hideStatus & HideStatus.ScriptField) != HideStatus.ScriptField && m_isMonoScript) { GUI.enabled = false; EditorGUILayout.PropertyField(m_mightyContext.ScriptProperty); GUI.enabled = true; } }
public static void ApplyAutoValues() { for (var i = 0; i < SceneManager.sceneCount; i++) { foreach (var script in ReferencesUtilities.FindAllObjects <MonoBehaviour>(SceneManager.GetSceneAt(i))) { if (MightyEditorUtilities.CreateMightyEditor <MonoBehaviourEditor>(script, out var mightyEditor)) { mightyEditor.ApplyAutoValues(); } } } foreach (var script in typeof(ScriptableObject).FindAssetsOfType()) { if (MightyEditorUtilities.CreateMightyEditor <ScriptableObjectEditor>(script, out var mightyEditor)) { mightyEditor.ApplyAutoValues(); } } MightyDebugUtilities.MightyDebug("Auto Values Applied", MightyDebugUtilities.LogType.AutoValues); }
private void DrawSerializedField(MightySerializedField serializedField) { if ((hideStatus & HideStatus.SerializedFields) == HideStatus.SerializedFields) { return; } var hasDecorations = serializedField.TryGetAttributes(out BaseGlobalDecoratorAttribute[] decoratorAttributes); if (serializedField.TryGetAttribute(out BaseShowConditionAttribute showConditionAttribute)) { var canDraw = ((IShowConditionDrawer)showConditionAttribute.Drawer).CanDraw(serializedField, showConditionAttribute); if (!canDraw) { if (!hasDecorations) { return; } foreach (var attribute in decoratorAttributes) { if (!(attribute is IDrawAnywhereAttribute drawAnywhereAttribute)) { continue; } ((IDrawAnywhereDecorator)attribute.Drawer).BeginDrawAnywhere(serializedField, drawAnywhereAttribute); } for (var i = decoratorAttributes.Length - 1; i >= 0; i--) { if (!(decoratorAttributes[i] is IDrawAnywhereAttribute drawAnywhereAttribute)) { continue; } ((IDrawAnywhereDecorator)decoratorAttributes[i].Drawer).EndDrawAnywhere(serializedField, drawAnywhereAttribute); } return; } } var hasArrayAttribute = serializedField.TryGetAttribute(out BaseArrayAttribute arrayAttribute); var hasChangeChecks = serializedField.TryGetAttributes(out BaseChangeCheckAttribute[] changeCheckAttributes); var hasValidators = serializedField.TryGetAttributes(out BaseValidatorAttribute[] validatorAttributes); var hasDrawerAttribute = serializedField.TryGetAttribute(out BasePropertyDrawerAttribute drawerAttribute); var hasEnableCondition = serializedField.TryGetAttribute(out BaseEnableConditionAttribute enableConditionAttribute); var decoratorsLength = hasDecorations ? decoratorAttributes.Length : 0; var lastArrayDecoratorIndex = -1; var isPropertyCollection = serializedField.Property.IsCollection(); if (isPropertyCollection) { for (var i = decoratorsLength - 1; i >= 0; i--) { if (!(decoratorAttributes[i] is BaseArrayDecoratorAttribute)) { continue; } lastArrayDecoratorIndex = i; break; } } if (hasDecorations) { for (var i = 0; i < decoratorsLength; i++) { switch (decoratorAttributes[i]) { case BaseArrayDecoratorAttribute arrayDecoratorAttribute when(!hasArrayAttribute && (!isPropertyCollection || i != lastArrayDecoratorIndex)): ((IArrayDecoratorDrawer)arrayDecoratorAttribute.Drawer).BeginDrawMember(serializedField, arrayDecoratorAttribute, null); break; case BaseDecoratorAttribute decoratorAttribute: ((IDecoratorDrawer)decoratorAttribute.Drawer).BeginDraw(serializedField, decoratorAttribute); break; } } } if (hasEnableCondition) { ((IEnableConditionDrawer)enableConditionAttribute.Drawer).BeginEnable(serializedField, enableConditionAttribute); } EditorGUI.BeginChangeCheck(); if (hasChangeChecks) { foreach (var attribute in changeCheckAttributes) { ((IChangeCheckDrawer)attribute.Drawer).BeginChangeCheck(serializedField, attribute); } } if (!hasArrayAttribute) { var propertyDrawCallback = hasDrawerAttribute ? new PropertyDrawCallback((mightyMember, property, baseAttribute) => ((IPropertyDrawer)drawerAttribute.Drawer).DrawProperty(mightyMember, property, baseAttribute)) : (_, property, __) => MightyGUIUtilities.DrawPropertyField(property); if (lastArrayDecoratorIndex != -1) { var lastAttribute = (BaseArrayDecoratorAttribute)decoratorAttributes[lastArrayDecoratorIndex]; var lastDecorator = (IArrayDecoratorDrawer)lastAttribute.Drawer; lastDecorator.BeginDrawMember(serializedField, lastAttribute, propertyDrawCallback, drawerAttribute); lastDecorator.EndDrawMember(serializedField, lastAttribute, propertyDrawCallback, drawerAttribute); } else { propertyDrawCallback(serializedField, serializedField.Property, drawerAttribute); } } else { ((IArrayDrawer)arrayAttribute.Drawer).DrawArray(serializedField, arrayAttribute, drawerAttribute?.Drawer as IArrayElementDrawer, drawerAttribute); } if (hasValidators) { foreach (var attribute in validatorAttributes) { ((IValidatorDrawer)attribute.Drawer).ValidateProperty(serializedField, attribute); } } var changed = EditorGUI.EndChangeCheck() || MightyEditorUtilities.HasEditorChanged(); if (hasChangeChecks) { if (hasChangeChecks) { foreach (var attribute in changeCheckAttributes) { ((IChangeCheckDrawer)attribute.Drawer).EndChangeCheck(changed, serializedField, attribute); } } } if (hasEnableCondition) { ((IEnableConditionDrawer)enableConditionAttribute.Drawer).EndEnable(serializedField, enableConditionAttribute); } if (hasDecorations) { for (var i = decoratorsLength - 1; i >= 0; i--) { switch (decoratorAttributes[i]) { case BaseArrayDecoratorAttribute arrayDecoratorAttribute when(!hasArrayAttribute && (!isPropertyCollection || i != lastArrayDecoratorIndex)): ((IArrayDecoratorDrawer)arrayDecoratorAttribute.Drawer).EndDrawMember( serializedField, (BaseArrayDecoratorAttribute)decoratorAttributes[i], null); break; case BaseDecoratorAttribute decoratorAttribute: ((IDecoratorDrawer)decoratorAttribute.Drawer).EndDraw(serializedField, (BaseDecoratorAttribute)decoratorAttributes[i]); break; } } } }