Update EntitySystem.cs

Update EntitySystem.cs
This commit is contained in:
ALEXTANG
2022-08-08 18:05:36 +08:00
parent e6f8af72a3
commit fb679832b3
5 changed files with 36 additions and 38 deletions

View File

@@ -10,28 +10,16 @@ namespace TEngine
void Start()
{
var entity = Entity.Create<Entity>();
var entity = Entity.Create<GameObjectEntity>();
entity.AddComponent<TestUpdateCmpt>();
GameObjectCmpt actor = entity.AddComponent<GameObjectCmpt>();
actor.Name = typeof(GameObjectCmpt).ToString();
actor.gameObject = Instantiate(@object);
actor.transform = actor.gameObject.GetComponent<Transform>();
entity.AddComponent<EntityComponent>();
entity.CheckDebugInfo(actor.gameObject);
entity.Bind(Instantiate(@object));
Debug.Log(entity.ToString());
var entity2 = Entity.Create<Entity>();
GameObjectCmpt actor2 = entity2.AddComponent<GameObjectCmpt>();
actor2.Name = typeof(GameObjectCmpt).ToString();
actor2.gameObject = Instantiate(@object);
actor2.transform = actor2.gameObject.GetComponent<Transform>();
entity2.AddComponent<EntityComponent>();
entity2.CheckDebugInfo(actor2.gameObject);
var entity2 = Entity.Create<GameObjectEntity>();
entity2.Bind(Instantiate(@object));
Debug.Log(entity2.ToString());
TimerMgr.Instance.AddTimer((args =>
{
GameEventMgr.Instance.Send<int,Action<EcsObject>>(EntityEvent.AttachToEntity,entity.InstanceId,(obj)=>

View File

@@ -4,7 +4,7 @@
/// Entity构架可以将此组件从Entity上移除这个组件并丢入对象池给其他此刻需要此组件的Entity使用
/// 因此可以节省大量的内存反复创建和释放, 这也是Entity的特性可以大量重复使用组件
/// </summary>
public class EntityComponent : EcsObject
public abstract class EntityComponent : EcsObject
{
public Entity Entity { get; set; }

View File

@@ -1,20 +0,0 @@
namespace TEngine.EntityModule
{
/// <summary>
/// Entity Actor
/// </summary>
public class GameObjectCmpt :EntityComponent
{
public string Name;
public UnityEngine.GameObject gameObject;
public UnityEngine.Transform transform;
public override void OnDestroy()
{
if (gameObject != null)
{
UnityEngine.GameObject.Destroy(gameObject);
}
}
}
}

View File

@@ -0,0 +1,30 @@
using TEngine.EntityModule;
using UnityEngine;
public class GameObjectEntity :Entity
{
public GameObject gameObject;
public Transform tranform;
public void Bind(GameObject gameObject)
{
this.gameObject = gameObject;
tranform = this.gameObject.transform;
}
public override void Awake()
{
base.Awake();
}
public override void OnDestroy()
{
if (gameObject != null)
{
Object.Destroy(gameObject);
gameObject = null;
}
tranform = null;
base.OnDestroy();
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 559f282b0e220ab4e8ccb2342e13aaf2
guid: de9cbd2c7aab4a74a92303b5a7b14d3e
MonoImporter:
externalObjects: {}
serializedVersion: 2