This commit is contained in:
Mikhail 2026-04-14 10:21:32 +08:00
parent 2c5461fca1
commit 4ddcbb9d56
7 changed files with 7 additions and 196 deletions

View File

@ -788,14 +788,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
DrawTypeMetaBlockResultFlags result = DrawTypeMetaBlockResultFlags.None; DrawTypeMetaBlockResultFlags result = DrawTypeMetaBlockResultFlags.None;
using (CheckChanged()) using (CheckChanged())
{ {
//Canceling isExpanded
//bool oldIsExpanded = rootProperty.isExpanded;
//if (ClickTest(optionRect))
//{
// rootProperty.isExpanded = oldIsExpanded;
// result |= DrawTypeMetaBlockResultFlags.DropExpanded;
//}
//Close button //Close button
optionRect.xMin = optionRect.xMax - HeadIconsRect.width; optionRect.xMin = optionRect.xMax - HeadIconsRect.width;
optionsWidth += optionRect.width; optionsWidth += optionRect.width;

View File

@ -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<IReferenceButtonAttribute>
// {
// private Type[] _withOutTypes;
//
// protected override void OnInit(SerializedProperty property)
// {
// Type fieldType = fieldInfo.FieldType;
// _withOutTypes = fieldType.TryGetAttribute(out ReferenceButtonWithOutAttribute a) ? a.PredicateTypes : Array.Empty<Type>();
// //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

View File

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

View File

@ -1,7 +1,6 @@
#if DISABLE_DEBUG #if DISABLE_DEBUG
#undef DEBUG #undef DEBUG
#endif #endif
using DCFApixels.DragonECS.Unity.Editors;
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using UnityEngine; using UnityEngine;
@ -85,20 +84,4 @@ namespace DCFApixels.DragonECS
public static bool operator !=(Null? a, ComponentTemplateProperty b) { return !b.IsNull; } public static bool operator !=(Null? a, ComponentTemplateProperty b) { return !b.IsNull; }
public readonly struct Null { } 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<Type>()) { }
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));
}
}
} }

View File

@ -1,55 +1,19 @@
#if DISABLE_DEBUG #if DISABLE_DEBUG
#undef DEBUG #undef DEBUG
#endif #endif
using DCFApixels.DragonECS.Unity.Editors;
using DCFApixels.DragonECS.Unity.Internal; using DCFApixels.DragonECS.Unity.Internal;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using UnityEditor;
using UnityEngine; using UnityEngine;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
internal interface IReferenceDropDownAttribute public sealed class ReferenceDropDownAttribute : PropertyAttribute
{
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<Type>()) { }
// 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<Type>()) { }
// 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 readonly Type[] AllowTypes; public readonly Type[] AllowTypes;
public readonly bool IsHideButtonIfNotNull; 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<Type>()) { } public ReferenceDropDownAttribute(bool isHideButtonIfNotNull = false) : this(isHideButtonIfNotNull, Array.Empty<Type>()) { }
public ReferenceDropDownAttribute(params Type[] predicateTypes) : this(false, predicateTypes) { } public ReferenceDropDownAttribute(params Type[] predicateTypes) : this(false, predicateTypes) { }
public ReferenceDropDownAttribute(bool isHideButtonIfNotNull, params Type[] predicateTypes) public ReferenceDropDownAttribute(bool isHideButtonIfNotNull, params Type[] predicateTypes)
@ -77,12 +41,11 @@ namespace DCFApixels.DragonECS
#if UNITY_EDITOR #if UNITY_EDITOR
namespace DCFApixels.DragonECS.Unity.Editors namespace DCFApixels.DragonECS.Unity.Editors
{ {
using UnityEditor;
[CustomPropertyDrawer(typeof(ReferenceDropDownAttribute), true)] [CustomPropertyDrawer(typeof(ReferenceDropDownAttribute), true)]
[CustomPropertyDrawer(typeof(TypeMetaBlockAttribute), true)] [CustomPropertyDrawer(typeof(TypeMetaBlockAttribute), true)]
internal class EcsDragonFieldDrawer : ExtendedPropertyDrawer internal class EcsDragonFieldDrawer : ExtendedPropertyDrawer
@ -98,6 +61,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
private bool _isInit = false; private bool _isInit = false;
private bool _hasSerializableData; private bool _hasSerializableData;
#region CheckSkip
[ThreadStatic] [ThreadStatic]
private static int _skips = 0; private static int _skips = 0;
private bool CheckSkip() private bool CheckSkip()
@ -114,6 +78,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
_skips = count - 1; _skips = count - 1;
return false; return false;
} }
#endregion
#region Properties #region Properties
private float Padding => Spacing; private float Padding => Spacing;
@ -122,12 +87,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
private bool IsDrawMetaBlock => TypeMetaBlockAttribute != null; private bool IsDrawMetaBlock => TypeMetaBlockAttribute != null;
#endregion #endregion
public EcsDragonFieldDrawer() { }
public EcsDragonFieldDrawer(PredicateTypesKey key)
{
_predicateOverride = key;
}
#region Init #region Init
protected override void OnInit(SerializedProperty property) 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) protected override void DrawCustom(Rect rect, SerializedProperty property, GUIContent label)
{
Draw(position, property, property, label);
}
public void Draw(Rect rect, SerializedProperty rootProperty, SerializedProperty property, GUIContent label)
{ {
if (CheckSkip()) { EditorGUI.PropertyField(rect, property, label, true); return; } if (CheckSkip()) { EditorGUI.PropertyField(rect, property, label, true); return; }
bool isSerializeReference = property.propertyType == SerializedPropertyType.ManagedReference; bool isSerializeReference = property.propertyType == SerializedPropertyType.ManagedReference;
var e = Event.current; var e = Event.current;
var rootProperty = property;
ITypeMeta meta = null; ITypeMeta meta = null;
SerializedProperty componentProp = property; SerializedProperty componentProp = property;