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 =>
{
@ -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 =>
{
@ -268,6 +268,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
protected override void ItemSelected(AdvancedDropdownItem item)
{
//EcsGUI.Changed = true;
base.ItemSelected(item);
var tType = (Item)item;
ItemSelected(tType);

View File

@ -507,9 +507,9 @@ namespace DCFApixels.DragonECS.Unity.Editors
{
public struct WorldData
{
public RuntimeComponentDropDown addComponentGenericMenu;
public RuntimeComponentsDropDown addComponentGenericMenu;
public int poolsCount;
public WorldData(RuntimeComponentDropDown addComponentGenericMenu, int poolsCount)
public WorldData(RuntimeComponentsDropDown addComponentGenericMenu, int poolsCount)
{
this.addComponentGenericMenu = addComponentGenericMenu;
this.poolsCount = poolsCount;
@ -518,7 +518,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
//world id
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))
{
@ -541,7 +541,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
private static WorldData CreateWorldData(EcsWorld world)
{
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);
}

View File

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

View File

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