diff --git a/src/Connectors/EcsEntityConnect.cs b/src/Connectors/EcsEntityConnect.cs index 0f6a22b..9424779 100644 --- a/src/Connectors/EcsEntityConnect.cs +++ b/src/Connectors/EcsEntityConnect.cs @@ -4,6 +4,7 @@ using System.Runtime.CompilerServices; using UnityEngine; #region UNITY_EDITOR using UnityEditor; +using DCFApixels.DragonECS.Unity.Internal; #endregion namespace DCFApixels.DragonECS @@ -52,6 +53,7 @@ namespace DCFApixels.DragonECS } } + [SelectionBase] [DisallowMultipleComponent] [AddComponentMenu(EcsConsts.FRAMEWORK_NAME + "/" + nameof(EcsEntityConnect), 30)] public class EcsEntityConnect : MonoBehaviour @@ -59,6 +61,8 @@ namespace DCFApixels.DragonECS private entlong _entity; private EcsWorld _world; + private static SparseArray _connectedEntities = new SparseArray(); + [SerializeField] private bool _deleteEntiityWithDestroy = false; [SerializeField] @@ -108,6 +112,7 @@ namespace DCFApixels.DragonECS _isConnectInvoked = true; _entity = entity; _world = world; + _connectedEntities.Add(GetInstanceID(), this); var goConnects = world.GetPool(); if (goConnects.Has(newEntityID)) { @@ -136,6 +141,7 @@ namespace DCFApixels.DragonECS { var unityGameObjects = _world.GetPool(); unityGameObjects.TryDel(oldEntityID); + _connectedEntities.Remove(GetInstanceID()); } _world = null; _entity = entlong.NULL; @@ -161,10 +167,35 @@ namespace DCFApixels.DragonECS { entlong ent = _entity; Disconnect(); - if (_deleteEntiityWithDestroy && ent.TryUnpack(out int id, out EcsWorld world)) + + + if (_deleteEntiityWithDestroy == false) { - world.DelEntity(id); + return; } + ent.UnpackUnchecked(out int e, out short gen, out short worldID); + var world = EcsWorld.GetWorld(worldID); + if (world != null && world.IsAlive(e, gen)) + { + world.DelEntity(e); + } + + + //if (_deleteEntiityWithDestroy && ent.TryUnpack(out int id, out EcsWorld world)) + //{ + // world.DelEntity(id); + //} + } + #endregion + + #region Other + public static EcsEntityConnect GetConnectByInstanceID(int instanceID) + { + return _connectedEntities[instanceID]; + } + public static bool TryGetConnectByInstanceID(int instanceID, out EcsEntityConnect conncet) + { + return _connectedEntities.TryGetValue(instanceID, out conncet); } #endregion diff --git a/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs index 64f7f3e..258903d 100644 --- a/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs +++ b/src/EntityTemplate/Editor/ComponentTemplatePropertyDrawer.cs @@ -82,7 +82,7 @@ namespace DCFApixels.DragonECS.Unity.Editors public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { - if(property.propertyType == SerializedPropertyType.ManagedReference == false) + if (property.propertyType == SerializedPropertyType.ManagedReference == false) { return EditorGUI.GetPropertyHeight(property, label); } diff --git a/src/EntityTemplate/Editor/EntityTemplateEditor.cs b/src/EntityTemplate/Editor/EntityTemplateEditor.cs index 9a0ba6c..69e5926 100644 --- a/src/EntityTemplate/Editor/EntityTemplateEditor.cs +++ b/src/EntityTemplate/Editor/EntityTemplateEditor.cs @@ -71,6 +71,7 @@ namespace DCFApixels.DragonECS.Unity.Editors return; } } + int index = componentsProp.arraySize; componentsProp.InsertArrayElementAtIndex(index); componentsProp.GetArrayElementAtIndex(index).managedReferenceValue = ((IComponentTemplate)obj).Clone(); @@ -107,7 +108,6 @@ namespace DCFApixels.DragonECS.Unity.Editors { DrawComponentData(componentsProp.GetArrayElementAtIndex(i), componentsProp.arraySize, i); } - GUILayout.EndVertical(); } private void DrawTop(ITemplateInternal target)