Beispiel #1
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);
        }
Beispiel #2
0
        /// <summary>
        /// 加载实体成功回调
        /// </summary>
        /// <param name="entityAssetName">实体资源名称</param>
        /// <param name="entityAsset">实体资源</param>
        /// <param name="duration">加载时间</param>
        /// <param name="userData">用户数据</param>
        private void LoadEntitySuccessCallback(string entityAssetName, UnityEngine.Object entityAsset, float duration, object userData)
        {
            ShowEntityInfo showEntityInfo = (ShowEntityInfo)userData;

            if (showEntityInfo == null)
            {
                throw new Exception("Show entity info is invalid.");
            }

            m_EntitiesBeingLoaded.Remove(showEntityInfo.EntityId);
            if (m_EntitiesToReleaseOnLoad.Contains(showEntityInfo.SerialId))
            {
                Log.Info("Release entity '{0}' (serial id '{1}') on loading success.", showEntityInfo.EntityId.ToString(), showEntityInfo.SerialId.ToString());
                m_EntitiesToReleaseOnLoad.Remove(showEntityInfo.SerialId);
                GameEntry.Resource.UnloadAsset(entityAsset);
                return;
            }

            EntityInstanceObject entityInstanceObject = new EntityInstanceObject(entityAssetName, entityAsset, UnityEngine.Object.Instantiate(entityAsset));

            showEntityInfo.EntityGroup.RegisterEntityInstanceObject(entityInstanceObject, true);

            InternalShowEntity(showEntityInfo.EntityId, entityAssetName, showEntityInfo.EntityGroup, entityInstanceObject.Target, true, duration, showEntityInfo.EntityLogicType, showEntityInfo.UserData);
        }
Beispiel #3
0
 public void RegisterEntityInstanceObject(EntityInstanceObject obj, bool spawned)
 {
     m_InstancePool.Register(obj, spawned);
 }