コード例 #1
0
        //回收实体
        private void RecoveryEntity(EntityLogicBase entityLogic)
        {
            Type type = entityLogic.GetType();
            EntityResourceAttribute attribute = type.GetCustomAttribute <EntityResourceAttribute>();

            if (attribute != null)
            {
                if (_entities.ContainsKey(type))
                {
                    if (attribute.IsUseObjectPool)
                    {
                        _entities[type].Remove(entityLogic);
                        entityLogic.OnDestroy();
                        Main.m_ReferencePool.Despawn(entityLogic);
                        _objectPool[type].Enqueue(entityLogic.Entity);
                        entityLogic.Entity.SetActive(false);
                        entityLogic.Entity = null;
                        entityLogic        = null;
                    }
                    else
                    {
                        _entities[type].Remove(entityLogic);
                        entityLogic.OnDestroy();
                        Main.m_ReferencePool.Despawn(entityLogic);
                        Destroy(entityLogic.Entity);
                        entityLogic.Entity = null;
                        entityLogic        = null;
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("销毁实体失败:实体对象 {0} 并未存在!", type.Name));
                }
            }
        }
コード例 #2
0
        //回收实体
        private void RecoveryEntity(EntityLogicBase entityLogic)
        {
            Type type = entityLogic.GetType();
            EntityResourceAttribute attribute = type.GetCustomAttribute <EntityResourceAttribute>();

            if (attribute != null)
            {
                if (Entities.ContainsKey(type))
                {
                    if (attribute.IsUseObjectPool)
                    {
                        Entities[type].Remove(entityLogic);
                        entityLogic.OnDestroy();
                        Main.m_ReferencePool.Despawn(entityLogic);
                        ObjectPools[type].Enqueue(entityLogic.Entity);
                        entityLogic.Entity.SetActive(false);
                        entityLogic.Entity = null;
                        entityLogic        = null;
                    }
                    else
                    {
                        Entities[type].Remove(entityLogic);
                        entityLogic.OnDestroy();
                        Main.m_ReferencePool.Despawn(entityLogic);
                        Main.Kill(entityLogic.Entity);
                        entityLogic.Entity = null;
                        entityLogic        = null;
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Entity, "销毁实体失败:实体对象 " + type.Name + " 并未存在!");
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// 隐藏实体
        /// </summary>
        /// <param name="entityLogic">实体逻辑对象</param>
        public void HideEntity(EntityLogicBase entityLogic)
        {
            if (entityLogic == null || !entityLogic.IsShowed)
            {
                return;
            }

            entityLogic.Entity.SetActive(false);
            entityLogic.OnHide();
        }
コード例 #4
0
        /// <summary>
        /// 显示实体
        /// </summary>
        /// <param name="entityLogic">实体逻辑对象</param>
        public void ShowEntity(EntityLogicBase entityLogic)
        {
            if (entityLogic == null || entityLogic.IsShowed)
            {
                return;
            }

            entityLogic.Entity.SetActive(true);
            entityLogic.OnShow();
        }
コード例 #5
0
 /// <summary>
 /// 根据名称获取实体
 /// </summary>
 /// <param name="type">实体逻辑类</param>
 /// <param name="entityName">实体名称</param>
 /// <returns>实体</returns>
 public EntityLogicBase GetEntity(Type type, string entityName)
 {
     if (Entities.ContainsKey(type))
     {
         EntityLogicBase entityLogic = Entities[type].Find((entity) => { return(entity.Name == entityName); });
         return(entityLogic);
     }
     else
     {
         throw new HTFrameworkException(HTFrameworkModule.Entity, "获取实体失败:实体对象 " + type.Name + " 并未存在!");
     }
 }
コード例 #6
0
        //生成实体
        private EntityLogicBase GenerateEntity(Type type, GameObject entity, string entityName)
        {
            EntityLogicBase entityLogic = Main.m_ReferencePool.Spawn(type) as EntityLogicBase;

            Entities[type].Add(entityLogic);
            entityLogic.Entity      = entity;
            entityLogic.Entity.name = entityLogic.Name = entityName;
            entityLogic.Entity.SetActive(true);
            entityLogic.OnInit();
            entityLogic.OnShow();
            return(entityLogic);
        }
コード例 #7
0
        /// <summary>
        /// 创建实体
        /// </summary>
        /// <param name="type">实体逻辑类</param>
        /// <param name="entityName">实体指定名称(为 <None> 时默认使用实体逻辑类名称)</param>
        /// <param name="loadingAction">创建实体过程进度回调</param>
        /// <param name="loadDoneAction">创建实体完成回调</param>
        /// <returns>加载协程</returns>
        public Coroutine CreateEntity(Type type, string entityName, HTFAction <float> loadingAction, HTFAction <EntityLogicBase> loadDoneAction)
        {
            EntityResourceAttribute attribute = type.GetCustomAttribute <EntityResourceAttribute>();

            if (attribute != null)
            {
                if (Entities.ContainsKey(type))
                {
                    if (attribute.IsUseObjectPool && ObjectPools[type].Count > 0)
                    {
                        EntityLogicBase entityLogic = GenerateEntity(type, ObjectPools[type].Dequeue(), entityName == "<None>" ? type.Name : entityName);

                        loadingAction?.Invoke(1);
                        loadDoneAction?.Invoke(entityLogic);
                        Main.m_Event.Throw(this, Main.m_ReferencePool.Spawn <EventCreateEntitySucceed>().Fill(entityLogic));
                        return(null);
                    }
                    else
                    {
                        if (_defineEntities.ContainsKey(type.FullName) && _defineEntities[type.FullName] != null)
                        {
                            EntityLogicBase entityLogic = GenerateEntity(type, Main.Clone(_defineEntities[type.FullName], _entitiesGroup[type].transform), entityName == "<None>" ? type.Name : entityName);

                            loadingAction?.Invoke(1);
                            loadDoneAction?.Invoke(entityLogic);
                            Main.m_Event.Throw(this, Main.m_ReferencePool.Spawn <EventCreateEntitySucceed>().Fill(entityLogic));
                            return(null);
                        }
                        else
                        {
                            return(Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _entitiesGroup[type].transform, loadingAction, (obj) =>
                            {
                                EntityLogicBase entityLogic = GenerateEntity(type, obj, entityName == "<None>" ? type.Name : entityName);

                                loadDoneAction?.Invoke(entityLogic);
                                Main.m_Event.Throw(this, Main.m_ReferencePool.Spawn <EventCreateEntitySucceed>().Fill(entityLogic));
                            }));
                        }
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Entity, "创建实体失败:实体对象 " + type.Name + " 并未存在!");
                }
            }
            return(null);
        }
コード例 #8
0
        //提取实体
        private Coroutine ExtractEntity(Type type, string entityName = "<None>", HTFAction <float> loadingAction = null, HTFAction <EntityLogicBase> loadDoneAction = null)
        {
            EntityResourceAttribute attribute = type.GetCustomAttribute <EntityResourceAttribute>();

            if (attribute != null)
            {
                if (_entities.ContainsKey(type))
                {
                    if (attribute.IsUseObjectPool && _objectPool[type].Count > 0)
                    {
                        EntityLogicBase entityLogic = Main.m_ReferencePool.Spawn(type) as EntityLogicBase;
                        _entities[type].Add(entityLogic);
                        entityLogic.Entity      = _objectPool[type].Dequeue();
                        entityLogic.Entity.name = entityLogic.Name = entityName == "<None>" ? type.Name : entityName;
                        entityLogic.Entity.SetActive(true);
                        entityLogic.OnInit();
                        entityLogic.OnShow();

                        loadingAction?.Invoke(1);
                        loadDoneAction?.Invoke(entityLogic);
                        Main.m_Event.Throw(this, Main.m_ReferencePool.Spawn <EventCreateEntitySucceed>().Fill(entityLogic));
                        return(null);
                    }
                    else
                    {
                        return(Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _entitiesGroup[type].transform, loadingAction, (obj) =>
                        {
                            EntityLogicBase entityLogic = Main.m_ReferencePool.Spawn(type) as EntityLogicBase;
                            _entities[type].Add(entityLogic);
                            entityLogic.Entity = obj;
                            entityLogic.Entity.name = entityLogic.Name = entityName == "<None>" ? type.Name : entityName;
                            entityLogic.Entity.SetActive(true);
                            entityLogic.OnInit();
                            entityLogic.OnShow();

                            loadDoneAction?.Invoke(entityLogic);
                            Main.m_Event.Throw(this, Main.m_ReferencePool.Spawn <EventCreateEntitySucceed>().Fill(entityLogic));
                        }));
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("创建实体失败:实体对象 {0} 并未存在!", type.Name));
                }
            }
            return(null);
        }
コード例 #9
0
 /// <summary>
 /// 根据名称获取实体
 /// </summary>
 /// <param name="type">实体逻辑类</param>
 /// <param name="entityName">实体名称</param>
 /// <returns>实体</returns>
 public EntityLogicBase GetEntity(Type type, string entityName)
 {
     if (_entities.ContainsKey(type))
     {
         EntityLogicBase entityLogic = _entities[type].Find((entity) => { return(entity.Name == entityName); });
         if (entityLogic == null)
         {
             GlobalTools.LogError(string.Format("获取实体失败:实体名称 {0} 并未存在!", entityName));
         }
         return(entityLogic);
     }
     else
     {
         GlobalTools.LogError(string.Format("获取实体失败:实体对象 {0} 并未存在!", type.Name));
         return(null);
     }
 }
コード例 #10
0
        //批量回收实体
        private void RecoveryEntities(Type type)
        {
            EntityResourceAttribute attribute = type.GetCustomAttribute <EntityResourceAttribute>();

            if (attribute != null)
            {
                if (_entities.ContainsKey(type))
                {
                    if (attribute.IsUseObjectPool)
                    {
                        for (int i = 0; i < _entities[type].Count; i++)
                        {
                            EntityLogicBase entityLogic = _entities[type][i];
                            entityLogic.OnDestroy();
                            Main.m_ReferencePool.Despawn(entityLogic);
                            _objectPool[type].Enqueue(entityLogic.Entity);
                            entityLogic.Entity.SetActive(false);
                            entityLogic.Entity = null;
                        }
                        _entities[type].Clear();
                    }
                    else
                    {
                        for (int i = 0; i < _entities[type].Count; i++)
                        {
                            EntityLogicBase entityLogic = _entities[type][i];
                            entityLogic.OnDestroy();
                            Main.m_ReferencePool.Despawn(entityLogic);
                            Main.Kill(entityLogic.Entity);
                            entityLogic.Entity = null;
                        }
                        _entities[type].Clear();
                    }
                }
                else
                {
                    throw new HTFrameworkException(HTFrameworkModule.Entity, "销毁实体失败:实体对象 " + type.Name + " 并未存在!");
                }
            }
        }
コード例 #11
0
 /// <summary>
 /// 销毁实体
 /// </summary>
 /// <param name="entityLogic">实体逻辑对象</param>
 public void DestroyEntity(EntityLogicBase entityLogic)
 {
     RecoveryEntity(entityLogic);
 }
コード例 #12
0
 /// <summary>
 /// 销毁实体
 /// </summary>
 /// <param name="entityLogic">实体逻辑对象</param>
 public void DestroyEntity(EntityLogicBase entityLogic)
 {
     _helper.DestroyEntity(entityLogic);
 }
コード例 #13
0
 /// <summary>
 /// 隐藏实体
 /// </summary>
 /// <param name="entityLogic">实体逻辑对象</param>
 public void HideEntity(EntityLogicBase entityLogic)
 {
     _helper.HideEntity(entityLogic);
 }
コード例 #14
0
 /// <summary>
 /// 显示实体
 /// </summary>
 /// <param name="entityLogic">实体逻辑对象</param>
 public void ShowEntity(EntityLogicBase entityLogic)
 {
     _helper.ShowEntity(entityLogic);
 }
コード例 #15
0
 /// <summary>
 /// 应用实体逻辑类的对象路径定义
 /// </summary>
 /// <param name="entityLogicBase">实体逻辑实例</param>
 /// <param name="fieldInfos">所有自动化字段</param>
 public static void ApplyObjectPath(EntityLogicBase entityLogicBase, FieldInfo[] fieldInfos)
 {
     ApplyObjectPath(entityLogicBase, entityLogicBase.Entity, fieldInfos);
 }
コード例 #16
0
 /// <summary>
 /// 应用实体逻辑类的数据绑定
 /// </summary>
 /// <param name="entityLogicBase">实体逻辑实例</param>
 /// <param name="fieldInfos">所有自动化字段</param>
 public static void ApplyDataBinding(EntityLogicBase entityLogicBase, FieldInfo[] fieldInfos)
 {
     ApplyDataBinding(entityLogicBase, entityLogicBase, fieldInfos);
 }