update editor

This commit is contained in:
Mikhail 2024-11-01 17:17:52 +08:00
parent 59e41eb5cd
commit bdc707dc74
12 changed files with 190 additions and 85 deletions

View File

@ -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()) { }

View File

@ -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<CustomToggleAttribute>
{
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

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc3766060e046a14f975dcb3b3ffe39c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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)
{

View File

@ -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);

View File

@ -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<IPipelineTemplate>
{

View File

@ -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

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c96272e4ae45f03408e899323c54d08f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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;
}
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}