mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
EntitySystem
EntitySystem
This commit is contained in:
@@ -4,8 +4,8 @@ using TEngine.Runtime.Entity;
|
|||||||
|
|
||||||
namespace TEngine.Editor
|
namespace TEngine.Editor
|
||||||
{
|
{
|
||||||
[CustomEditor(typeof(EntityComponent))]
|
[CustomEditor(typeof(EntitySystem))]
|
||||||
internal sealed class EntityComponentInspector : TEngineInspector
|
internal sealed class EntitySystemInspector : TEngineInspector
|
||||||
{
|
{
|
||||||
private SerializedProperty m_EnableShowEntityUpdateEvent = null;
|
private SerializedProperty m_EnableShowEntityUpdateEvent = null;
|
||||||
private SerializedProperty m_EnableShowEntityDependencyAssetEvent = null;
|
private SerializedProperty m_EnableShowEntityDependencyAssetEvent = null;
|
||||||
@@ -23,7 +23,7 @@ namespace TEngine.Editor
|
|||||||
|
|
||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
|
|
||||||
EntityComponent t = (EntityComponent)target;
|
EntitySystem t = (EntitySystem)target;
|
||||||
|
|
||||||
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
|
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
|
||||||
{
|
{
|
@@ -6,7 +6,7 @@ namespace TEngine.Runtime.Entity
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 实体。
|
/// 实体。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class Entity : MonoBehaviour, IEntity
|
public partial class Entity : MonoBehaviour, IEntity
|
||||||
{
|
{
|
||||||
private int m_Id;
|
private int m_Id;
|
||||||
private string m_EntityAssetName;
|
private string m_EntityAssetName;
|
||||||
|
@@ -7,9 +7,9 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 生成客户端序列化ID/EntityID,服务器默认不用
|
/// 生成客户端序列化ID/EntityID,服务器默认不用
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="entityComponent"></param>
|
/// <param name="entitySystem"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int GenerateSerialId(this EntityComponent entityComponent)
|
public static int GenerateSerialId(this EntitySystem entitySystem)
|
||||||
{
|
{
|
||||||
return ++_serialId;
|
return ++_serialId;
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,26 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建实体
|
/// 创建实体
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="entityComponent">EntityComponent</param>
|
/// <param name="entitySystem">EntitySystem</param>
|
||||||
|
/// <param name="assetPath">实体资源路径</param>
|
||||||
|
/// <param name="userData">实体数据</param>
|
||||||
|
/// <param name="autoReleaseInterval">实体实例对象池自动释放可释放对象的间隔秒数</param>
|
||||||
|
/// <param name="capacity">实体实例对象池容量</param>
|
||||||
|
/// <param name="expireTime">实体实例对象池对象过期秒数</param>
|
||||||
|
/// <param name="priority">实体实例对象池的优先级</param>
|
||||||
|
/// <typeparam name="T">实体类型</typeparam>
|
||||||
|
public static void CreateEntity<T>(this EntitySystem entitySystem, string assetPath,
|
||||||
|
object userData, float autoReleaseInterval = 60f,
|
||||||
|
int capacity = 60, float expireTime = 60f, int priority = 0)
|
||||||
|
{
|
||||||
|
entitySystem.CreateEntity(typeof(T), assetPath, userData, autoReleaseInterval, capacity, expireTime,
|
||||||
|
priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建实体
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entitySystem">EntitySystem</param>
|
||||||
/// <param name="assetPath">实体资源路径</param>
|
/// <param name="assetPath">实体资源路径</param>
|
||||||
/// <param name="userData">EntityData实体数据</param>
|
/// <param name="userData">EntityData实体数据</param>
|
||||||
/// <param name="autoReleaseInterval">实体实例对象池自动释放可释放对象的间隔秒数</param>
|
/// <param name="autoReleaseInterval">实体实例对象池自动释放可释放对象的间隔秒数</param>
|
||||||
@@ -25,7 +44,7 @@
|
|||||||
/// <param name="expireTime">实体实例对象池对象过期秒数</param>
|
/// <param name="expireTime">实体实例对象池对象过期秒数</param>
|
||||||
/// <param name="priority">实体实例对象池的优先级</param>
|
/// <param name="priority">实体实例对象池的优先级</param>
|
||||||
/// <typeparam name="T">实体类型</typeparam>
|
/// <typeparam name="T">实体类型</typeparam>
|
||||||
public static void CreateEntity<T>(this EntityComponent entityComponent, string assetPath,
|
public static void CreateEntity<T>(this EntitySystem entitySystem, string assetPath,
|
||||||
EntityData userData = null, float autoReleaseInterval = 60f,
|
EntityData userData = null, float autoReleaseInterval = 60f,
|
||||||
int capacity = 60, float expireTime = 60f, int priority = 0)
|
int capacity = 60, float expireTime = 60f, int priority = 0)
|
||||||
{
|
{
|
||||||
@@ -34,14 +53,14 @@
|
|||||||
userData = EntityData.Create();
|
userData = EntityData.Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
entityComponent.CreateEntity(typeof(T), assetPath, userData, autoReleaseInterval, capacity, expireTime,
|
entitySystem.CreateEntity(typeof(T), assetPath, userData, autoReleaseInterval, capacity, expireTime,
|
||||||
priority);
|
priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建实体
|
/// 创建实体
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="entityComponent"></param>
|
/// <param name="entitySystem"></param>
|
||||||
/// <param name="logicType"></param>
|
/// <param name="logicType"></param>
|
||||||
/// <param name="assetPath"></param>
|
/// <param name="assetPath"></param>
|
||||||
/// <param name="userData"></param>
|
/// <param name="userData"></param>
|
||||||
@@ -49,20 +68,20 @@
|
|||||||
/// <param name="capacity"></param>
|
/// <param name="capacity"></param>
|
||||||
/// <param name="expireTime"></param>
|
/// <param name="expireTime"></param>
|
||||||
/// <param name="priority"></param>
|
/// <param name="priority"></param>
|
||||||
public static void CreateEntity(this EntityComponent entityComponent, System.Type logicType, string assetPath,
|
public static void CreateEntity(this EntitySystem entitySystem, System.Type logicType, string assetPath,
|
||||||
object userData = null, float autoReleaseInterval = 60f,
|
object userData = null, float autoReleaseInterval = 60f,
|
||||||
int capacity = 60,
|
int capacity = 60,
|
||||||
float expireTime = 60f, int priority = 0)
|
float expireTime = 60f, int priority = 0)
|
||||||
{
|
{
|
||||||
var entityId = entityComponent.GenerateSerialId();
|
var entityId = entitySystem.GenerateSerialId();
|
||||||
entityComponent.CreateEntity(entityId, logicType, assetPath, userData, autoReleaseInterval, capacity,
|
entitySystem.CreateEntity(entityId, logicType, assetPath, userData, autoReleaseInterval, capacity,
|
||||||
expireTime, priority);
|
expireTime, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建实体
|
/// 创建实体
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="entityComponent"></param>
|
/// <param name="entitySystem"></param>
|
||||||
/// <param name="entityId"></param>
|
/// <param name="entityId"></param>
|
||||||
/// <param name="logicType"></param>
|
/// <param name="logicType"></param>
|
||||||
/// <param name="assetPath"></param>
|
/// <param name="assetPath"></param>
|
||||||
@@ -71,7 +90,7 @@
|
|||||||
/// <param name="capacity"></param>
|
/// <param name="capacity"></param>
|
||||||
/// <param name="expireTime"></param>
|
/// <param name="expireTime"></param>
|
||||||
/// <param name="priority"></param>
|
/// <param name="priority"></param>
|
||||||
public static void CreateEntity(this EntityComponent entityComponent, int entityId,
|
public static void CreateEntity(this EntitySystem entitySystem, int entityId,
|
||||||
System.Type logicType, string assetPath, object userData = null, float autoReleaseInterval = 60f,
|
System.Type logicType, string assetPath, object userData = null, float autoReleaseInterval = 60f,
|
||||||
int capacity = 60,
|
int capacity = 60,
|
||||||
float expireTime = 60f, int priority = 0)
|
float expireTime = 60f, int priority = 0)
|
||||||
@@ -82,14 +101,14 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!entityComponent.HasEntityGroup(logicType.Name))
|
if (!entitySystem.HasEntityGroup(logicType.Name))
|
||||||
{
|
{
|
||||||
EntityComponent.Instance.AddEntityGroup(logicType.Name,
|
EntitySystem.Instance.AddEntityGroup(logicType.Name,
|
||||||
autoReleaseInterval, capacity,
|
autoReleaseInterval, capacity,
|
||||||
expireTime, priority);
|
expireTime, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
entityComponent.ShowEntity(entityId, logicType, assetPath, logicType.Name,
|
entitySystem.ShowEntity(entityId, logicType, assetPath, logicType.Name,
|
||||||
Constant.DefaultPriority, userData);
|
Constant.DefaultPriority, userData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace TEngine.Runtime.Entity
|
namespace TEngine.Runtime.Entity
|
||||||
{
|
{
|
||||||
public sealed partial class EntityComponent
|
public sealed partial class EntitySystem
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
private sealed class EntityGroup
|
private sealed class EntityGroup
|
@@ -9,8 +9,8 @@ namespace TEngine.Runtime.Entity
|
|||||||
/// 实体组件。
|
/// 实体组件。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
[AddComponentMenu("TEngine/EntityManager")]
|
[AddComponentMenu("TEngine/EntitySys")]
|
||||||
public sealed partial class EntityComponent : UnitySingleton<EntityComponent>
|
public sealed partial class EntitySystem : UnitySingleton<EntitySystem>
|
||||||
{
|
{
|
||||||
private const int DefaultPriority = 0;
|
private const int DefaultPriority = 0;
|
||||||
|
|
Reference in New Issue
Block a user