From 4ddcbb9d56ccc854bab869cc06011a6c6598ccdc Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 14 Apr 2026 10:21:32 +0800 Subject: [PATCH] cleanup --- src/Internal/Editor/EcsGUI.cs | 8 -- .../ReferenceButtonAttributeDrawer.cs | 109 ------------------ .../ReferenceButtonAttributeDrawer.cs.meta | 11 -- .../ComponentTemplateProperty.cs | 17 --- .../ComponentTemplateProperty.cs.meta | 0 ...ibute.cs => ReferenceDropDownAttribute.cs} | 58 ++-------- ...eta => ReferenceDropDownAttribute.cs.meta} | 0 7 files changed, 7 insertions(+), 196 deletions(-) delete mode 100644 src/Internal/ReferenceButtonAttributeDrawer.cs delete mode 100644 src/Internal/ReferenceButtonAttributeDrawer.cs.meta rename src/Templates/EntityTemplate/{ => Templates}/ComponentTemplateProperty.cs (77%) rename src/Templates/EntityTemplate/{ => Templates}/ComponentTemplateProperty.cs.meta (100%) rename src/Utils/{ReferenceButtonAttribute.cs => ReferenceDropDownAttribute.cs} (88%) rename src/Utils/{ReferenceButtonAttribute.cs.meta => ReferenceDropDownAttribute.cs.meta} (100%) diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index 48fb4e6..1d17bdd 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -788,14 +788,6 @@ namespace DCFApixels.DragonECS.Unity.Editors DrawTypeMetaBlockResultFlags result = DrawTypeMetaBlockResultFlags.None; using (CheckChanged()) { - //Canceling isExpanded - //bool oldIsExpanded = rootProperty.isExpanded; - //if (ClickTest(optionRect)) - //{ - // rootProperty.isExpanded = oldIsExpanded; - // result |= DrawTypeMetaBlockResultFlags.DropExpanded; - //} - //Close button optionRect.xMin = optionRect.xMax - HeadIconsRect.width; optionsWidth += optionRect.width; diff --git a/src/Internal/ReferenceButtonAttributeDrawer.cs b/src/Internal/ReferenceButtonAttributeDrawer.cs deleted file mode 100644 index a28b21c..0000000 --- a/src/Internal/ReferenceButtonAttributeDrawer.cs +++ /dev/null @@ -1,109 +0,0 @@ -//using System; -// -//#if UNITY_EDITOR -//namespace DCFApixels.DragonECS.Unity.Internal -//{ -// using DCFApixels.DragonECS.Unity.Editors; -// using UnityEditor; -// internal partial class UnityReflectionCache -// { -// public bool IsReferenceButtonCacheInit_Editor; -// public bool InitReferenceButtonCache_Editor(SerializedProperty sp) -// { -// if (IsReferenceButtonCacheInit_Editor) { return false; } -// -// HasSerializableData_Editor = sp.HasSerializableData(); -// -// IsReferenceButtonCacheInit_Editor = true; -// return true; -// } -// public bool HasSerializableData_Editor; -// } -//} -// -//namespace DCFApixels.DragonECS.Unity.Editors -//{ -// using DCFApixels.DragonECS.Unity.Internal; -// using System; -// using UnityEditor; -// using UnityEngine; -// -// [CustomPropertyDrawer(typeof(ReferenceButtonAttribute), true)] -// internal sealed class ReferenceButtonAttributeDrawer : ExtendedPropertyDrawer -// { -// private Type[] _withOutTypes; -// -// protected override void OnInit(SerializedProperty property) -// { -// Type fieldType = fieldInfo.FieldType; -// _withOutTypes = fieldType.TryGetAttribute(out ReferenceButtonWithOutAttribute a) ? a.PredicateTypes : Array.Empty(); -// //if (fieldType.IsGenericType) -// //{ -// // if (fieldType.IsGenericTypeDefinition == false) -// // { -// // fieldType = fieldType.GetGenericTypeDefinition(); -// // } -// //} -// } -// -// private UnityReflectionCache _reflectionCache; -// private UnityReflectionCache Cahce(SerializedProperty sp) -// { -// if (UnityReflectionCache.InitLocal(sp.managedReferenceValue.GetType(), ref _reflectionCache)) -// { -// _reflectionCache.InitReferenceButtonCache_Editor(sp); -// } -// return _reflectionCache; -// } -// -// public override float GetPropertyHeight(SerializedProperty property, GUIContent label) -// { -// Init(property); -// if (property.propertyType == SerializedPropertyType.ManagedReference && -// property.managedReferenceValue != null && -// Cahce(property).HasSerializableData_Editor) -// { -// return EditorGUI.GetPropertyHeight(property, label, true); -// } -// else -// { -// return OneLineHeight; -// } -// } -// -// protected override void DrawCustom(Rect position, SerializedProperty property, GUIContent label) -// { -// if(property.propertyType != SerializedPropertyType.ManagedReference) -// { -// GUI.Label(position, label); -// return; -// } -// if (IsArrayElement) -// { -// label = UnityEditorUtility.GetLabelTemp(); -// } -// Rect selButtnoRect = position; -// selButtnoRect.height = OneLineHeight; -// DrawSelectionPopupButton(selButtnoRect, property); -// -// if (property.managedReferenceValue != null && -// Cahce(property).HasSerializableData_Editor) -// { -// EditorGUI.PropertyField(position, property, label, true); -// } -// else -// { -// EditorGUI.BeginProperty(position, label, property); -// EditorGUI.LabelField(position, label); -// EditorGUI.EndProperty(); -// } -// } -// -// 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); -// } -// } -//} -//#endif \ No newline at end of file diff --git a/src/Internal/ReferenceButtonAttributeDrawer.cs.meta b/src/Internal/ReferenceButtonAttributeDrawer.cs.meta deleted file mode 100644 index 0f15cb9..0000000 --- a/src/Internal/ReferenceButtonAttributeDrawer.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 69a86e40de1b68a448f49be1e83a1ed5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/Templates/EntityTemplate/ComponentTemplateProperty.cs b/src/Templates/EntityTemplate/Templates/ComponentTemplateProperty.cs similarity index 77% rename from src/Templates/EntityTemplate/ComponentTemplateProperty.cs rename to src/Templates/EntityTemplate/Templates/ComponentTemplateProperty.cs index 68f83ee..ce7406e 100644 --- a/src/Templates/EntityTemplate/ComponentTemplateProperty.cs +++ b/src/Templates/EntityTemplate/Templates/ComponentTemplateProperty.cs @@ -1,7 +1,6 @@ #if DISABLE_DEBUG #undef DEBUG #endif -using DCFApixels.DragonECS.Unity.Editors; using System; using System.Runtime.CompilerServices; using UnityEngine; @@ -85,20 +84,4 @@ namespace DCFApixels.DragonECS public static bool operator !=(Null? a, ComponentTemplateProperty b) { return !b.IsNull; } public readonly struct Null { } } - - public sealed class ComponentTemplateFieldAttribute : PropertyAttribute, IReferenceDropDownAttribute - { - public Type[] PredicateTypes; - public readonly bool IsHideButtonIfNotNull = true; - Type[] IReferenceDropDownAttribute.PredicateTypes { get { return PredicateTypes; } } - bool IReferenceDropDownAttribute.IsHideButtonIfNotNull { get { return IsHideButtonIfNotNull; } } - public ComponentTemplateFieldAttribute(bool isHideButtonIfNotNull = false) : this(isHideButtonIfNotNull, Array.Empty()) { } - public ComponentTemplateFieldAttribute(params Type[] predicateTypes) : this(false, predicateTypes) { } - public ComponentTemplateFieldAttribute(bool isHideButtonIfNotNull, params Type[] predicateTypes) - { - IsHideButtonIfNotNull = isHideButtonIfNotNull; - PredicateTypes = predicateTypes; - Array.Sort(predicateTypes, (a, b) => string.Compare(a.AssemblyQualifiedName, b.AssemblyQualifiedName, StringComparison.Ordinal)); - } - } } \ No newline at end of file diff --git a/src/Templates/EntityTemplate/ComponentTemplateProperty.cs.meta b/src/Templates/EntityTemplate/Templates/ComponentTemplateProperty.cs.meta similarity index 100% rename from src/Templates/EntityTemplate/ComponentTemplateProperty.cs.meta rename to src/Templates/EntityTemplate/Templates/ComponentTemplateProperty.cs.meta diff --git a/src/Utils/ReferenceButtonAttribute.cs b/src/Utils/ReferenceDropDownAttribute.cs similarity index 88% rename from src/Utils/ReferenceButtonAttribute.cs rename to src/Utils/ReferenceDropDownAttribute.cs index 5a67249..ca098df 100644 --- a/src/Utils/ReferenceButtonAttribute.cs +++ b/src/Utils/ReferenceDropDownAttribute.cs @@ -1,55 +1,19 @@ #if DISABLE_DEBUG #undef DEBUG #endif -using DCFApixels.DragonECS.Unity.Editors; using DCFApixels.DragonECS.Unity.Internal; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using UnityEditor; using UnityEngine; namespace DCFApixels.DragonECS { - internal interface IReferenceDropDownAttribute - { - Type[] PredicateTypes { get; } - bool IsHideButtonIfNotNull { get; } - } - //public sealed class ReferenceButtonAttribute : PropertyAttribute, IReferenceDropDownAttribute - //{ - // public readonly Type[] PredicateTypes; - // public readonly bool IsHideButtonIfNotNull; - // Type[] IReferenceDropDownAttribute.PredicateTypes { get { return PredicateTypes; } } - // bool IReferenceDropDownAttribute.IsHideButtonIfNotNull { get { return IsHideButtonIfNotNull; } } - // public ReferenceButtonAttribute(bool isHideButtonIfNotNull = false) : this(isHideButtonIfNotNull, Array.Empty()) { } - // public ReferenceButtonAttribute(params Type[] predicateTypes) : this(false, predicateTypes) { } - // public ReferenceButtonAttribute(bool isHideButtonIfNotNull, params Type[] predicateTypes) - // { - // IsHideButtonIfNotNull = isHideButtonIfNotNull; - // PredicateTypes = predicateTypes; - // Array.Sort(predicateTypes, (a, b) => string.Compare(a.AssemblyQualifiedName, b.AssemblyQualifiedName, StringComparison.Ordinal)); - // } - //} - //public sealed class ReferenceButtonWithOutAttribute : Attribute - //{ - // public readonly Type[] PredicateTypes; - // [Obsolete("With empty parameters, this attribute makes no sense.", true)] - // public ReferenceButtonWithOutAttribute() : this(Array.Empty()) { } - // public ReferenceButtonWithOutAttribute(params Type[] predicateTypes) - // { - // PredicateTypes = predicateTypes; - // Array.Sort(predicateTypes, (a, b) => string.Compare(a.AssemblyQualifiedName, b.AssemblyQualifiedName, StringComparison.Ordinal)); - // } - //} - - public sealed class ReferenceDropDownAttribute : PropertyAttribute, IReferenceDropDownAttribute + public sealed class ReferenceDropDownAttribute : PropertyAttribute { public readonly Type[] AllowTypes; public readonly bool IsHideButtonIfNotNull; - Type[] IReferenceDropDownAttribute.PredicateTypes { get { return AllowTypes; } } - bool IReferenceDropDownAttribute.IsHideButtonIfNotNull { get { return IsHideButtonIfNotNull; } } public ReferenceDropDownAttribute(bool isHideButtonIfNotNull = false) : this(isHideButtonIfNotNull, Array.Empty()) { } public ReferenceDropDownAttribute(params Type[] predicateTypes) : this(false, predicateTypes) { } public ReferenceDropDownAttribute(bool isHideButtonIfNotNull, params Type[] predicateTypes) @@ -77,12 +41,11 @@ namespace DCFApixels.DragonECS - - - #if UNITY_EDITOR namespace DCFApixels.DragonECS.Unity.Editors { + using UnityEditor; + [CustomPropertyDrawer(typeof(ReferenceDropDownAttribute), true)] [CustomPropertyDrawer(typeof(TypeMetaBlockAttribute), true)] internal class EcsDragonFieldDrawer : ExtendedPropertyDrawer @@ -98,6 +61,7 @@ namespace DCFApixels.DragonECS.Unity.Editors private bool _isInit = false; private bool _hasSerializableData; + #region CheckSkip [ThreadStatic] private static int _skips = 0; private bool CheckSkip() @@ -114,6 +78,7 @@ namespace DCFApixels.DragonECS.Unity.Editors _skips = count - 1; return false; } + #endregion #region Properties private float Padding => Spacing; @@ -122,12 +87,6 @@ namespace DCFApixels.DragonECS.Unity.Editors private bool IsDrawMetaBlock => TypeMetaBlockAttribute != null; #endregion - public EcsDragonFieldDrawer() { } - public EcsDragonFieldDrawer(PredicateTypesKey key) - { - _predicateOverride = key; - } - #region Init protected override void OnInit(SerializedProperty property) { @@ -259,15 +218,12 @@ namespace DCFApixels.DragonECS.Unity.Editors } } - protected override void DrawCustom(Rect position, SerializedProperty property, GUIContent label) - { - Draw(position, property, property, label); - } - public void Draw(Rect rect, SerializedProperty rootProperty, SerializedProperty property, GUIContent label) + protected override void DrawCustom(Rect rect, SerializedProperty property, GUIContent label) { if (CheckSkip()) { EditorGUI.PropertyField(rect, property, label, true); return; } bool isSerializeReference = property.propertyType == SerializedPropertyType.ManagedReference; var e = Event.current; + var rootProperty = property; ITypeMeta meta = null; SerializedProperty componentProp = property; diff --git a/src/Utils/ReferenceButtonAttribute.cs.meta b/src/Utils/ReferenceDropDownAttribute.cs.meta similarity index 100% rename from src/Utils/ReferenceButtonAttribute.cs.meta rename to src/Utils/ReferenceDropDownAttribute.cs.meta