diff --git a/Assets/TEngine/Runtime/Entity/Demo/ECSDemoApp.cs b/Assets/TEngine/Runtime/Entity/Demo/ECSDemoApp.cs index ac20b85d..cd7c0203 100644 --- a/Assets/TEngine/Runtime/Entity/Demo/ECSDemoApp.cs +++ b/Assets/TEngine/Runtime/Entity/Demo/ECSDemoApp.cs @@ -1,4 +1,5 @@ -using TEngine.EntityModule; +using System; +using TEngine.EntityModule; using UnityEngine; namespace TEngine @@ -33,6 +34,10 @@ namespace TEngine TimerMgr.Instance.AddTimer((args => { + GameEventMgr.Instance.Send>(EntityEvent.AttachToEntity,entity.InstanceId,(obj)=> + { + TLogger.LogInfoSuccessd("Attach Success"+obj.HashCode); + }); Entity.Destroy(entity); Entity.Destroy(entity2); }), 3f,false); diff --git a/Assets/TEngine/Runtime/Entity/EntitySystem.cs b/Assets/TEngine/Runtime/Entity/EntitySystem.cs index fe2e7a27..127c60e9 100644 --- a/Assets/TEngine/Runtime/Entity/EntitySystem.cs +++ b/Assets/TEngine/Runtime/Entity/EntitySystem.cs @@ -26,6 +26,7 @@ namespace TEngine.EntityModule } private EntitySystem() { + GameEventMgr.Instance.AddEventListener>(EntityEvent.AttachToEntity, AttachToEntity); Update(true); } /// @@ -189,5 +190,26 @@ namespace TEngine.EntityModule } #endregion + #region AttachEventToEntity + + public void AttachToEntity(int instanceId,Action callback) + { + if (EcsObjects.TryGetValue(instanceId,out var entity)) + { + if (entity.IsDisposed) + { + return; + } + callback?.Invoke(entity); + } + } + + + #endregion + } + + public static class EntityEvent + { + public static int AttachToEntity = StringId.StringToHash("EntityEvent.AttachToEntity"); } } \ No newline at end of file