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