mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
Entity
Entity
This commit is contained in:
@@ -254,6 +254,14 @@ PrefabInstance:
|
||||
m_Modification:
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 96376813, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3}
|
||||
propertyPath: m_EntityHelperTypeName
|
||||
value: TEngine.Runtime.Entity.DefaultEntityHelper
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 96376813, guid: 161ff7c8132079c4a95e2e4e70ddd41b, type: 3}
|
||||
propertyPath: m_EntityGroupHelperTypeName
|
||||
value: TEngine.Runtime.Entity.DefaultEntityGroupHelper
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3463045026180535776, guid: 161ff7c8132079c4a95e2e4e70ddd41b,
|
||||
type: 3}
|
||||
propertyPath: m_Name
|
||||
|
@@ -1,5 +1,56 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &96376811
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 96376812}
|
||||
- component: {fileID: 96376813}
|
||||
m_Layer: 0
|
||||
m_Name: Entity
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &96376812
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 96376811}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 3463045026180535779}
|
||||
m_RootOrder: 7
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &96376813
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 96376811}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fc62b60a444ff0c4a952566cb2ecd2fa, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_EnableShowEntityUpdateEvent: 0
|
||||
m_EnableShowEntityDependencyAssetEvent: 0
|
||||
m_InstanceRoot: {fileID: 0}
|
||||
m_EntityHelperTypeName: UnityGameFramework.Runtime.DefaultEntityHelper
|
||||
m_CustomEntityHelper: {fileID: 0}
|
||||
m_EntityGroupHelperTypeName: UnityGameFramework.Runtime.DefaultEntityGroupHelper
|
||||
m_CustomEntityGroupHelper: {fileID: 0}
|
||||
m_EntityGroups: []
|
||||
--- !u!1 &1672025513
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -334,6 +385,7 @@ Transform:
|
||||
- {fileID: 3463045026010536331}
|
||||
- {fileID: 3463045025307533286}
|
||||
- {fileID: 1672025514}
|
||||
- {fileID: 96376812}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
|
@@ -0,0 +1,84 @@
|
||||
using UnityEditor;
|
||||
using TEngine.Runtime;
|
||||
using TEngine.Runtime.Entity;
|
||||
|
||||
namespace TEngine.Editor
|
||||
{
|
||||
[CustomEditor(typeof(EntityComponent))]
|
||||
internal sealed class EntityComponentInspector : TEngineInspector
|
||||
{
|
||||
private SerializedProperty m_EnableShowEntityUpdateEvent = null;
|
||||
private SerializedProperty m_EnableShowEntityDependencyAssetEvent = null;
|
||||
private SerializedProperty m_InstanceRoot = null;
|
||||
private SerializedProperty m_EntityGroups = null;
|
||||
|
||||
private HelperInfo<EntityHelperBase> m_EntityHelperInfo = new HelperInfo<EntityHelperBase>("Entity");
|
||||
|
||||
private HelperInfo<EntityGroupHelperBase> m_EntityGroupHelperInfo =
|
||||
new HelperInfo<EntityGroupHelperBase>("EntityGroup");
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
EntityComponent t = (EntityComponent)target;
|
||||
|
||||
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_EnableShowEntityUpdateEvent);
|
||||
EditorGUILayout.PropertyField(m_EnableShowEntityDependencyAssetEvent);
|
||||
EditorGUILayout.PropertyField(m_InstanceRoot);
|
||||
m_EntityHelperInfo.Draw();
|
||||
m_EntityGroupHelperInfo.Draw();
|
||||
EditorGUILayout.PropertyField(m_EntityGroups, true);
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
|
||||
{
|
||||
EditorGUILayout.LabelField("Entity Group Count", t.EntityGroupCount.ToString());
|
||||
EditorGUILayout.LabelField("Entity Count (Total)", t.EntityCount.ToString());
|
||||
IEntityGroup[] entityGroups = t.GetAllEntityGroups();
|
||||
foreach (IEntityGroup entityGroup in entityGroups)
|
||||
{
|
||||
EditorGUILayout.LabelField(Utility.Text.Format("Entity Count ({0})", entityGroup.Name),
|
||||
entityGroup.EntityCount.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
Repaint();
|
||||
}
|
||||
|
||||
protected override void OnCompileComplete()
|
||||
{
|
||||
base.OnCompileComplete();
|
||||
|
||||
RefreshTypeNames();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_EnableShowEntityUpdateEvent = serializedObject.FindProperty("m_EnableShowEntityUpdateEvent");
|
||||
m_EnableShowEntityDependencyAssetEvent =
|
||||
serializedObject.FindProperty("m_EnableShowEntityDependencyAssetEvent");
|
||||
m_InstanceRoot = serializedObject.FindProperty("m_InstanceRoot");
|
||||
m_EntityGroups = serializedObject.FindProperty("m_EntityGroups");
|
||||
|
||||
m_EntityHelperInfo.Init(serializedObject);
|
||||
m_EntityGroupHelperInfo.Init(serializedObject);
|
||||
|
||||
RefreshTypeNames();
|
||||
}
|
||||
|
||||
private void RefreshTypeNames()
|
||||
{
|
||||
m_EntityHelperInfo.Refresh();
|
||||
m_EntityGroupHelperInfo.Refresh();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1af7d751dbbd0b747abf134b41b933e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/TEngine/Scripts/Runtime/Entity.meta
Normal file
8
Assets/TEngine/Scripts/Runtime/Entity.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f0f5b0fa0da6bd4796b1653da8b5f30
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/TEngine/Scripts/Runtime/Entity/Core.meta
Normal file
8
Assets/TEngine/Scripts/Runtime/Entity/Core.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1890cc3fe06b2b4da111ef7ddf8a427
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
internal sealed class AttachEntityInfo : IMemory
|
||||
{
|
||||
private Transform m_ParentTransform;
|
||||
private object m_UserData;
|
||||
|
||||
public AttachEntityInfo()
|
||||
{
|
||||
m_ParentTransform = null;
|
||||
m_UserData = null;
|
||||
}
|
||||
|
||||
public Transform ParentTransform
|
||||
{
|
||||
get { return m_ParentTransform; }
|
||||
}
|
||||
|
||||
public object UserData
|
||||
{
|
||||
get { return m_UserData; }
|
||||
}
|
||||
|
||||
public static AttachEntityInfo Create(Transform parentTransform, object userData)
|
||||
{
|
||||
AttachEntityInfo attachEntityInfo = MemoryPool.Acquire<AttachEntityInfo>();
|
||||
attachEntityInfo.m_ParentTransform = parentTransform;
|
||||
attachEntityInfo.m_UserData = userData;
|
||||
return attachEntityInfo;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_ParentTransform = null;
|
||||
m_UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3c6e44db8714628925debf2ddb7f77e
|
||||
timeCreated: 1662367448
|
3
Assets/TEngine/Scripts/Runtime/Entity/Core/Entity.meta
Normal file
3
Assets/TEngine/Scripts/Runtime/Entity/Core/Entity.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6741e1112b8479b80f987aa31465d11
|
||||
timeCreated: 1662367755
|
271
Assets/TEngine/Scripts/Runtime/Entity/Core/Entity/Entity.cs
Normal file
271
Assets/TEngine/Scripts/Runtime/Entity/Core/Entity/Entity.cs
Normal file
@@ -0,0 +1,271 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体。
|
||||
/// </summary>
|
||||
public sealed class Entity : MonoBehaviour, IEntity
|
||||
{
|
||||
private int m_Id;
|
||||
private string m_EntityAssetName;
|
||||
private IEntityGroup m_EntityGroup;
|
||||
private EntityLogic m_EntityLogic;
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体编号。
|
||||
/// </summary>
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Id;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体资源名称。
|
||||
/// </summary>
|
||||
public string EntityAssetName
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EntityAssetName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体实例。
|
||||
/// </summary>
|
||||
public object Handle
|
||||
{
|
||||
get
|
||||
{
|
||||
return gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体所属的实体组。
|
||||
/// </summary>
|
||||
public IEntityGroup EntityGroup
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EntityGroup;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体逻辑。
|
||||
/// </summary>
|
||||
public EntityLogic Logic
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EntityLogic;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体初始化。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <param name="entityGroup">实体所属的实体组。</param>
|
||||
/// <param name="isNewInstance">是否是新实例。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void OnInit(int entityId, string entityAssetName, IEntityGroup entityGroup, bool isNewInstance, object userData)
|
||||
{
|
||||
m_Id = entityId;
|
||||
m_EntityAssetName = entityAssetName;
|
||||
if (isNewInstance)
|
||||
{
|
||||
m_EntityGroup = entityGroup;
|
||||
}
|
||||
else if (m_EntityGroup != entityGroup)
|
||||
{
|
||||
Log.Error("Entity group is inconsistent for non-new-instance entity.");
|
||||
return;
|
||||
}
|
||||
|
||||
ShowEntityInfo showEntityInfo = (ShowEntityInfo)userData;
|
||||
Type entityLogicType = showEntityInfo.EntityLogicType;
|
||||
if (entityLogicType == null)
|
||||
{
|
||||
Log.Error("Entity logic type is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_EntityLogic != null)
|
||||
{
|
||||
if (m_EntityLogic.GetType() == entityLogicType)
|
||||
{
|
||||
m_EntityLogic.enabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Destroy(m_EntityLogic);
|
||||
m_EntityLogic = null;
|
||||
}
|
||||
|
||||
m_EntityLogic = gameObject.AddComponent(entityLogicType) as EntityLogic;
|
||||
if (m_EntityLogic == null)
|
||||
{
|
||||
Log.Error("Entity '{0}' can not add entity logic.", entityAssetName);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m_EntityLogic.OnInit(showEntityInfo.UserData);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Entity '[{0}]{1}' OnInit with exception '{2}'.", m_Id.ToString(), m_EntityAssetName, exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体回收。
|
||||
/// </summary>
|
||||
public void OnRecycle()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_EntityLogic.OnRecycle();
|
||||
m_EntityLogic.enabled = false;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Entity '[{0}]{1}' OnRecycle with exception '{2}'.", m_Id.ToString(), m_EntityAssetName, exception.ToString());
|
||||
}
|
||||
|
||||
m_Id = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体显示。
|
||||
/// </summary>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void OnShow(object userData)
|
||||
{
|
||||
ShowEntityInfo showEntityInfo = (ShowEntityInfo)userData;
|
||||
try
|
||||
{
|
||||
m_EntityLogic.OnShow(showEntityInfo.UserData);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Entity '[{0}]{1}' OnShow with exception '{2}'.", m_Id.ToString(), m_EntityAssetName, exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体隐藏。
|
||||
/// </summary>
|
||||
/// <param name="isShutdown">是否是关闭实体管理器时触发。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void OnHide(bool isShutdown, object userData)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_EntityLogic.OnHide(isShutdown, userData);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Entity '[{0}]{1}' OnHide with exception '{2}'.", m_Id.ToString(), m_EntityAssetName, exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">附加的子实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void OnAttached(IEntity childEntity, object userData)
|
||||
{
|
||||
AttachEntityInfo attachEntityInfo = (AttachEntityInfo)userData;
|
||||
try
|
||||
{
|
||||
m_EntityLogic.OnAttached(((Entity)childEntity).Logic, attachEntityInfo.ParentTransform, attachEntityInfo.UserData);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Entity '[{0}]{1}' OnAttached with exception '{2}'.", m_Id.ToString(), m_EntityAssetName, exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体解除子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">解除的子实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void OnDetached(IEntity childEntity, object userData)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_EntityLogic.OnDetached(((Entity)childEntity).Logic, userData);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Entity '[{0}]{1}' OnDetached with exception '{2}'.", m_Id.ToString(), m_EntityAssetName, exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">被附加的父实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void OnAttachTo(IEntity parentEntity, object userData)
|
||||
{
|
||||
AttachEntityInfo attachEntityInfo = (AttachEntityInfo)userData;
|
||||
try
|
||||
{
|
||||
m_EntityLogic.OnAttachTo(((Entity)parentEntity).Logic, attachEntityInfo.ParentTransform, attachEntityInfo.UserData);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Entity '[{0}]{1}' OnAttachTo with exception '{2}'.", m_Id.ToString(), m_EntityAssetName, exception.ToString());
|
||||
}
|
||||
|
||||
MemoryPool.Release(attachEntityInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体解除子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">被解除的父实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
public void OnDetachFrom(IEntity parentEntity, object userData)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_EntityLogic.OnDetachFrom(((Entity)parentEntity).Logic, userData);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Entity '[{0}]{1}' OnDetachFrom with exception '{2}'.", m_Id.ToString(), m_EntityAssetName, exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_EntityLogic.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Entity '[{0}]{1}' OnUpdate with exception '{2}'.", m_Id.ToString(), m_EntityAssetName, exception.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 903e6994d2a2425dbb2de4a6db599fc4
|
||||
timeCreated: 1662367797
|
195
Assets/TEngine/Scripts/Runtime/Entity/Core/Entity/EntityLogic.cs
Normal file
195
Assets/TEngine/Scripts/Runtime/Entity/Core/Entity/EntityLogic.cs
Normal file
@@ -0,0 +1,195 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体逻辑基类。
|
||||
/// </summary>
|
||||
public abstract class EntityLogic : MonoBehaviour
|
||||
{
|
||||
private bool m_Available = false;
|
||||
private bool m_Visible = false;
|
||||
private Entity m_Entity = null;
|
||||
private Transform m_CachedTransform = null;
|
||||
private int m_OriginalLayer = 0;
|
||||
private Transform m_OriginalTransform = null;
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体。
|
||||
/// </summary>
|
||||
public Entity Entity
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Entity;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实体名称。
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return gameObject.name;
|
||||
}
|
||||
set
|
||||
{
|
||||
gameObject.name = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体是否可用。
|
||||
/// </summary>
|
||||
public bool Available
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Available;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实体是否可见。
|
||||
/// </summary>
|
||||
public bool Visible
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Available && m_Visible;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!m_Available)
|
||||
{
|
||||
Log.Warning("Entity '{0}' is not available.", Name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_Visible == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_Visible = value;
|
||||
InternalSetVisible(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取已缓存的 Transform。
|
||||
/// </summary>
|
||||
public Transform CachedTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_CachedTransform;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体初始化。
|
||||
/// </summary>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
protected internal virtual void OnInit(object userData)
|
||||
{
|
||||
if (m_CachedTransform == null)
|
||||
{
|
||||
m_CachedTransform = transform;
|
||||
}
|
||||
|
||||
m_Entity = GetComponent<Entity>();
|
||||
m_OriginalLayer = gameObject.layer;
|
||||
m_OriginalTransform = CachedTransform.parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体回收。
|
||||
/// </summary>
|
||||
protected internal virtual void OnRecycle()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体显示。
|
||||
/// </summary>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
protected internal virtual void OnShow(object userData)
|
||||
{
|
||||
m_Available = true;
|
||||
Visible = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体隐藏。
|
||||
/// </summary>
|
||||
/// <param name="isShutdown">是否是关闭实体管理器时触发。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
protected internal virtual void OnHide(bool isShutdown, object userData)
|
||||
{
|
||||
gameObject.SetLayerRecursively(m_OriginalLayer);
|
||||
Visible = false;
|
||||
m_Available = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">附加的子实体。</param>
|
||||
/// <param name="parentTransform">被附加父实体的位置。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
protected internal virtual void OnAttached(EntityLogic childEntity, Transform parentTransform, object userData)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体解除子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">解除的子实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
protected internal virtual void OnDetached(EntityLogic childEntity, object userData)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">被附加的父实体。</param>
|
||||
/// <param name="parentTransform">被附加父实体的位置。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
protected internal virtual void OnAttachTo(EntityLogic parentEntity, Transform parentTransform, object userData)
|
||||
{
|
||||
CachedTransform.SetParent(parentTransform);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体解除子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">被解除的父实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
protected internal virtual void OnDetachFrom(EntityLogic parentEntity, object userData)
|
||||
{
|
||||
CachedTransform.SetParent(m_OriginalTransform);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
protected internal virtual void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置实体的可见性。
|
||||
/// </summary>
|
||||
/// <param name="visible">实体的可见性。</param>
|
||||
protected virtual void InternalSetVisible(bool visible)
|
||||
{
|
||||
gameObject.SetActive(visible);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 329de04d1e564c0c93db5b8798db4805
|
||||
timeCreated: 1662367765
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6610a9afbe2b144184f6503487276c2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,361 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine.Runtime.ObjectPool;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
internal sealed partial class EntityManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体组。
|
||||
/// </summary>
|
||||
private sealed class EntityGroup : IEntityGroup
|
||||
{
|
||||
private readonly string m_Name;
|
||||
private readonly IEntityGroupHelper m_EntityGroupHelper;
|
||||
private readonly IObjectPool<EntityInstanceObject> m_InstancePool;
|
||||
private readonly LinkedList<IEntity> m_Entities;
|
||||
private LinkedListNode<IEntity> m_CachedNode;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化实体组的新实例。
|
||||
/// </summary>
|
||||
/// <param name="name">实体组名称。</param>
|
||||
/// <param name="instanceAutoReleaseInterval">实体实例对象池自动释放可释放对象的间隔秒数。</param>
|
||||
/// <param name="instanceCapacity">实体实例对象池容量。</param>
|
||||
/// <param name="instanceExpireTime">实体实例对象池对象过期秒数。</param>
|
||||
/// <param name="instancePriority">实体实例对象池的优先级。</param>
|
||||
/// <param name="entityGroupHelper">实体组辅助器。</param>
|
||||
/// <param name="objectPoolManager">对象池管理器。</param>
|
||||
public EntityGroup(string name, float instanceAutoReleaseInterval, int instanceCapacity,
|
||||
float instanceExpireTime, int instancePriority, IEntityGroupHelper entityGroupHelper,
|
||||
IObjectPoolManager objectPoolManager)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception("Entity group name is invalid.");
|
||||
}
|
||||
|
||||
if (entityGroupHelper == null)
|
||||
{
|
||||
throw new Exception("Entity group helper is invalid.");
|
||||
}
|
||||
|
||||
m_Name = name;
|
||||
m_EntityGroupHelper = entityGroupHelper;
|
||||
m_InstancePool = objectPoolManager.CreateSingleSpawnObjectPool<EntityInstanceObject>(
|
||||
Utility.Text.Format("Entity Instance Pool ({0})", name), instanceCapacity, instanceExpireTime,
|
||||
instancePriority);
|
||||
m_InstancePool.AutoReleaseInterval = instanceAutoReleaseInterval;
|
||||
m_Entities = new LinkedList<IEntity>();
|
||||
m_CachedNode = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体组名称。
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return m_Name; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体组中实体数量。
|
||||
/// </summary>
|
||||
public int EntityCount
|
||||
{
|
||||
get { return m_Entities.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实体组实例对象池自动释放可释放对象的间隔秒数。
|
||||
/// </summary>
|
||||
public float InstanceAutoReleaseInterval
|
||||
{
|
||||
get { return m_InstancePool.AutoReleaseInterval; }
|
||||
set { m_InstancePool.AutoReleaseInterval = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实体组实例对象池的容量。
|
||||
/// </summary>
|
||||
public int InstanceCapacity
|
||||
{
|
||||
get { return m_InstancePool.Capacity; }
|
||||
set { m_InstancePool.Capacity = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实体组实例对象池对象过期秒数。
|
||||
/// </summary>
|
||||
public float InstanceExpireTime
|
||||
{
|
||||
get { return m_InstancePool.ExpireTime; }
|
||||
set { m_InstancePool.ExpireTime = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实体组实例对象池的优先级。
|
||||
/// </summary>
|
||||
public int InstancePriority
|
||||
{
|
||||
get { return m_InstancePool.Priority; }
|
||||
set { m_InstancePool.Priority = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体组辅助器。
|
||||
/// </summary>
|
||||
public IEntityGroupHelper Helper
|
||||
{
|
||||
get { return m_EntityGroupHelper; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体组轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
public void Update(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
LinkedListNode<IEntity> current = m_Entities.First;
|
||||
while (current != null)
|
||||
{
|
||||
m_CachedNode = current.Next;
|
||||
current.Value.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
current = m_CachedNode;
|
||||
m_CachedNode = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体组中是否存在实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体序列编号。</param>
|
||||
/// <returns>实体组中是否存在实体。</returns>
|
||||
public bool HasEntity(int entityId)
|
||||
{
|
||||
foreach (IEntity entity in m_Entities)
|
||||
{
|
||||
if (entity.Id == entityId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体组中是否存在实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <returns>实体组中是否存在实体。</returns>
|
||||
public bool HasEntity(string entityAssetName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(entityAssetName))
|
||||
{
|
||||
throw new Exception("Entity asset name is invalid.");
|
||||
}
|
||||
|
||||
foreach (IEntity entity in m_Entities)
|
||||
{
|
||||
if (entity.EntityAssetName == entityAssetName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体序列编号。</param>
|
||||
/// <returns>要获取的实体。</returns>
|
||||
public IEntity GetEntity(int entityId)
|
||||
{
|
||||
foreach (IEntity entity in m_Entities)
|
||||
{
|
||||
if (entity.Id == entityId)
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <returns>要获取的实体。</returns>
|
||||
public IEntity GetEntity(string entityAssetName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(entityAssetName))
|
||||
{
|
||||
throw new Exception("Entity asset name is invalid.");
|
||||
}
|
||||
|
||||
foreach (IEntity entity in m_Entities)
|
||||
{
|
||||
if (entity.EntityAssetName == entityAssetName)
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <returns>要获取的实体。</returns>
|
||||
public IEntity[] GetEntities(string entityAssetName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(entityAssetName))
|
||||
{
|
||||
throw new Exception("Entity asset name is invalid.");
|
||||
}
|
||||
|
||||
List<IEntity> results = new List<IEntity>();
|
||||
foreach (IEntity entity in m_Entities)
|
||||
{
|
||||
if (entity.EntityAssetName == entityAssetName)
|
||||
{
|
||||
results.Add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <param name="results">要获取的实体。</param>
|
||||
public void GetEntities(string entityAssetName, List<IEntity> results)
|
||||
{
|
||||
if (string.IsNullOrEmpty(entityAssetName))
|
||||
{
|
||||
throw new Exception("Entity asset name is invalid.");
|
||||
}
|
||||
|
||||
if (results == null)
|
||||
{
|
||||
throw new Exception("Results is invalid.");
|
||||
}
|
||||
|
||||
results.Clear();
|
||||
foreach (IEntity entity in m_Entities)
|
||||
{
|
||||
if (entity.EntityAssetName == entityAssetName)
|
||||
{
|
||||
results.Add(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取所有实体。
|
||||
/// </summary>
|
||||
/// <returns>实体组中的所有实体。</returns>
|
||||
public IEntity[] GetAllEntities()
|
||||
{
|
||||
List<IEntity> results = new List<IEntity>();
|
||||
foreach (IEntity entity in m_Entities)
|
||||
{
|
||||
results.Add(entity);
|
||||
}
|
||||
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取所有实体。
|
||||
/// </summary>
|
||||
/// <param name="results">实体组中的所有实体。</param>
|
||||
public void GetAllEntities(List<IEntity> results)
|
||||
{
|
||||
if (results == null)
|
||||
{
|
||||
throw new Exception("Results is invalid.");
|
||||
}
|
||||
|
||||
results.Clear();
|
||||
foreach (IEntity entity in m_Entities)
|
||||
{
|
||||
results.Add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 往实体组增加实体。
|
||||
/// </summary>
|
||||
/// <param name="entity">要增加的实体。</param>
|
||||
public void AddEntity(IEntity entity)
|
||||
{
|
||||
m_Entities.AddLast(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组移除实体。
|
||||
/// </summary>
|
||||
/// <param name="entity">要移除的实体。</param>
|
||||
public void RemoveEntity(IEntity entity)
|
||||
{
|
||||
if (m_CachedNode != null && m_CachedNode.Value == entity)
|
||||
{
|
||||
m_CachedNode = m_CachedNode.Next;
|
||||
}
|
||||
|
||||
if (!m_Entities.Remove(entity))
|
||||
{
|
||||
throw new Exception(Utility.Text.Format(
|
||||
"Entity group '{0}' not exists specified entity '[{1}]{2}'.", m_Name, entity.Id,
|
||||
entity.EntityAssetName));
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterEntityInstanceObject(EntityInstanceObject obj, bool spawned)
|
||||
{
|
||||
m_InstancePool.Register(obj, spawned);
|
||||
}
|
||||
|
||||
public EntityInstanceObject SpawnEntityInstanceObject(string name)
|
||||
{
|
||||
return m_InstancePool.Spawn(name);
|
||||
}
|
||||
|
||||
public void UnspawnEntity(IEntity entity)
|
||||
{
|
||||
m_InstancePool.Unspawn(entity.Handle);
|
||||
}
|
||||
|
||||
public void SetEntityInstanceLocked(object entityInstance, bool locked)
|
||||
{
|
||||
if (entityInstance == null)
|
||||
{
|
||||
throw new Exception("Entity instance is invalid.");
|
||||
}
|
||||
|
||||
m_InstancePool.SetLocked(entityInstance, locked);
|
||||
}
|
||||
|
||||
public void SetEntityInstancePriority(object entityInstance, int priority)
|
||||
{
|
||||
if (entityInstance == null)
|
||||
{
|
||||
throw new Exception("Entity instance is invalid.");
|
||||
}
|
||||
|
||||
m_InstancePool.SetPriority(entityInstance, priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1c60ef7d4f16f04891e04a86c657264
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
internal sealed partial class EntityManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体信息。
|
||||
/// </summary>
|
||||
private sealed class EntityInfo : IMemory
|
||||
{
|
||||
private IEntity m_Entity;
|
||||
private EntityStatus m_Status;
|
||||
private IEntity m_ParentEntity;
|
||||
private List<IEntity> m_ChildEntities;
|
||||
|
||||
public EntityInfo()
|
||||
{
|
||||
m_Entity = null;
|
||||
m_Status = EntityStatus.Unknown;
|
||||
m_ParentEntity = null;
|
||||
m_ChildEntities = new List<IEntity>();
|
||||
}
|
||||
|
||||
public IEntity Entity
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Entity;
|
||||
}
|
||||
}
|
||||
|
||||
public EntityStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Status;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_Status = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IEntity ParentEntity
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ParentEntity;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_ParentEntity = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int ChildEntityCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_ChildEntities.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public static EntityInfo Create(IEntity entity)
|
||||
{
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception("Entity is invalid.");
|
||||
}
|
||||
|
||||
EntityInfo entityInfo = MemoryPool.Acquire<EntityInfo>();
|
||||
entityInfo.m_Entity = entity;
|
||||
entityInfo.m_Status = EntityStatus.WillInit;
|
||||
return entityInfo;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_Entity = null;
|
||||
m_Status = EntityStatus.Unknown;
|
||||
m_ParentEntity = null;
|
||||
m_ChildEntities.Clear();
|
||||
}
|
||||
|
||||
public IEntity GetChildEntity()
|
||||
{
|
||||
return m_ChildEntities.Count > 0 ? m_ChildEntities[0] : null;
|
||||
}
|
||||
|
||||
public IEntity[] GetChildEntities()
|
||||
{
|
||||
return m_ChildEntities.ToArray();
|
||||
}
|
||||
|
||||
public void GetChildEntities(List<IEntity> results)
|
||||
{
|
||||
if (results == null)
|
||||
{
|
||||
throw new Exception("Results is invalid.");
|
||||
}
|
||||
|
||||
results.Clear();
|
||||
foreach (IEntity childEntity in m_ChildEntities)
|
||||
{
|
||||
results.Add(childEntity);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddChildEntity(IEntity childEntity)
|
||||
{
|
||||
if (m_ChildEntities.Contains(childEntity))
|
||||
{
|
||||
throw new Exception("Can not add child entity which is already exist.");
|
||||
}
|
||||
|
||||
m_ChildEntities.Add(childEntity);
|
||||
}
|
||||
|
||||
public void RemoveChildEntity(IEntity childEntity)
|
||||
{
|
||||
if (!m_ChildEntities.Remove(childEntity))
|
||||
{
|
||||
throw new Exception("Can not remove child entity which is not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5adfe04298f84665915103f3b7570e4d
|
||||
timeCreated: 1662358455
|
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using TEngine.Runtime.ObjectPool;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
internal sealed partial class EntityManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体实例对象。
|
||||
/// </summary>
|
||||
private sealed class EntityInstanceObject : ObjectBase
|
||||
{
|
||||
private object m_EntityAsset;
|
||||
private IEntityHelper m_EntityHelper;
|
||||
|
||||
public EntityInstanceObject()
|
||||
{
|
||||
m_EntityAsset = null;
|
||||
m_EntityHelper = null;
|
||||
}
|
||||
|
||||
public static EntityInstanceObject Create(string name, object entityAsset, object entityInstance, IEntityHelper entityHelper)
|
||||
{
|
||||
if (entityAsset == null)
|
||||
{
|
||||
throw new Exception("Entity asset is invalid.");
|
||||
}
|
||||
|
||||
if (entityHelper == null)
|
||||
{
|
||||
throw new Exception("Entity helper is invalid.");
|
||||
}
|
||||
|
||||
EntityInstanceObject entityInstanceObject = MemoryPool.Acquire<EntityInstanceObject>();
|
||||
entityInstanceObject.Initialize(name, entityInstance);
|
||||
entityInstanceObject.m_EntityAsset = entityAsset;
|
||||
entityInstanceObject.m_EntityHelper = entityHelper;
|
||||
return entityInstanceObject;
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
m_EntityAsset = null;
|
||||
m_EntityHelper = null;
|
||||
}
|
||||
|
||||
protected internal override void Release(bool isShutdown)
|
||||
{
|
||||
m_EntityHelper.ReleaseEntity(m_EntityAsset, Target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da6cc3aa119f9204382ef80b4fe5a9fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,21 @@
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
internal sealed partial class EntityManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体状态。
|
||||
/// </summary>
|
||||
private enum EntityStatus : byte
|
||||
{
|
||||
Unknown = 0,
|
||||
WillInit,
|
||||
Inited,
|
||||
WillShow,
|
||||
Showed,
|
||||
WillHide,
|
||||
Hidden,
|
||||
WillRecycle,
|
||||
Recycled
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 870878f06eb048a6b3be7129c316cbd8
|
||||
timeCreated: 1662358523
|
@@ -0,0 +1,59 @@
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
internal sealed partial class EntityManager
|
||||
{
|
||||
private sealed class ShowEntityInfo : IMemory
|
||||
{
|
||||
private int m_SerialId;
|
||||
private int m_EntityId;
|
||||
private EntityGroup m_EntityGroup;
|
||||
private object m_UserData;
|
||||
|
||||
public ShowEntityInfo()
|
||||
{
|
||||
m_SerialId = 0;
|
||||
m_EntityId = 0;
|
||||
m_EntityGroup = null;
|
||||
m_UserData = null;
|
||||
}
|
||||
|
||||
public int SerialId
|
||||
{
|
||||
get { return m_SerialId; }
|
||||
}
|
||||
|
||||
public int EntityId
|
||||
{
|
||||
get { return m_EntityId; }
|
||||
}
|
||||
|
||||
public EntityGroup EntityGroup
|
||||
{
|
||||
get { return m_EntityGroup; }
|
||||
}
|
||||
|
||||
public object UserData
|
||||
{
|
||||
get { return m_UserData; }
|
||||
}
|
||||
|
||||
public static ShowEntityInfo Create(int serialId, int entityId, EntityGroup entityGroup, object userData)
|
||||
{
|
||||
ShowEntityInfo showEntityInfo = MemoryPool.Acquire<ShowEntityInfo>();
|
||||
showEntityInfo.m_SerialId = serialId;
|
||||
showEntityInfo.m_EntityId = entityId;
|
||||
showEntityInfo.m_EntityGroup = entityGroup;
|
||||
showEntityInfo.m_UserData = userData;
|
||||
return showEntityInfo;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_SerialId = 0;
|
||||
m_EntityId = 0;
|
||||
m_EntityGroup = null;
|
||||
m_UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a4dce96f95bd01438468b6ad9cef7f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0a1321b9ce04887a06a1c0dcec06269
|
||||
timeCreated: 1662358334
|
8
Assets/TEngine/Scripts/Runtime/Entity/Core/Helper.meta
Normal file
8
Assets/TEngine/Scripts/Runtime/Entity/Core/Helper.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fbd6ae736ae43794d84817469577cd4b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体组辅助器基类。
|
||||
/// </summary>
|
||||
public abstract class EntityGroupHelperBase : MonoBehaviour, IEntityGroupHelper
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc047b6e51dd7ef4991643ff2142afcd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体辅助器基类。
|
||||
/// </summary>
|
||||
public abstract class EntityHelperBase : MonoBehaviour, IEntityHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 实例化实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAsset">要实例化的实体资源。</param>
|
||||
/// <returns>实例化后的实体。</returns>
|
||||
public abstract object InstantiateEntity(object entityAsset);
|
||||
|
||||
/// <summary>
|
||||
/// 创建实体。
|
||||
/// </summary>
|
||||
/// <param name="entityInstance">实体实例。</param>
|
||||
/// <param name="entityGroup">实体所属的实体组。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>实体。</returns>
|
||||
public abstract IEntity CreateEntity(object entityInstance, IEntityGroup entityGroup, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 释放实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAsset">要释放的实体资源。</param>
|
||||
/// <param name="entityInstance">要释放的实体实例。</param>
|
||||
public abstract void ReleaseEntity(object entityAsset, object entityInstance);
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3afe009e65b14bfbb07b98f3c033c740
|
||||
timeCreated: 1662367200
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5ed11bdb1bb4113bb3b499775670817
|
||||
timeCreated: 1662358264
|
103
Assets/TEngine/Scripts/Runtime/Entity/Core/Interface/IEntity.cs
Normal file
103
Assets/TEngine/Scripts/Runtime/Entity/Core/Interface/IEntity.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体接口。
|
||||
/// </summary>
|
||||
public interface IEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取实体编号。
|
||||
/// </summary>
|
||||
int Id
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体资源名称。
|
||||
/// </summary>
|
||||
string EntityAssetName
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体实例。
|
||||
/// </summary>
|
||||
object Handle
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体所属的实体组。
|
||||
/// </summary>
|
||||
IEntityGroup EntityGroup
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体初始化。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <param name="entityGroup">实体所属的实体组。</param>
|
||||
/// <param name="isNewInstance">是否是新实例。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void OnInit(int entityId, string entityAssetName, IEntityGroup entityGroup, bool isNewInstance, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 实体回收。
|
||||
/// </summary>
|
||||
void OnRecycle();
|
||||
|
||||
/// <summary>
|
||||
/// 实体显示。
|
||||
/// </summary>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void OnShow(object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 实体隐藏。
|
||||
/// </summary>
|
||||
/// <param name="isShutdown">是否是关闭实体管理器时触发。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void OnHide(bool isShutdown, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 实体附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">附加的子实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void OnAttached(IEntity childEntity, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 实体解除子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">解除的子实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void OnDetached(IEntity childEntity, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 实体附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">被附加的父实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void OnAttachTo(IEntity parentEntity, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 实体解除子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">被解除的父实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void OnDetachFrom(IEntity parentEntity, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 实体轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
void OnUpdate(float elapseSeconds, float realElapseSeconds);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e277c35f794ac274ca4b108ee863f8b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,113 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体组接口。
|
||||
/// </summary>
|
||||
public interface IEntityGroup
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取实体组名称。
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体组中实体数量。
|
||||
/// </summary>
|
||||
int EntityCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实体组实例对象池自动释放可释放对象的间隔秒数。
|
||||
/// </summary>
|
||||
float InstanceAutoReleaseInterval { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实体组实例对象池的容量。
|
||||
/// </summary>
|
||||
int InstanceCapacity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实体组实例对象池对象过期秒数。
|
||||
/// </summary>
|
||||
float InstanceExpireTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置实体组实例对象池的优先级。
|
||||
/// </summary>
|
||||
int InstancePriority { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体组辅助器。
|
||||
/// </summary>
|
||||
IEntityGroupHelper Helper { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 实体组中是否存在实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体序列编号。</param>
|
||||
/// <returns>实体组中是否存在实体。</returns>
|
||||
bool HasEntity(int entityId);
|
||||
|
||||
/// <summary>
|
||||
/// 实体组中是否存在实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <returns>实体组中是否存在实体。</returns>
|
||||
bool HasEntity(string entityAssetName);
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体序列编号。</param>
|
||||
/// <returns>要获取的实体。</returns>
|
||||
IEntity GetEntity(int entityId);
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <returns>要获取的实体。</returns>
|
||||
IEntity GetEntity(string entityAssetName);
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <returns>要获取的实体。</returns>
|
||||
IEntity[] GetEntities(string entityAssetName);
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <param name="results">要获取的实体。</param>
|
||||
void GetEntities(string entityAssetName, List<IEntity> results);
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取所有实体。
|
||||
/// </summary>
|
||||
/// <returns>实体组中的所有实体。</returns>
|
||||
IEntity[] GetAllEntities();
|
||||
|
||||
/// <summary>
|
||||
/// 从实体组中获取所有实体。
|
||||
/// </summary>
|
||||
/// <param name="results">实体组中的所有实体。</param>
|
||||
void GetAllEntities(List<IEntity> results);
|
||||
|
||||
/// <summary>
|
||||
/// 设置实体实例是否被加锁。
|
||||
/// </summary>
|
||||
/// <param name="entityInstance">实体实例。</param>
|
||||
/// <param name="locked">实体实例是否被加锁。</param>
|
||||
void SetEntityInstanceLocked(object entityInstance, bool locked);
|
||||
|
||||
/// <summary>
|
||||
/// 设置实体实例的优先级。
|
||||
/// </summary>
|
||||
/// <param name="entityInstance">实体实例。</param>
|
||||
/// <param name="priority">实体实例优先级。</param>
|
||||
void SetEntityInstancePriority(object entityInstance, int priority);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e08cae97715f4184595d43d984e4678b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,7 @@
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
public interface IEntityGroupHelper
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93a0420819e041d88ad86f4a337525af
|
||||
timeCreated: 1662358160
|
@@ -0,0 +1,31 @@
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体辅助器接口。
|
||||
/// </summary>
|
||||
public interface IEntityHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 实例化实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAsset">要实例化的实体资源。</param>
|
||||
/// <returns>实例化后的实体。</returns>
|
||||
object InstantiateEntity(object entityAsset);
|
||||
|
||||
/// <summary>
|
||||
/// 创建实体。
|
||||
/// </summary>
|
||||
/// <param name="entityInstance">实体实例。</param>
|
||||
/// <param name="entityGroup">实体所属的实体组。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>实体。</returns>
|
||||
IEntity CreateEntity(object entityInstance, IEntityGroup entityGroup, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 释放实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAsset">要释放的实体资源。</param>
|
||||
/// <param name="entityInstance">要释放的实体实例。</param>
|
||||
void ReleaseEntity(object entityAsset, object entityInstance);
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5afe8f7284924202b37194d224d25300
|
||||
timeCreated: 1662358246
|
@@ -0,0 +1,443 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TEngine.Runtime.ObjectPool;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体管理器接口。
|
||||
/// </summary>
|
||||
public interface IEntityManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取实体数量。
|
||||
/// </summary>
|
||||
int EntityCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体组数量。
|
||||
/// </summary>
|
||||
int EntityGroupCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 显示实体成功事件。
|
||||
/// </summary>
|
||||
event Action<IEntity, float, object> ShowEntitySuccess;
|
||||
|
||||
/// <summary>
|
||||
/// 显示实体失败事件。
|
||||
/// </summary>
|
||||
event Action<int, string, string, string, object> ShowEntityFailure;
|
||||
|
||||
/// <summary>
|
||||
/// 显示实体更新事件。
|
||||
/// </summary>
|
||||
event Action<int, string, string, float, object> ShowEntityUpdate;
|
||||
|
||||
/// <summary>
|
||||
/// 显示实体时加载依赖资源事件。
|
||||
/// </summary>
|
||||
event Action<int, string, string, string, int, int, object> ShowEntityDependencyAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏实体完成事件。
|
||||
/// </summary>
|
||||
event Action<int, string, IEntityGroup, object> HideEntityComplete;
|
||||
|
||||
/// <summary>
|
||||
/// 设置对象池管理器。
|
||||
/// </summary>
|
||||
/// <param name="objectPoolManager">对象池管理器。</param>
|
||||
void SetObjectPoolManager(IObjectPoolManager objectPoolManager);
|
||||
|
||||
/// <summary>
|
||||
/// 设置实体辅助器。
|
||||
/// </summary>
|
||||
/// <param name="entityHelper">实体辅助器。</param>
|
||||
void SetEntityHelper(IEntityHelper entityHelper);
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在实体组。
|
||||
/// </summary>
|
||||
/// <param name="entityGroupName">实体组名称。</param>
|
||||
/// <returns>是否存在实体组。</returns>
|
||||
bool HasEntityGroup(string entityGroupName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体组。
|
||||
/// </summary>
|
||||
/// <param name="entityGroupName">实体组名称。</param>
|
||||
/// <returns>要获取的实体组。</returns>
|
||||
IEntityGroup GetEntityGroup(string entityGroupName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有实体组。
|
||||
/// </summary>
|
||||
/// <returns>所有实体组。</returns>
|
||||
IEntityGroup[] GetAllEntityGroups();
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有实体组。
|
||||
/// </summary>
|
||||
/// <param name="results">所有实体组。</param>
|
||||
void GetAllEntityGroups(List<IEntityGroup> results);
|
||||
|
||||
/// <summary>
|
||||
/// 增加实体组。
|
||||
/// </summary>
|
||||
/// <param name="entityGroupName">实体组名称。</param>
|
||||
/// <param name="instanceAutoReleaseInterval">实体实例对象池自动释放可释放对象的间隔秒数。</param>
|
||||
/// <param name="instanceCapacity">实体实例对象池容量。</param>
|
||||
/// <param name="instanceExpireTime">实体实例对象池对象过期秒数。</param>
|
||||
/// <param name="instancePriority">实体实例对象池的优先级。</param>
|
||||
/// <param name="entityGroupHelper">实体组辅助器。</param>
|
||||
/// <returns>是否增加实体组成功。</returns>
|
||||
bool AddEntityGroup(string entityGroupName, float instanceAutoReleaseInterval, int instanceCapacity,
|
||||
float instanceExpireTime, int instancePriority, IEntityGroupHelper entityGroupHelper);
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
/// <returns>是否存在实体。</returns>
|
||||
bool HasEntity(int entityId);
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <returns>是否存在实体。</returns>
|
||||
bool HasEntity(string entityAssetName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
/// <returns>要获取的实体。</returns>
|
||||
IEntity GetEntity(int entityId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <returns>要获取的实体。</returns>
|
||||
IEntity GetEntity(string entityAssetName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <returns>要获取的实体。</returns>
|
||||
IEntity[] GetEntities(string entityAssetName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <param name="results">要获取的实体。</param>
|
||||
void GetEntities(string entityAssetName, List<IEntity> results);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有已加载的实体。
|
||||
/// </summary>
|
||||
/// <returns>所有已加载的实体。</returns>
|
||||
IEntity[] GetAllLoadedEntities();
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有已加载的实体。
|
||||
/// </summary>
|
||||
/// <param name="results">所有已加载的实体。</param>
|
||||
void GetAllLoadedEntities(List<IEntity> results);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有正在加载实体的编号。
|
||||
/// </summary>
|
||||
/// <returns>所有正在加载实体的编号。</returns>
|
||||
int[] GetAllLoadingEntityIds();
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有正在加载实体的编号。
|
||||
/// </summary>
|
||||
/// <param name="results">所有正在加载实体的编号。</param>
|
||||
void GetAllLoadingEntityIds(List<int> results);
|
||||
|
||||
/// <summary>
|
||||
/// 是否正在加载实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
/// <returns>是否正在加载实体。</returns>
|
||||
bool IsLoadingEntity(int entityId);
|
||||
|
||||
/// <summary>
|
||||
/// 是否是合法的实体。
|
||||
/// </summary>
|
||||
/// <param name="entity">实体。</param>
|
||||
/// <returns>实体是否合法。</returns>
|
||||
bool IsValidEntity(IEntity entity);
|
||||
|
||||
/// <summary>
|
||||
/// 显示实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <param name="entityGroupName">实体组名称。</param>
|
||||
void ShowEntity(int entityId, string entityAssetName, string entityGroupName);
|
||||
|
||||
/// <summary>
|
||||
/// 显示实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <param name="entityGroupName">实体组名称。</param>
|
||||
/// <param name="priority">加载实体资源的优先级。</param>
|
||||
void ShowEntity(int entityId, string entityAssetName, string entityGroupName, int priority);
|
||||
|
||||
/// <summary>
|
||||
/// 显示实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <param name="entityGroupName">实体组名称。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void ShowEntity(int entityId, string entityAssetName, string entityGroupName, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 显示实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
/// <param name="entityAssetName">实体资源名称。</param>
|
||||
/// <param name="entityGroupName">实体组名称。</param>
|
||||
/// <param name="priority">加载实体资源的优先级。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void ShowEntity(int entityId, string entityAssetName, string entityGroupName, int priority, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
void HideEntity(int entityId);
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏实体。
|
||||
/// </summary>
|
||||
/// <param name="entityId">实体编号。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void HideEntity(int entityId, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏实体。
|
||||
/// </summary>
|
||||
/// <param name="entity">实体。</param>
|
||||
void HideEntity(IEntity entity);
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏实体。
|
||||
/// </summary>
|
||||
/// <param name="entity">实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void HideEntity(IEntity entity, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏所有已加载的实体。
|
||||
/// </summary>
|
||||
void HideAllLoadedEntities();
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏所有已加载的实体。
|
||||
/// </summary>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void HideAllLoadedEntities(object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏所有正在加载的实体。
|
||||
/// </summary>
|
||||
void HideAllLoadingEntities();
|
||||
|
||||
/// <summary>
|
||||
/// 获取父实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntityId">要获取父实体的子实体的实体编号。</param>
|
||||
/// <returns>子实体的父实体。</returns>
|
||||
IEntity GetParentEntity(int childEntityId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取父实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">要获取父实体的子实体。</param>
|
||||
/// <returns>子实体的父实体。</returns>
|
||||
IEntity GetParentEntity(IEntity childEntity);
|
||||
|
||||
/// <summary>
|
||||
/// 获取子实体数量。
|
||||
/// </summary>
|
||||
/// <param name="parentEntityId">要获取子实体数量的父实体的实体编号。</param>
|
||||
/// <returns>子实体数量。</returns>
|
||||
int GetChildEntityCount(int parentEntityId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntityId">要获取子实体的父实体的实体编号。</param>
|
||||
/// <returns>子实体。</returns>
|
||||
IEntity GetChildEntity(int parentEntityId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">要获取子实体的父实体。</param>
|
||||
/// <returns>子实体。</returns>
|
||||
IEntity GetChildEntity(IEntity parentEntity);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntityId">要获取所有子实体的父实体的实体编号。</param>
|
||||
/// <returns>所有子实体。</returns>
|
||||
IEntity[] GetChildEntities(int parentEntityId);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntityId">要获取所有子实体的父实体的实体编号。</param>
|
||||
/// <param name="results">所有子实体。</param>
|
||||
void GetChildEntities(int parentEntityId, List<IEntity> results);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">要获取所有子实体的父实体。</param>
|
||||
/// <returns>所有子实体。</returns>
|
||||
IEntity[] GetChildEntities(IEntity parentEntity);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">要获取所有子实体的父实体。</param>
|
||||
/// <param name="results">所有子实体。</param>
|
||||
void GetChildEntities(IEntity parentEntity, List<IEntity> results);
|
||||
|
||||
/// <summary>
|
||||
/// 附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntityId">要附加的子实体的实体编号。</param>
|
||||
/// <param name="parentEntityId">被附加的父实体的实体编号。</param>
|
||||
void AttachEntity(int childEntityId, int parentEntityId);
|
||||
|
||||
/// <summary>
|
||||
/// 附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntityId">要附加的子实体的实体编号。</param>
|
||||
/// <param name="parentEntityId">被附加的父实体的实体编号。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void AttachEntity(int childEntityId, int parentEntityId, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntityId">要附加的子实体的实体编号。</param>
|
||||
/// <param name="parentEntity">被附加的父实体。</param>
|
||||
void AttachEntity(int childEntityId, IEntity parentEntity);
|
||||
|
||||
/// <summary>
|
||||
/// 附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntityId">要附加的子实体的实体编号。</param>
|
||||
/// <param name="parentEntity">被附加的父实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void AttachEntity(int childEntityId, IEntity parentEntity, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">要附加的子实体。</param>
|
||||
/// <param name="parentEntityId">被附加的父实体的实体编号。</param>
|
||||
void AttachEntity(IEntity childEntity, int parentEntityId);
|
||||
|
||||
/// <summary>
|
||||
/// 附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">要附加的子实体。</param>
|
||||
/// <param name="parentEntityId">被附加的父实体的实体编号。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void AttachEntity(IEntity childEntity, int parentEntityId, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">要附加的子实体。</param>
|
||||
/// <param name="parentEntity">被附加的父实体。</param>
|
||||
void AttachEntity(IEntity childEntity, IEntity parentEntity);
|
||||
|
||||
/// <summary>
|
||||
/// 附加子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">要附加的子实体。</param>
|
||||
/// <param name="parentEntity">被附加的父实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void AttachEntity(IEntity childEntity, IEntity parentEntity, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 解除子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntityId">要解除的子实体的实体编号。</param>
|
||||
void DetachEntity(int childEntityId);
|
||||
|
||||
/// <summary>
|
||||
/// 解除子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntityId">要解除的子实体的实体编号。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void DetachEntity(int childEntityId, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 解除子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">要解除的子实体。</param>
|
||||
void DetachEntity(IEntity childEntity);
|
||||
|
||||
/// <summary>
|
||||
/// 解除子实体。
|
||||
/// </summary>
|
||||
/// <param name="childEntity">要解除的子实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void DetachEntity(IEntity childEntity, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 解除所有子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntityId">被解除的父实体的实体编号。</param>
|
||||
void DetachChildEntities(int parentEntityId);
|
||||
|
||||
/// <summary>
|
||||
/// 解除所有子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntityId">被解除的父实体的实体编号。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void DetachChildEntities(int parentEntityId, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 解除所有子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">被解除的父实体。</param>
|
||||
void DetachChildEntities(IEntity parentEntity);
|
||||
|
||||
/// <summary>
|
||||
/// 解除所有子实体。
|
||||
/// </summary>
|
||||
/// <param name="parentEntity">被解除的父实体。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
void DetachChildEntities(IEntity parentEntity, object userData);
|
||||
|
||||
/// <summary>
|
||||
/// 实体管理器轮询。
|
||||
/// </summary>
|
||||
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
|
||||
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
|
||||
void Update(float elapseSeconds, float realElapseSeconds);
|
||||
|
||||
/// <summary>
|
||||
/// 关闭并清理实体管理器。
|
||||
/// </summary>
|
||||
void ShutDown();
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9deb38cdf5564cc9990eceff01f894d9
|
||||
timeCreated: 1662358217
|
40
Assets/TEngine/Scripts/Runtime/Entity/Core/ShowEntityInfo.cs
Normal file
40
Assets/TEngine/Scripts/Runtime/Entity/Core/ShowEntityInfo.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
internal sealed class ShowEntityInfo : IMemory
|
||||
{
|
||||
private Type m_EntityLogicType;
|
||||
private object m_UserData;
|
||||
|
||||
public ShowEntityInfo()
|
||||
{
|
||||
m_EntityLogicType = null;
|
||||
m_UserData = null;
|
||||
}
|
||||
|
||||
public Type EntityLogicType
|
||||
{
|
||||
get { return m_EntityLogicType; }
|
||||
}
|
||||
|
||||
public object UserData
|
||||
{
|
||||
get { return m_UserData; }
|
||||
}
|
||||
|
||||
public static ShowEntityInfo Create(Type entityLogicType, object userData)
|
||||
{
|
||||
ShowEntityInfo showEntityInfo = MemoryPool.Acquire<ShowEntityInfo>();
|
||||
showEntityInfo.m_EntityLogicType = entityLogicType;
|
||||
showEntityInfo.m_UserData = userData;
|
||||
return showEntityInfo;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_EntityLogicType = null;
|
||||
m_UserData = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea3881241f5746719af12b872f51d7f8
|
||||
timeCreated: 1662367905
|
@@ -0,0 +1,9 @@
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认实体组辅助器。
|
||||
/// </summary>
|
||||
public class DefaultEntityGroupHelper : EntityGroupHelperBase
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96fc5bb7ba6933342a0b5b54bd358b59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
52
Assets/TEngine/Scripts/Runtime/Entity/DefaultEntityHelper.cs
Normal file
52
Assets/TEngine/Scripts/Runtime/Entity/DefaultEntityHelper.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认实体辅助器。
|
||||
/// </summary>
|
||||
public class DefaultEntityHelper : EntityHelperBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 实例化实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAsset">要实例化的实体资源。</param>
|
||||
/// <returns>实例化后的实体。</returns>
|
||||
public override object InstantiateEntity(object entityAsset)
|
||||
{
|
||||
return Instantiate((Object)entityAsset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建实体。
|
||||
/// </summary>
|
||||
/// <param name="entityInstance">实体实例。</param>
|
||||
/// <param name="entityGroup">实体所属的实体组。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>实体。</returns>
|
||||
public override IEntity CreateEntity(object entityInstance, IEntityGroup entityGroup, object userData)
|
||||
{
|
||||
GameObject gameObject = entityInstance as GameObject;
|
||||
if (gameObject == null)
|
||||
{
|
||||
Log.Error("Entity instance is invalid.");
|
||||
return null;
|
||||
}
|
||||
|
||||
Transform transform = gameObject.transform;
|
||||
transform.SetParent(((MonoBehaviour)entityGroup.Helper).transform);
|
||||
|
||||
return gameObject.GetOrAddComponent<Entity>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放实体。
|
||||
/// </summary>
|
||||
/// <param name="entityAsset">要释放的实体资源。</param>
|
||||
/// <param name="entityInstance">要释放的实体实例。</param>
|
||||
public override void ReleaseEntity(object entityAsset, object entityInstance)
|
||||
{
|
||||
Destroy((Object)entityInstance);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d984472e4ffc461998251d10ac639577
|
||||
timeCreated: 1662368182
|
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
public sealed partial class EntityComponent
|
||||
{
|
||||
[Serializable]
|
||||
private sealed class EntityGroup
|
||||
{
|
||||
[SerializeField] private string m_Name = null;
|
||||
|
||||
[SerializeField] private float m_InstanceAutoReleaseInterval = 60f;
|
||||
|
||||
[SerializeField] private int m_InstanceCapacity = 16;
|
||||
|
||||
[SerializeField] private float m_InstanceExpireTime = 60f;
|
||||
|
||||
[SerializeField] private int m_InstancePriority = 0;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_Name; }
|
||||
}
|
||||
|
||||
public float InstanceAutoReleaseInterval
|
||||
{
|
||||
get { return m_InstanceAutoReleaseInterval; }
|
||||
}
|
||||
|
||||
public int InstanceCapacity
|
||||
{
|
||||
get { return m_InstanceCapacity; }
|
||||
}
|
||||
|
||||
public float InstanceExpireTime
|
||||
{
|
||||
get { return m_InstanceExpireTime; }
|
||||
}
|
||||
|
||||
public int InstancePriority
|
||||
{
|
||||
get { return m_InstancePriority; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c0f66a106324c0ca6deff08e55f3777
|
||||
timeCreated: 1662368917
|
1166
Assets/TEngine/Scripts/Runtime/Entity/EntityComponent.cs
Normal file
1166
Assets/TEngine/Scripts/Runtime/Entity/EntityComponent.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc62b60a444ff0c4a952566cb2ecd2fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
12
Assets/TEngine/Scripts/Runtime/Entity/EntityEvent.cs
Normal file
12
Assets/TEngine/Scripts/Runtime/Entity/EntityEvent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace TEngine.Runtime.Entity
|
||||
{
|
||||
public class EntityEvent
|
||||
{
|
||||
public static int ShowEntitySuccess = StringId.StringToHash("EntityEvent.ShowEntitySuccess");
|
||||
public static int ShowEntityFailure = StringId.StringToHash("EntityEvent.ShowEntityFailure");
|
||||
public static int ShowEntityUpdate = StringId.StringToHash("EntityEvent.ShowEntityUpdate");
|
||||
public static int ShowEntityDependency = StringId.StringToHash("EntityEvent.ShowEntityDependency");
|
||||
public static int HideEntityComplete = StringId.StringToHash("EntityEvent.HideEntityComplete");
|
||||
}
|
||||
}
|
||||
|
11
Assets/TEngine/Scripts/Runtime/Entity/EntityEvent.cs.meta
Normal file
11
Assets/TEngine/Scripts/Runtime/Entity/EntityEvent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3339c75ba3df974385330e4bbcf25af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -11,6 +11,8 @@ namespace TEngine.Runtime.ObjectPool
|
||||
[AddComponentMenu("TEngine/Object Pool")]
|
||||
public sealed class ObjectPoolComponent : UnitySingleton<ObjectPoolComponent>
|
||||
{
|
||||
public IObjectPoolManager PoolManager => m_ObjectPoolManager;
|
||||
|
||||
private IObjectPoolManager m_ObjectPoolManager = null;
|
||||
|
||||
/// <summary>
|
||||
@@ -1025,11 +1027,11 @@ namespace TEngine.Runtime.ObjectPool
|
||||
{
|
||||
return m_ObjectPoolManager.DestroyObjectPool(objectPool);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 释放对象池中的可释放对象。
|
||||
/// </summary>
|
||||
public void Release()
|
||||
public void ReleaseObject()
|
||||
{
|
||||
Log.Info("Object pool release...");
|
||||
m_ObjectPoolManager.Release();
|
||||
|
Reference in New Issue
Block a user