mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Entity Attach
Entity Attach
This commit is contained in:
@@ -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);
|
||||
|
@@ -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");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user