From d95c5c24da38c6276a304bcfc26efc92b6008bc7 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Mon, 8 Aug 2022 17:09:59 +0800 Subject: [PATCH] Entity Attach Entity Attach --- .../TEngine/Runtime/Entity/Demo/ECSDemoApp.cs | 7 +++++- Assets/TEngine/Runtime/Entity/EntitySystem.cs | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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