diff --git a/src/Connectors/EcsEntityConnect.cs b/src/Connectors/EcsEntityConnect.cs index 0f08c57..1e6f997 100644 --- a/src/Connectors/EcsEntityConnect.cs +++ b/src/Connectors/EcsEntityConnect.cs @@ -61,6 +61,8 @@ namespace DCFApixels.DragonECS [SerializeField] private MonoEntityTemplate[] _monoTemplates; + private bool _isConnected = false; + #region Properties public entlong Entity { @@ -98,34 +100,36 @@ namespace DCFApixels.DragonECS if (entity.TryUnpack(out int newEntityID, out EcsWorld world)) { + _isConnected = true; _entity = entity; _world = world; - var unityGameObjects = _world.GetPool(); - if (unityGameObjects.Has(newEntityID)) + var goConnects = world.GetPool(); + if (goConnects.Has(newEntityID)) { - ref readonly var uconnect = ref unityGameObjects.Read(newEntityID); - if (uconnect.IsConnected) + ref readonly var goConnect = ref goConnects.Read(newEntityID); + if (goConnect.IsConnected) { - uconnect.connect.Disconnect(); + goConnect.Connect.Disconnect(); } } - unityGameObjects.TryAddOrGet(newEntityID) = new UnityGameObjectConnect(this); + goConnects.TryAddOrGet(newEntityID) = new GameObjectConnect(this); if (applyTemplates) { ApplyTemplatesFor(world.id, newEntityID); } } - else - { - _entity = entlong.NULL; - } } public void Disconnect() { + if(_isConnected == false) + { + return; + } + _isConnected = false; if (_entity.TryGetID(out int oldEntityID) && _world != null) { - var unityGameObjects = _world.GetPool(); + var unityGameObjects = _world.GetPool(); unityGameObjects.TryDel(oldEntityID); } _world = null; diff --git a/src/Connectors/UnityGameObjectConnect.cs b/src/Connectors/GameObjectConnect.cs similarity index 71% rename from src/Connectors/UnityGameObjectConnect.cs rename to src/Connectors/GameObjectConnect.cs index e92b602..71c21ec 100644 --- a/src/Connectors/UnityGameObjectConnect.cs +++ b/src/Connectors/GameObjectConnect.cs @@ -7,35 +7,29 @@ using UnityEditor; namespace DCFApixels.DragonECS { [MetaColor(MetaColor.Cyan)] - public readonly struct UnityGameObjectConnect : IEcsComponent, IEcsComponentLifecycle + public readonly struct GameObjectConnect : IEcsComponent, IEcsComponentLifecycle { - public readonly EcsEntityConnect connect; - public readonly Transform transform; - public string Name - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get { return connect.name; } - } + public readonly EcsEntityConnect Connect; public bool IsConnected { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get { return connect != null; } + get { return Connect != null; } } - internal UnityGameObjectConnect(EcsEntityConnect connect) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal GameObjectConnect(EcsEntityConnect connect) { - this.connect = connect; - transform = connect.transform; + Connect = connect; } - void IEcsComponentLifecycle.Enable(ref UnityGameObjectConnect component) + void IEcsComponentLifecycle.Enable(ref GameObjectConnect component) { component = default; } - void IEcsComponentLifecycle.Disable(ref UnityGameObjectConnect component) + void IEcsComponentLifecycle.Disable(ref GameObjectConnect component) { - if (component.connect != null) + if (component.Connect != null) { - component.connect.Disconnect(); + component.Connect.Disconnect(); } component = default; } @@ -69,7 +63,7 @@ namespace DCFApixels.DragonECS Diamond_Red, Diamond_Purple } - public static class GameObjectIconConsts + internal static class GameObjectIconConsts { public const int RAW_LABEL_ICON_LAST = (int)GameObjectIcon.Label_Purple; } diff --git a/src/Connectors/UnityGameObjectConnect.cs.meta b/src/Connectors/GameObjectConnect.cs.meta similarity index 100% rename from src/Connectors/UnityGameObjectConnect.cs.meta rename to src/Connectors/GameObjectConnect.cs.meta