mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Update EntitySystem.cs
Update EntitySystem.cs
This commit is contained in:
@@ -10,26 +10,14 @@ namespace TEngine
|
|||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
var entity = Entity.Create<Entity>();
|
var entity = Entity.Create<GameObjectEntity>();
|
||||||
entity.AddComponent<TestUpdateCmpt>();
|
entity.AddComponent<TestUpdateCmpt>();
|
||||||
GameObjectCmpt actor = entity.AddComponent<GameObjectCmpt>();
|
entity.Bind(Instantiate(@object));
|
||||||
actor.Name = typeof(GameObjectCmpt).ToString();
|
|
||||||
actor.gameObject = Instantiate(@object);
|
|
||||||
actor.transform = actor.gameObject.GetComponent<Transform>();
|
|
||||||
entity.AddComponent<EntityComponent>();
|
|
||||||
entity.CheckDebugInfo(actor.gameObject);
|
|
||||||
Debug.Log(entity.ToString());
|
Debug.Log(entity.ToString());
|
||||||
|
|
||||||
var entity2 = Entity.Create<Entity>();
|
var entity2 = Entity.Create<GameObjectEntity>();
|
||||||
GameObjectCmpt actor2 = entity2.AddComponent<GameObjectCmpt>();
|
entity2.Bind(Instantiate(@object));
|
||||||
actor2.Name = typeof(GameObjectCmpt).ToString();
|
|
||||||
actor2.gameObject = Instantiate(@object);
|
|
||||||
actor2.transform = actor2.gameObject.GetComponent<Transform>();
|
|
||||||
entity2.AddComponent<EntityComponent>();
|
|
||||||
entity2.CheckDebugInfo(actor2.gameObject);
|
|
||||||
Debug.Log(entity2.ToString());
|
Debug.Log(entity2.ToString());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TimerMgr.Instance.AddTimer((args =>
|
TimerMgr.Instance.AddTimer((args =>
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
/// Entity构架可以将此组件从Entity上移除这个组件并丢入对象池,给其他此刻需要此组件的Entity使用,
|
/// Entity构架可以将此组件从Entity上移除这个组件并丢入对象池,给其他此刻需要此组件的Entity使用,
|
||||||
/// 因此可以节省大量的内存反复创建和释放, 这也是Entity的特性可以大量重复使用组件
|
/// 因此可以节省大量的内存反复创建和释放, 这也是Entity的特性可以大量重复使用组件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityComponent : EcsObject
|
public abstract class EntityComponent : EcsObject
|
||||||
{
|
{
|
||||||
public Entity Entity { get; set; }
|
public Entity Entity { get; set; }
|
||||||
|
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
30
Assets/TEngine/Runtime/Entity/GameObjectEntity.cs
Normal file
30
Assets/TEngine/Runtime/Entity/GameObjectEntity.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 559f282b0e220ab4e8ccb2342e13aaf2
|
guid: de9cbd2c7aab4a74a92303b5a7b14d3e
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
Reference in New Issue
Block a user