mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Entity
Entity
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
public class EntityData : IMemory
|
||||
{
|
||||
protected Vector3 m_Position = Vector3.zero;
|
||||
|
||||
protected Quaternion m_Rotation = Quaternion.identity;
|
||||
|
||||
public EntityData()
|
||||
{
|
||||
m_Position = Vector3.zero;
|
||||
m_Rotation = Quaternion.identity;
|
||||
UserData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体位置。
|
||||
/// </summary>
|
||||
public Vector3 Position
|
||||
{
|
||||
get { return m_Position; }
|
||||
set { m_Position = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体朝向。
|
||||
/// </summary>
|
||||
public Quaternion Rotation
|
||||
{
|
||||
get { return m_Rotation; }
|
||||
set { m_Rotation = value; }
|
||||
}
|
||||
|
||||
public object UserData { get; protected set; }
|
||||
|
||||
public static EntityData Create(object userData = null)
|
||||
{
|
||||
EntityData entityData = MemoryPool.Acquire<EntityData>();
|
||||
entityData.Position = Vector3.zero;
|
||||
entityData.Rotation = Quaternion.identity;
|
||||
entityData.UserData = userData;
|
||||
return entityData;
|
||||
}
|
||||
|
||||
public static EntityData Create(Vector3 position, object userData = null)
|
||||
{
|
||||
EntityData entityData = MemoryPool.Acquire<EntityData>();
|
||||
entityData.Position = position;
|
||||
entityData.Rotation = Quaternion.identity;
|
||||
entityData.UserData = userData;
|
||||
return entityData;
|
||||
}
|
||||
|
||||
public static EntityData Create(Vector3 position, Quaternion quaternion, object userData = null)
|
||||
{
|
||||
EntityData entityData = MemoryPool.Acquire<EntityData>();
|
||||
entityData.Position = position;
|
||||
entityData.Rotation = quaternion;
|
||||
entityData.UserData = userData;
|
||||
return entityData;
|
||||
}
|
||||
|
||||
public virtual void Clear()
|
||||
{
|
||||
m_Position = Vector3.zero;
|
||||
m_Rotation = Quaternion.identity;
|
||||
UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 414727f378e043a7800d009402172d15
|
||||
timeCreated: 1662376564
|
@@ -0,0 +1,39 @@
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
public static class EntityExtension
|
||||
{
|
||||
private static int _serialId = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 生成客户端序列化ID,服务器默认不用
|
||||
/// </summary>
|
||||
/// <param name="entityComponent"></param>
|
||||
/// <returns></returns>
|
||||
public static int GenerateSerialId(this EntityComponent entityComponent)
|
||||
{
|
||||
return ++_serialId;
|
||||
}
|
||||
|
||||
public static void ShowEntity(this EntityComponent entityComponent, int serialId, int entityId,
|
||||
System.Type logicType, string assetPath, object userData = null, float autoReleaseInterval = 60f,
|
||||
int capacity = 60,
|
||||
float expireTime = 60f, int priority = 0)
|
||||
{
|
||||
if (serialId < 0)
|
||||
{
|
||||
Log.Error("Can not load entity id '{0}' from data table.", entityId.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entityComponent.HasEntityGroup(logicType.Name))
|
||||
{
|
||||
EntityComponent.Instance.AddEntityGroup(logicType.Name,
|
||||
autoReleaseInterval, capacity,
|
||||
expireTime, priority);
|
||||
}
|
||||
|
||||
entityComponent.ShowEntity(serialId, logicType, assetPath, logicType.Name,
|
||||
Constant.DefaultPriority, userData);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfc72f38bbb4465aaabec8fd9d5a461d
|
||||
timeCreated: 1662376752
|
@@ -0,0 +1,77 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
public abstract class EntityLogicEx : EntityLogic
|
||||
{
|
||||
[SerializeField] private EntityData m_EntityData = null;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get { return Entity.Id; }
|
||||
}
|
||||
|
||||
public Animation Animation { get; private set; }
|
||||
|
||||
protected internal override void OnInit(object userData)
|
||||
{
|
||||
base.OnInit(userData);
|
||||
Animation = GetComponent<Animation>();
|
||||
}
|
||||
|
||||
protected internal override void OnRecycle()
|
||||
{
|
||||
base.OnRecycle();
|
||||
}
|
||||
|
||||
protected internal override void OnShow(object userData)
|
||||
{
|
||||
base.OnShow(userData);
|
||||
|
||||
m_EntityData = userData as EntityData;
|
||||
if (m_EntityData == null)
|
||||
{
|
||||
Log.Error("Entity data is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
Name = Utility.Text.Format("[Entity {0}]", Id.ToString());
|
||||
CachedTransform.localPosition = m_EntityData.Position;
|
||||
CachedTransform.localRotation = m_EntityData.Rotation;
|
||||
CachedTransform.localScale = Vector3.one;
|
||||
}
|
||||
|
||||
protected internal override void OnHide(bool isShutdown, object userData)
|
||||
{
|
||||
base.OnHide(isShutdown, userData);
|
||||
|
||||
MemoryPool.Release(m_EntityData);
|
||||
}
|
||||
|
||||
protected internal override void OnAttached(EntityLogic childEntity, Transform parentTransform, object userData)
|
||||
{
|
||||
base.OnAttached(childEntity, parentTransform, userData);
|
||||
}
|
||||
|
||||
protected internal override void OnDetached(EntityLogic childEntity, object userData)
|
||||
{
|
||||
base.OnDetached(childEntity, userData);
|
||||
}
|
||||
|
||||
protected internal override void OnAttachTo(EntityLogic parentEntity, Transform parentTransform,
|
||||
object userData)
|
||||
{
|
||||
base.OnAttachTo(parentEntity, parentTransform, userData);
|
||||
}
|
||||
|
||||
protected internal override void OnDetachFrom(EntityLogic parentEntity, object userData)
|
||||
{
|
||||
base.OnDetachFrom(parentEntity, userData);
|
||||
}
|
||||
|
||||
protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
base.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48dddd54c9564e868d36fa1e0640c996
|
||||
timeCreated: 1662463218
|
@@ -14,7 +14,8 @@ namespace TEngine.Runtime.Entity
|
||||
/// <returns>实例化后的实体。</returns>
|
||||
public override object InstantiateEntity(object entityAsset)
|
||||
{
|
||||
return Instantiate((Object)entityAsset);
|
||||
// return Instantiate((Object)entityAsset);
|
||||
return (Object)entityAsset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user