Entity Attach

Entity Attach
This commit is contained in:
ALEXTANG
2022-08-08 17:09:59 +08:00
parent 464d1b230c
commit d95c5c24da
2 changed files with 28 additions and 1 deletions

View File

@@ -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<int,Action<EcsObject>>(EntityEvent.AttachToEntity,entity.InstanceId,(obj)=>
{
TLogger.LogInfoSuccessd("Attach Success"+obj.HashCode);
});
Entity.Destroy(entity);
Entity.Destroy(entity2);
}), 3f,false);

View File

@@ -26,6 +26,7 @@ namespace TEngine.EntityModule
}
private EntitySystem()
{
GameEventMgr.Instance.AddEventListener<int,Action<EcsObject>>(EntityEvent.AttachToEntity, AttachToEntity);
Update(true);
}
/// <summary>
@@ -189,5 +190,26 @@ namespace TEngine.EntityModule
}
#endregion
#region AttachEventToEntity
public void AttachToEntity(int instanceId,Action<EcsObject> 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");
}
}