Compare commits

...

5 Commits

Author SHA1 Message Date
DCFApixels
240e651575 up version to 0.5.14 2025-04-04 17:46:37 +08:00
DCFApixels
2fd798e631 add MetaIDGenerator 2025-04-04 17:43:05 +08:00
DCFApixels
fb8afe1aee up version to 0.5.13 2025-04-04 17:04:28 +08:00
DCFApixels
27b352032d Update ComponentTemplatePropertyDrawer.cs 2025-04-04 17:04:03 +08:00
DCFApixels
26afa999a9 simple refactoring/fix ReorderableList height 2025-04-04 15:56:25 +08:00
10 changed files with 89 additions and 15 deletions

View File

@ -8,7 +8,7 @@
"displayName": "DragonECS-Unity", "displayName": "DragonECS-Unity",
"description": "Integration with Unity for DragonECS", "description": "Integration with Unity for DragonECS",
"unity": "2021.2", "unity": "2021.2",
"version": "0.5.12", "version": "0.5.14",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/DCFApixels/DragonECS-Unity.git" "url": "https://github.com/DCFApixels/DragonECS-Unity.git"

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

View File

@ -9,7 +9,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
{ {
internal class DeepDebuggerWindow : EditorWindow internal class DeepDebuggerWindow : EditorWindow
{ {
public const string TITLE = "DeepDebuggerWindow"; public const string TITLE = nameof(DeepDebuggerWindow);
#if DRAGONECS_DEEP_DEBUG #if DRAGONECS_DEEP_DEBUG
[MenuItem("Tools/" + EcsConsts.FRAMEWORK_NAME + "/" + TITLE)] [MenuItem("Tools/" + EcsConsts.FRAMEWORK_NAME + "/" + TITLE)]

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 97fdad78c98d48c43a73aeecf2083cbb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d73207c0a0e08c3479a7101a2090e17c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,42 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace DCFApixels.DragonECS.Unity.Editors
{
internal class MetaIDGenerator : EditorWindow
{
public const string TITLE = nameof(MetaIDGenerator);
[MenuItem("Tools/" + EcsConsts.FRAMEWORK_NAME + "/" + TITLE)]
static void Open()
{
var wnd = GetWindow<MetaIDGenerator>();
wnd.titleContent = new GUIContent(TITLE);
wnd.minSize = new Vector2(100f, 120f);
wnd.Show();
}
private string _lastID;
private string _lastIDAttribute;
private string _template;
private void OnGUI()
{
EditorGUILayout.TextField("MetaID", _lastID);
EditorGUILayout.TextField("Attribute", _lastIDAttribute);
EditorGUILayout.TextField("Template Type", _template);
if (GUILayout.Button("Generate new MetaID"))
{
_lastID = MetaID.GenerateNewUniqueID();
_lastIDAttribute = MetaID.IDToAttribute(_lastID);
_template = "Tempalte" + MetaID.ConvertIDToTypeName(_lastID);
GUI.FocusControl(null);
}
}
}
}
#endif

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 63d0e9c5d1c44844abb3e6dc3c863668