123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- //------------------------------------------------------------
- // Game Framework
- // Copyright © 2013-2021 loyalsoft. All rights reserved.
- // Homepage: http://www.game7000.com/
- // Feedback: http://www.game7000.com/
- //------------------------------------------------------------
- using System.Collections.Generic;
- namespace GameFramework.Entity
- {
- internal sealed partial class EntityManager : GameFrameworkModule, IEntityManager
- {
- /// <summary>
- /// 实体信息。
- /// </summary>
- private sealed class EntityInfo : IReference
- {
- 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 GameFrameworkException("Entity is invalid.");
- }
- EntityInfo entityInfo = ReferencePool.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 GameFrameworkException("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 GameFrameworkException("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 GameFrameworkException("Can not remove child entity which is not exist.");
- }
- }
- }
- }
- }
|