Esempio n. 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);
                        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 + " 并未存在!");
                }
            }
        }
Esempio n. 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);
                        _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));
                }
            }
        }