simple refactoring/fix ReorderableList height

This commit is contained in:
DCFApixels 2025-04-04 15:56:25 +08:00
parent ab80e92b36
commit 26afa999a9
4 changed files with 27 additions and 13 deletions

View File

@ -86,9 +86,9 @@ namespace DCFApixels.DragonECS.Unity.Editors
} }
} }
} }
internal class ComponentDropDown : MetaObjectsDropDown<IComponentTemplate> internal class ComponentTemplatesDropDown : MetaObjectsDropDown<IComponentTemplate>
{ {
public ComponentDropDown() public ComponentTemplatesDropDown()
{ {
IEnumerable<(IComponentTemplate template, ITypeMeta meta)> itemMetaPairs = ComponentTemplateTypeCache.Dummies.ToArray().Select(dummy => IEnumerable<(IComponentTemplate template, ITypeMeta meta)> itemMetaPairs = ComponentTemplateTypeCache.Dummies.ToArray().Select(dummy =>
{ {
@ -168,9 +168,9 @@ namespace DCFApixels.DragonECS.Unity.Editors
} }
} }
} }
internal class RuntimeComponentDropDown : MetaObjectsDropDown<IEcsPool> internal class RuntimeComponentsDropDown : MetaObjectsDropDown<IEcsPool>
{ {
public RuntimeComponentDropDown(IEnumerable<IEcsPool> pools) public RuntimeComponentsDropDown(IEnumerable<IEcsPool> pools)
{ {
IEnumerable<(IEcsPool pool, ITypeMeta meta)> itemMetaPairs = pools.Select(pool => IEnumerable<(IEcsPool pool, ITypeMeta meta)> itemMetaPairs = pools.Select(pool =>
{ {
@ -268,6 +268,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
protected override void ItemSelected(AdvancedDropdownItem item) protected override void ItemSelected(AdvancedDropdownItem item)
{ {
//EcsGUI.Changed = true;
base.ItemSelected(item); base.ItemSelected(item);
var tType = (Item)item; var tType = (Item)item;
ItemSelected(tType); ItemSelected(tType);

View File

@ -507,9 +507,9 @@ namespace DCFApixels.DragonECS.Unity.Editors
{ {
public struct WorldData public struct WorldData
{ {
public RuntimeComponentDropDown addComponentGenericMenu; public RuntimeComponentsDropDown addComponentGenericMenu;
public int poolsCount; public int poolsCount;
public WorldData(RuntimeComponentDropDown addComponentGenericMenu, int poolsCount) public WorldData(RuntimeComponentsDropDown addComponentGenericMenu, int poolsCount)
{ {
this.addComponentGenericMenu = addComponentGenericMenu; this.addComponentGenericMenu = addComponentGenericMenu;
this.poolsCount = poolsCount; this.poolsCount = poolsCount;
@ -518,7 +518,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
//world id //world id
private static Dictionary<EcsWorld, WorldData> _worldDatas = new Dictionary<EcsWorld, WorldData>(); private static Dictionary<EcsWorld, WorldData> _worldDatas = new Dictionary<EcsWorld, WorldData>();
public static RuntimeComponentDropDown GetAddComponentGenericMenu(EcsWorld world) public static RuntimeComponentsDropDown GetAddComponentGenericMenu(EcsWorld world)
{ {
if (_worldDatas.TryGetValue(world, out WorldData data)) if (_worldDatas.TryGetValue(world, out WorldData data))
{ {
@ -541,7 +541,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
private static WorldData CreateWorldData(EcsWorld world) private static WorldData CreateWorldData(EcsWorld world)
{ {
IEnumerable<IEcsPool> pools = world.AllPools.ToArray().Where(o => o.IsNullOrDummy() == false); IEnumerable<IEcsPool> pools = world.AllPools.ToArray().Where(o => o.IsNullOrDummy() == false);
RuntimeComponentDropDown genericMenu = new RuntimeComponentDropDown(pools); RuntimeComponentsDropDown genericMenu = new RuntimeComponentsDropDown(pools);
return new WorldData(genericMenu, world.PoolsCount); return new WorldData(genericMenu, world.PoolsCount);
} }

View File

@ -30,7 +30,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
internal class ComponentTemplateReferenceDrawer : ExtendedPropertyDrawer<ComponentTemplateReferenceAttribute> internal class ComponentTemplateReferenceDrawer : ExtendedPropertyDrawer<ComponentTemplateReferenceAttribute>
{ {
private const float DamagedComponentHeight = 18f * 2f; private const float DamagedComponentHeight = 18f * 2f;
private static ComponentDropDown _componentDropDown; private static ComponentTemplatesDropDown _componentDropDown;
#region Properties #region Properties
private float SingleLineWithPadding => OneLineHeight + Padding * 4f; private float SingleLineWithPadding => OneLineHeight + Padding * 4f;
@ -41,14 +41,15 @@ namespace DCFApixels.DragonECS.Unity.Editors
#region Init #region Init
protected override void OnStaticInit() protected override void OnStaticInit()
{ {
_componentDropDown = new ComponentDropDown(); _componentDropDown = new ComponentTemplatesDropDown();
_componentDropDown.OnSelected += SelectComponent; _componentDropDown.OnSelected += SelectComponent;
} }
[ThreadStatic] [ThreadStatic]
private static SerializedProperty currentProperty; private static SerializedProperty currentProperty;
private static void SelectComponent(ComponentDropDown.Item item) private static void SelectComponent(ComponentTemplatesDropDown.Item item)
{ {
EcsGUI.Changed = true;
currentProperty.managedReferenceValue = item.Obj.Clone(); currentProperty.managedReferenceValue = item.Obj.Clone();
currentProperty.isExpanded = false; currentProperty.isExpanded = false;
currentProperty.serializedObject.ApplyModifiedProperties(); currentProperty.serializedObject.ApplyModifiedProperties();

View File

@ -9,10 +9,11 @@ namespace DCFApixels.DragonECS.Unity.Editors
{ {
internal abstract class EntityTemplateEditorBase : ExtendedEditor<IEntityTemplateInternal> internal abstract class EntityTemplateEditorBase : ExtendedEditor<IEntityTemplateInternal>
{ {
private ComponentDropDown _componentDropDown; private ComponentTemplatesDropDown _componentDropDown;
private SerializedProperty _componentsProp; private SerializedProperty _componentsProp;
private ReorderableList _reorderableComponentsList; private ReorderableList _reorderableComponentsList;
private int _reorderableComponentsListLastCount;
protected abstract bool IsSO { get; } protected abstract bool IsSO { get; }
@ -22,7 +23,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
protected override bool IsInit { get { return _componentDropDown != null; } } protected override bool IsInit { get { return _componentDropDown != null; } }
protected override void OnInit() protected override void OnInit()
{ {
_componentDropDown = new ComponentDropDown(); _componentDropDown = new ComponentTemplatesDropDown();
_componentsProp = serializedObject.FindProperty(Target.ComponentsPropertyName); _componentsProp = serializedObject.FindProperty(Target.ComponentsPropertyName);
@ -38,6 +39,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
_reorderableComponentsList.footerHeight = 0f; _reorderableComponentsList.footerHeight = 0f;
_reorderableComponentsList.headerHeight = 0f; _reorderableComponentsList.headerHeight = 0f;
_reorderableComponentsList.elementHeight = 0f; _reorderableComponentsList.elementHeight = 0f;
_reorderableComponentsListLastCount = _reorderableComponentsList.count;
} }
#region ReorderableComponentsList #region ReorderableComponentsList
@ -166,6 +169,15 @@ namespace DCFApixels.DragonECS.Unity.Editors
GUILayout.Label("Multi-object editing not supported.", EditorStyles.helpBox); GUILayout.Label("Multi-object editing not supported.", EditorStyles.helpBox);
return; return;
} }
else
{
//костыль который насильно заставляет _reorderableComponentsList пересчитать высоту
if (_reorderableComponentsListLastCount != _reorderableComponentsList.count)
{
EcsGUI.Changed = true;
_reorderableComponentsListLastCount = _reorderableComponentsList.count;
}
}
if (IsMultipleTargets == false && SerializationUtility.HasManagedReferencesWithMissingTypes(target)) if (IsMultipleTargets == false && SerializationUtility.HasManagedReferencesWithMissingTypes(target))
{ {