Esempio n. 1
0
 private void OnHideEntityComplete(int entityId, string entityAssetName, EntityGroup entityGroup, object userData)
 {
     if (m_EnableHideEntityCompleteEvent)
     {
         GameEntry.Event.CommonEvent.Dispatch(this, GameEntry.Pool.SpawnClassObject <HideEntityCompleteEventArgs>().Fill(entityId, entityAssetName, entityGroup, userData));
     }
 }
Esempio n. 2
0
 public ShowEntityInfo(int serialId, int entityId, EntityGroup entityGroup, Type entityLogicType, object userData)
 {
     m_SerialId        = serialId;
     m_EntityId        = entityId;
     m_EntityGroup     = entityGroup;
     m_EntityLogicType = entityLogicType;
     m_UserData        = userData;
 }
Esempio n. 3
0
        /// <summary>
        /// 获取所有实体组
        /// </summary>
        /// <returns>所有实体组</returns>
        public EntityGroup[] GetAllEntityGroups()
        {
            int index = 0;

            EntityGroup[] results = new EntityGroup[m_EntityGroups.Count];
            foreach (KeyValuePair <string, EntityGroup> entityGroup in m_EntityGroups)
            {
                results[index++] = entityGroup.Value;
            }

            return(results);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取实体组
        /// </summary>
        /// <param name="entityGroupName">实体组名称</param>
        /// <returns>要获取的实体组</returns>
        public EntityGroup GetEntityGroup(string entityGroupName)
        {
            if (string.IsNullOrEmpty(entityGroupName))
            {
                throw new Exception("Entity group name is invalid.");
            }

            EntityGroup entityGroup = null;

            if (m_EntityGroups.TryGetValue(entityGroupName, out entityGroup))
            {
                return(entityGroup);
            }

            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// 设置实体是否被加锁
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="locked">实体是否被加锁</param>
        public void SetEntityInstanceLocked(EntityBase entity, bool locked)
        {
            if (entity == null)
            {
                Debug.LogWarning("Entity is invalid.");
                return;
            }

            EntityGroup entityGroup = entity.EntityGroup;

            if (entityGroup == null)
            {
                Debug.LogWarning("Entity group is invalid.");
                return;
            }

            entityGroup.SetEntityInstanceLocked(entity.gameObject, locked);
        }
Esempio n. 6
0
        /// <summary>
        /// 设置实体的优先级
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="priority">实体优先级</param>
        public void SetInstancePriority(EntityBase entity, int priority)
        {
            if (entity == null)
            {
                Debug.LogWarning("Entity is invalid.");
                return;
            }

            EntityGroup entityGroup = entity.EntityGroup;

            if (entityGroup == null)
            {
                Debug.LogWarning("Entity group is invalid.");
                return;
            }

            entityGroup.SetEntityInstancePriority(entity.gameObject, priority);
        }
Esempio n. 7
0
        /// <summary>
        /// 实体初始化
        /// </summary>
        /// <param name="entityId">实体编号</param>
        /// <param name="entityAssetName">实体资源名称</param>
        /// <param name="entityGroup">实体所属的实体组</param>
        /// <param name="isNewInstance">是否是新实例</param>
        /// <param name="isNewLogic">是否是新逻辑</param>
        /// <param name="userData">用户自定义数据</param>
        public void OnInit(int entityId, string entityAssetName, EntityGroup entityGroup, bool isNewInstance, bool isNewLogic, object userData)
        {
            m_Id = entityId;
            m_EntityAssetName = entityAssetName;

            if (isNewInstance || isNewLogic)
            {
                m_EntityGroup = entityGroup;
            }
            else if (m_EntityGroup != entityGroup)
            {
                Log.Error("Entity group is inconsistent for non-new-instance entity.");
                return;
            }

            if (isNewLogic)
            {
                OnInit(userData);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 显示实体
        /// </summary>
        /// <param name="entityId">实体编号</param>
        /// <param name="entityAssetName">实体资源名称</param>
        /// <param name="entityGroupName">实体组名称</param>
        /// <param name="priority">加载实体资源的优先级</param>
        /// <param name="entityLogicType">实体逻辑</param>
        /// <param name="userData">用户自定义数据</param>
        public void ShowEntity(int entityId, string entityAssetName, string entityGroupName, int priority, Type entityLogicType, object userData)
        {
            if (string.IsNullOrEmpty(entityAssetName))
            {
                throw new Exception("Entity asset name is invalid.");
            }

            if (string.IsNullOrEmpty(entityGroupName))
            {
                throw new Exception("Entity group name is invalid.");
            }

            if (m_EntityInfos.ContainsKey(entityId))
            {
                throw new Exception(TextUtil.Format("Entity id '{0}' is already exist.", entityId.ToString()));
            }

            if (IsLoadingEntity(entityId))
            {
                throw new Exception(TextUtil.Format("Entity '{0}' is already being loaded.", entityId.ToString()));
            }

            EntityGroup entityGroup = GetEntityGroup(entityGroupName);

            if (entityGroup == null)
            {
                throw new Exception(TextUtil.Format("Entity group '{0}' is not exist.", entityGroupName));
            }

            EntityInstanceObject entityInstanceObject = entityGroup.SpawnEntityInstanceObject(entityAssetName);

            if (entityInstanceObject == null)
            {
                int serialId = m_Serial++;
                m_EntitiesBeingLoaded.Add(entityId, serialId);
                GameEntry.Resource.LoadAsset(entityAssetName, typeof(GameObject), priority, m_LoadAssetCallbacks, new ShowEntityInfo(serialId, entityId, entityGroup, entityLogicType, userData));
                return;
            }

            InternalShowEntity(entityId, entityAssetName, entityGroup, entityInstanceObject.Target, false, 0f, entityLogicType, userData);
        }
Esempio n. 9
0
        private void InternalHideEntity(EntityInfo entityInfo, object userData)
        {
            EntityBase entity = entityInfo.Entity;

            EntityBase[] childEntities = entityInfo.GetChildEntities();
            foreach (EntityBase childEntity in childEntities)
            {
                HideEntity(childEntity.Id, userData);
            }

            if (entityInfo.Status == EntityStatus.Hidden)
            {
                return;
            }

            DetachEntity(entity.Id, userData);
            entityInfo.Status = EntityStatus.WillHide;
            entity.OnHide(userData);
            entityInfo.Status = EntityStatus.Hidden;

            EntityGroup entityGroup = entity.EntityGroup;

            if (entityGroup == null)
            {
                throw new Exception("Entity group is invalid.");
            }

            entityGroup.RemoveEntity(entity);
            if (!m_EntityInfos.Remove(entity.Id))
            {
                throw new Exception("Entity info is unmanaged.");
            }

            if (HideEntityCompleteCallBack != null)
            {
                HideEntityCompleteCallBack(entity.Id, entity.EntityAssetName, entityGroup, userData);
            }

            m_RecycleQueue.AddLast(entityInfo);
        }
Esempio n. 10
0
        /// <summary>
        /// 实体管理器轮询
        /// </summary>
        public void OnUpdate(float deltaTime, float unscaledDeltaTime)
        {
            while (m_RecycleQueue.Count > 0)
            {
                EntityInfo entityInfo = m_RecycleQueue.First.Value;
                m_RecycleQueue.RemoveFirst();
                EntityBase  entity      = entityInfo.Entity;
                EntityGroup entityGroup = entity.EntityGroup;
                if (entityGroup == null)
                {
                    throw new Exception("Entity group is invalid.");
                }

                entityInfo.Status = EntityStatus.WillRecycle;
                entity.OnRecycle();
                entityInfo.Status = EntityStatus.Recycled;
                entityGroup.UnspawnEntity(entity);
            }

            foreach (KeyValuePair <string, EntityGroup> entityGroup in m_EntityGroups)
            {
                entityGroup.Value.OnUpdate(deltaTime, unscaledDeltaTime);
            }
        }
Esempio n. 11
0
        private void InternalShowEntity(int entityId, string entityAssetName, EntityGroup entityGroup, object entityInstance, bool isNewInstance, float duration, Type entityLogicType, object userData)
        {
            try
            {
                GameObject gameObject = entityInstance as GameObject;
                if (gameObject == null)
                {
                    Log.Error("Entity instance is invalid.");
                    return;
                }
                Transform transform = gameObject.transform;
                transform.SetParent(entityGroup.GroupTransform);

                EntityBase oldentity  = gameObject.GetComponent <EntityBase>();
                EntityBase entity     = null;
                bool       isNewLogic = false;
                if (oldentity != null)
                {
                    if (oldentity.GetType() == entityLogicType)
                    {
                        oldentity.enabled = true;
                        entity            = oldentity;
                    }
                    else
                    {
                        UnityEngine.Object.Destroy(oldentity);
                        entity     = gameObject.AddComponent(entityLogicType) as EntityBase;
                        isNewLogic = true;
                    }
                }
                else
                {
                    entity     = gameObject.AddComponent(entityLogicType) as EntityBase;
                    isNewLogic = true;
                }

                if (entity == null)
                {
                    throw new Exception(string.Format("Entity '{0}' can not add entity logic.", entityAssetName));
                }

                EntityInfo entityInfo = new EntityInfo(entity);
                m_EntityInfos.Add(entityId, entityInfo);
                entityInfo.Status = EntityStatus.WillInit;
                entity.OnInit(entityId, entityAssetName, entityGroup, isNewInstance, isNewLogic, userData);
                entityInfo.Status = EntityStatus.Inited;
                entityGroup.AddEntity(entity);
                entityInfo.Status = EntityStatus.WillShow;
                entity.OnShow(userData);
                entityInfo.Status = EntityStatus.Showed;

                if (ShowEntitySuccessCallBack != null)
                {
                    ShowEntitySuccessCallBack(entity, duration, userData);
                }
            }
            catch (Exception exception)
            {
                if (ShowEntityFailureCallBack != null)
                {
                    ShowEntityFailureCallBack(entityId, entityAssetName, entityGroup.Name, entityLogicType, exception.ToString(), userData);
                    return;
                }

                throw;
            }
        }