Update
This commit is contained in:
ALEXTANG
2022-08-08 17:35:36 +08:00
parent 9b318e0a0b
commit 60a01056f1
3 changed files with 23 additions and 6 deletions

View File

@@ -40,6 +40,12 @@ namespace TEngine
}); });
Entity.Destroy(entity); Entity.Destroy(entity);
Entity.Destroy(entity2); Entity.Destroy(entity2);
TimerMgr.Instance.AddTimer(objects =>
{
Start();
}, 3f);
}), 3f,false); }), 3f,false);
} }

View File

@@ -12,7 +12,7 @@ namespace TEngine.EntityModule
public int InstanceId public int InstanceId
{ {
get; get;
protected set; set;
} }
internal int HashCode internal int HashCode
@@ -30,8 +30,6 @@ namespace TEngine.EntityModule
public EcsObject() public EcsObject()
{ {
HashCode = GetType().GetHashCode(); HashCode = GetType().GetHashCode();
InstanceId = EntitySystem.Instance.CurInstanceId;
EntitySystem.Instance.CurInstanceId++;
} }
public virtual void Dispose() public virtual void Dispose()

View File

@@ -27,7 +27,11 @@ namespace TEngine.EntityModule
private EntitySystem() private EntitySystem()
{ {
GameEventMgr.Instance.AddEventListener<int,Action<EcsObject>>(EntityEvent.AttachToEntity, AttachToEntity); GameEventMgr.Instance.AddEventListener<int,Action<EcsObject>>(EntityEvent.AttachToEntity, AttachToEntity);
Update(true); //Update(true);
MonoUtility.AddUpdateListener((() =>
{
Update(false);
}));
MonoUtility.AddFixedUpdateListener(FixedUpdate); MonoUtility.AddFixedUpdateListener(FixedUpdate);
MonoUtility.AddLateUpdateListener(LateUpdate); MonoUtility.AddLateUpdateListener(LateUpdate);
} }
@@ -59,17 +63,26 @@ namespace TEngine.EntityModule
{ {
if (stack.Count > 0) if (stack.Count > 0)
{ {
return (T)stack.Pop(); var poolObj = (T)stack.Pop();
GenInstanceId(poolObj);
return poolObj;
} }
goto Instantiate; goto Instantiate;
} }
stack = new Stack<EcsObject>(); stack = new Stack<EcsObject>();
ObjectPool.Add(type, stack); ObjectPool.Add(type, stack);
Instantiate: T ecsObject = new T(); Instantiate: T ecsObject = new T();
EcsObjects.Add(ecsObject.InstanceId, ecsObject); GenInstanceId(ecsObject);
return ecsObject; return ecsObject;
} }
private void GenInstanceId(EcsObject ecsObject)
{
ecsObject.InstanceId = CurInstanceId;
Instance.CurInstanceId++;
EcsObjects.Add(ecsObject.InstanceId, ecsObject);
}
internal void Push(EcsObject ecsObject) internal void Push(EcsObject ecsObject)
{ {
int type = ecsObject.HashCode; int type = ecsObject.HashCode;