Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }