diff --git a/src/DebugUtils/Editor/SettingsEditor.cs b/src/DebugUtils/Editor/SettingsEditor.cs index 8834948..bfe05e8 100644 --- a/src/DebugUtils/Editor/SettingsEditor.cs +++ b/src/DebugUtils/Editor/SettingsEditor.cs @@ -54,23 +54,27 @@ namespace DCFApixels.DragonECS.Unity.Editors //using (prefs.DisableAutoSave()) { GUILayout.BeginHorizontal(); - prefs.IsShowHidden = EditorGUILayout.Toggle(prefs.IsShowHidden, GUILayout.Width(checkBoxWidth)); - GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowHidden)), GUILayout.ExpandWidth(false)); + prefs.IsShowHidden = EditorGUILayout.ToggleLeft( + UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowHidden)), + prefs.IsShowHidden); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); - prefs.IsShowInterfaces = EditorGUILayout.Toggle(prefs.IsShowInterfaces, GUILayout.Width(checkBoxWidth)); - GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowInterfaces)), GUILayout.ExpandWidth(false)); + prefs.IsShowInterfaces = EditorGUILayout.ToggleLeft( + UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowInterfaces)), + prefs.IsShowInterfaces); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); - prefs.IsShowRuntimeComponents = EditorGUILayout.Toggle(prefs.IsShowRuntimeComponents, GUILayout.Width(checkBoxWidth)); - GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowRuntimeComponents)), GUILayout.ExpandWidth(false)); + prefs.IsShowRuntimeComponents = EditorGUILayout.ToggleLeft( + UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowRuntimeComponents)), + prefs.IsShowRuntimeComponents); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); - prefs.IsUseCustomNames = EditorGUILayout.Toggle(prefs.IsUseCustomNames, GUILayout.Width(checkBoxWidth)); - GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsUseCustomNames)), GUILayout.ExpandWidth(false)); + prefs.IsUseCustomNames = EditorGUILayout.ToggleLeft( + UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsUseCustomNames)), + prefs.IsUseCustomNames); GUILayout.EndHorizontal(); prefs.ComponentColorMode = (ComponentColorMode)EditorGUILayout.EnumPopup(UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.ComponentColorMode)), prefs.ComponentColorMode); @@ -80,7 +84,9 @@ namespace DCFApixels.DragonECS.Unity.Editors GUILayout.Space(20f); using (EcsGUI.SetColor(Color.white * 0.5f)) + { GUILayout.BeginVertical(EditorStyles.helpBox); + } //using (new EcsGUI.ColorScope(Color.white * 1.2f)) GUILayout.Label("", EditorStyles.toolbar, GUILayout.ExpandWidth(true), GUILayout.Height(22f)); rect = GUILayoutUtility.GetLastRect(); @@ -95,15 +101,10 @@ namespace DCFApixels.DragonECS.Unity.Editors { GUILayout.BeginHorizontal(); var symbol = _defineSymbols[i]; - symbol.isOn = EditorGUILayout.Toggle(symbol.isOn, GUILayout.Width(checkBoxWidth)); - if (symbol.name == "DEBUG") - { - GUILayout.Label(symbol.name + " (Build Olny)", GUILayout.ExpandWidth(false)); - } - else - { - GUILayout.Label(symbol.name, GUILayout.ExpandWidth(false)); - } + + string text = symbol.name == "DEBUG" ? symbol.name + " (Build Olny)" : symbol.name; + symbol.isOn = EditorGUILayout.ToggleLeft(text, symbol.isOn); + GUILayout.EndHorizontal(); } if (EditorGUI.EndChangeCheck()) { } diff --git a/src/Internal/CustomToggleAttribute.cs b/src/Internal/CustomToggleAttribute.cs new file mode 100644 index 0000000..1bda942 --- /dev/null +++ b/src/Internal/CustomToggleAttribute.cs @@ -0,0 +1,55 @@ +using UnityEngine; + +namespace DCFApixels.DragonECS.Unity.Internal +{ + internal class CustomToggleAttribute : PropertyAttribute + { + public string Name; + public bool IsInverted; + public bool IsLeft; + } +} + +#if UNITY_EDITOR +namespace DCFApixels.DragonECS.Unity.Editors +{ + using DCFApixels.DragonECS.Unity.Internal; + using UnityEditor; + [CustomPropertyDrawer(typeof(CustomToggleAttribute))] + internal class LeftToggleAttributeDrawer : ExtendedPropertyDrawer + { + protected override void DrawCustom(Rect position, SerializedProperty property, GUIContent label) + { + if (property.propertyType != SerializedPropertyType.Boolean) + { + EditorGUI.PropertyField(position, property, label); + } + + if (string.IsNullOrEmpty(Attribute.Name) == false) + { + label.text = Attribute.Name; + } + + bool value = property.boolValue; + if (Attribute.IsInverted) + { + value = !value; + } + + if (Attribute.IsLeft) + { + value = EditorGUI.ToggleLeft(position, label, value); + } + + value = EditorGUI.ToggleLeft(position, label, value); + + if (Attribute.IsInverted) + { + value = !value; + } + + property.boolValue = value; + } + } +} +#endif \ No newline at end of file diff --git a/src/Internal/CustomToggleAttribute.cs.meta b/src/Internal/CustomToggleAttribute.cs.meta new file mode 100644 index 0000000..2aaa37d --- /dev/null +++ b/src/Internal/CustomToggleAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fc3766060e046a14f975dcb3b3ffe39c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index 631dcb7..1b606cc 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -268,6 +268,8 @@ namespace DCFApixels.DragonECS.Unity.Editors public static float EntityBarHeight => EditorGUIUtility.singleLineHeight + 3f; + private static float indent => (float)EditorGUI.indentLevel * 15f; + #region Properties private static ComponentColorMode AutoColorMode { @@ -447,6 +449,18 @@ namespace DCFApixels.DragonECS.Unity.Editors } #endregion + //#region One line elems + //public static bool LeftToggle(Rect position, GUIContent label, bool value) + //{ + // position = position.AddPadding(indent, 0, 0, 0); + // Rect togglePos; + // (togglePos, position) = position.HorizontalSliceLeft(18f); + // + // EditorGUI.togg(position, label); + // GUI.Label(position, label); + //} + //#endregion + #region entity bar public static void EntityBarForAlive(Rect position, EntityStatus status, int id, short gen, short world) { @@ -978,6 +992,7 @@ namespace DCFApixels.DragonECS.Unity.Editors public static void DrawSelectReferenceButton(Rect position, SerializedProperty property, Type[] sortedPredicateTypes, Type[] sortedWithOutTypes, bool isHideButtonIfNotNull) { object obj = property.hasMultipleDifferentValues ? null : property.managedReferenceValue; + string text = obj == null ? "Select..." : obj.GetMeta().Name; if (!isHideButtonIfNotNull || obj == null) { diff --git a/src/Internal/ReferenceButtonAttributeDrawer.cs b/src/Internal/ReferenceButtonAttributeDrawer.cs index 602a33a..6bdb4a3 100644 --- a/src/Internal/ReferenceButtonAttributeDrawer.cs +++ b/src/Internal/ReferenceButtonAttributeDrawer.cs @@ -56,7 +56,7 @@ namespace DCFApixels.DragonECS.Unity.Editors } Rect selButtnoRect = position; selButtnoRect.height = OneLineHeight; - DrawSelectionPopupButton(selButtnoRect, property, label); + DrawSelectionPopupButton(selButtnoRect, property); if (property.managedReferenceValue != null) { @@ -70,7 +70,7 @@ namespace DCFApixels.DragonECS.Unity.Editors } } - private void DrawSelectionPopupButton(Rect position, SerializedProperty property, GUIContent label) + private void DrawSelectionPopupButton(Rect position, SerializedProperty property) { Rect buttonRect = IsArrayElement ? position : position.AddPadding(EditorGUIUtility.labelWidth, 0f, 0f, 0f); ; EcsGUI.DrawSelectReferenceButton(buttonRect, property, Attribute.PredicateTypes.Length == 0 ? new Type[1] { fieldInfo.FieldType } : Attribute.PredicateTypes, _withOutTypes, Attribute.IsHideButtonIfNotNull); diff --git a/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateEditorBase.cs b/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateEditor.cs similarity index 81% rename from src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateEditorBase.cs rename to src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateEditor.cs index fa48413..60bfabf 100644 --- a/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateEditorBase.cs +++ b/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateEditor.cs @@ -8,63 +8,6 @@ using UnityEngine; namespace DCFApixels.DragonECS.Unity.Editors { - [CustomPropertyDrawer(typeof(PipelineTemplateUtility.Record))] - internal class PipelineTemplateUtilityRecordDrawer : ExtendedPropertyDrawer - { - protected override void DrawCustom(Rect position, SerializedProperty property, GUIContent label) - { - if (IsArrayElement == false) - { - Rect foldoutRect; - (foldoutRect, position) = position.VerticalSliceTop(OneLineHeight + Spacing); - property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label); - if (property.isExpanded == false) - { - return; - } - } - - using (EcsGUI.SetIndentLevel(IsArrayElement ? EditorGUI.indentLevel : EditorGUI.indentLevel + 1)) - { - Rect subPosition = position; - int depth = -1; - float height = 0f; - - property.Next(true); - do - { - subPosition.y += height; - height = EditorGUI.GetPropertyHeight(property); - subPosition.height = height; - - EditorGUI.PropertyField(subPosition, property, true); - - } while (property.NextDepth(false, ref depth)); - } - } - - public override float GetPropertyHeight(SerializedProperty property, GUIContent label) - { - float result = 0f; - if (IsArrayElement == false) - { - result += OneLineHeight; - if (property.isExpanded == false) - { - return result; - } - } - - - property.Next(true); - int depth = -1; - do - { - result += EditorGUI.GetPropertyHeight(property, true); - } while (property.NextDepth(false, ref depth)); - return result; - } - } [CustomEditor(typeof(ScriptablePipelineTemplate))] internal class PipelineTemplateEditorBase : ExtendedEditor { diff --git a/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateEditorBase.cs.meta b/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateEditor.cs.meta similarity index 100% rename from src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateEditorBase.cs.meta rename to src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateEditor.cs.meta diff --git a/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateUtilityRecordDrawer.cs b/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateUtilityRecordDrawer.cs new file mode 100644 index 0000000..7ef4a0f --- /dev/null +++ b/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateUtilityRecordDrawer.cs @@ -0,0 +1,66 @@ +#if UNITY_EDITOR +using DCFApixels.DragonECS.Unity.Internal; +using UnityEditor; +using UnityEngine; + +namespace DCFApixels.DragonECS.Unity.Editors +{ + [CustomPropertyDrawer(typeof(PipelineTemplateUtility.Record))] + internal class PipelineTemplateUtilityRecordDrawer : ExtendedPropertyDrawer + { + protected override void DrawCustom(Rect position, SerializedProperty property, GUIContent label) + { + if (IsArrayElement == false) + { + Rect foldoutRect; + (foldoutRect, position) = position.VerticalSliceTop(OneLineHeight + Spacing); + property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label); + if (property.isExpanded == false) + { + return; + } + } + + using (EcsGUI.SetIndentLevel(IsArrayElement ? EditorGUI.indentLevel : EditorGUI.indentLevel + 1)) + { + Rect subPosition = position; + int depth = -1; + float height = 0f; + + property.Next(true); + + do + { + subPosition.y += height; + height = EditorGUI.GetPropertyHeight(property); + subPosition.height = height; + + EditorGUI.PropertyField(subPosition, property, true); + + } while (property.NextDepth(false, ref depth)); + } + } + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + float result = 0f; + if (IsArrayElement == false) + { + result += OneLineHeight; + if (property.isExpanded == false) + { + return result; + } + } + + property.Next(true); + int depth = -1; + do + { + result += EditorGUI.GetPropertyHeight(property, true); + } while (property.NextDepth(false, ref depth)); + return result; + } + } +} +#endif \ No newline at end of file diff --git a/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateUtilityRecordDrawer.cs.meta b/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateUtilityRecordDrawer.cs.meta new file mode 100644 index 0000000..e8ea3fb --- /dev/null +++ b/src/Templates/EcsPipelineTemplate/Editor/PipelineTemplateUtilityRecordDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c96272e4ae45f03408e899323c54d08f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Templates/EcsPipelineTemplate/PipelineTemplateUtility.cs b/src/Templates/EcsPipelineTemplate/PipelineTemplateUtility.cs index 7139061..c3485d0 100644 --- a/src/Templates/EcsPipelineTemplate/PipelineTemplateUtility.cs +++ b/src/Templates/EcsPipelineTemplate/PipelineTemplateUtility.cs @@ -105,10 +105,13 @@ namespace DCFApixels.DragonECS.Unity [ArrayElement] public object target;// нельзя менять поярдок полей, иначе это поломает отрисовку в инспекторе изза применения property.Next(bool); public AddParams parameters; - public Record(object target, AddParams parameters) + [CustomToggle(Name = "Enable", IsLeft = true, IsInverted = true)] + public bool disabled; + public Record(object target, AddParams parameters, bool disabled) { this.target = target; this.parameters = parameters; + this.disabled = disabled; } } } diff --git a/src/Templates/EcsPipelineTemplate/Templates/MonoPipelineTemplate.cs b/src/Templates/EcsPipelineTemplate/Templates/MonoPipelineTemplate.cs index 91a00ee..f612aac 100644 --- a/src/Templates/EcsPipelineTemplate/Templates/MonoPipelineTemplate.cs +++ b/src/Templates/EcsPipelineTemplate/Templates/MonoPipelineTemplate.cs @@ -44,10 +44,10 @@ namespace DCFApixels.DragonECS public sealed override void Import(EcsPipeline.Builder b) { b.Layers.MergeWith(_layers); - foreach (var s in _records) + foreach (var r in _records) { - if (s.target == null) { continue; } - b.Add(s.target, s.parameters); + if (r.target == null || r.disabled) { continue; } + b.Add(r.target, r.parameters); } } @@ -59,7 +59,7 @@ namespace DCFApixels.DragonECS for (int i = 0; i < _records.Length; i++) { ref var s = ref template.records[i]; - _records[i] = new Record(s.target, s.parameters); + _records[i] = new Record(s.target, s.parameters, true); } } diff --git a/src/Templates/EcsPipelineTemplate/Templates/ScriptablePipelineTemplate.cs b/src/Templates/EcsPipelineTemplate/Templates/ScriptablePipelineTemplate.cs index 0c4d1fa..4915aea 100644 --- a/src/Templates/EcsPipelineTemplate/Templates/ScriptablePipelineTemplate.cs +++ b/src/Templates/EcsPipelineTemplate/Templates/ScriptablePipelineTemplate.cs @@ -43,10 +43,10 @@ namespace DCFApixels.DragonECS public sealed override void Import(EcsPipeline.Builder b) { b.Layers.MergeWith(_layers); - foreach (var s in _records) + foreach (var r in _records) { - if (s.target == null) { continue; } - b.Add(s.target, s.parameters); + if (r.target == null || r.disabled) { continue; } + b.Add(r.target, r.parameters); } } @@ -58,7 +58,7 @@ namespace DCFApixels.DragonECS for (int i = 0; i < _records.Length; i++) { ref var s = ref template.records[i]; - _records[i] = new Record(s.target, s.parameters); + _records[i] = new Record(s.target, s.parameters, true); } }