private void LoadEntitySuccessCallback(string entityAssetName, object entityAsset, float duration, object userData)
        {
            //获取记载实体的信息
            LoadEntityInfo loadEntityInfo = (LoadEntityInfo)userData;

            if (loadEntityInfo == null)
            {
                Debug.LogError("加载实体的信息为空");
                return;
            }
            m_EntitiesBeingLoaded.Remove(loadEntityInfo.EntityId);

            if (m_EntitiesToReleaseOnLoad.Contains(loadEntityInfo.SerialId))
            {
                Debug.LogError(string.Format("需要释放的实体:{0}(id:{1})加载成功", loadEntityInfo.EntityId.ToString(), loadEntityInfo.SerialId.ToString()));
                m_EntitiesToReleaseOnLoad.Remove(loadEntityInfo.SerialId);
                m_EntityHelper.ReleaseEntity(entityAsset, null);
                return;
            }

            //实例化实体,并将实体实例对象放入对象池
            EntityInstanceObject entityInstanceObject = new EntityInstanceObject(entityAssetName, entityAsset, m_EntityHelper.InstantiateEntity(entityAsset), m_EntityHelper);

            loadEntityInfo.EntityGroup.RegisterEntityInstanceObject(entityInstanceObject, true);

            //显示实体
            ShowEntity(loadEntityInfo.EntityId, entityAssetName, loadEntityInfo.EntityGroup, entityInstanceObject.Target, true, duration, loadEntityInfo.UserData);
        }
        /// <summary>
        /// 显示实体。
        /// </summary>
        /// <param name="entityId">实体编号</param>
        /// <param name="entityLogicType">实体逻辑类型</param>
        /// <param name="entityAssetName">实体资源名称</param>
        /// <param name="entityGroupName">实体组名称</param>
        /// <param name="userData">用户自定义数据</param>
        public void ShowEntity(int entityId, Type entityLogicType, string entityAssetName, string entityGroupName, object userData)
        {
            if (entityLogicType == null)
            {
                Debug.LogError("显示实体时的实体逻辑类型为空");
                return;
            }
            ShowEntityInfo info = new ShowEntityInfo(entityLogicType, userData);

            if (m_ResourceManager == null)
            {
                Debug.LogError("显示实体时的资源管理器为空");
                return;
            }

            if (m_EntityHelper == null)
            {
                Debug.LogError("显示实体时的辅助器为空");
                return;
            }

            if (string.IsNullOrEmpty(entityAssetName))
            {
                Debug.LogError("显示实体时的实体资源名称为空");
                return;
            }

            if (string.IsNullOrEmpty(entityGroupName))
            {
                Debug.LogError("显示实体时的实体组名称为空");
                return;
            }

            if (m_EntityInfos.ContainsKey(entityId))
            {
                Debug.LogError("显示实体时的实体信息已存在");
                return;
            }

            if (IsLoadingEntity(entityId))
            {
                Debug.LogError("要显示的实体已在加载");
                return;
            }

            //实体组检查
            EntityGroup entityGroup = GetEntityGroup(entityGroupName);

            if (entityGroup == null)
            {
                Debug.LogError("显示实体时的实体组不存在");
                return;
            }

            //尝试从对象池获取实体实例
            EntityInstanceObject entityInstanceObject = entityGroup.SpawnEntityInstanceObject(entityAssetName);

            if (entityInstanceObject == null)
            {
                //没获取到就加载该实体
                int serialId = m_Serial++;
                m_EntitiesBeingLoaded.Add(entityId, serialId);
                m_ResourceManager.LoadAsset(entityAssetName, m_LoadAssetCallbacks, new LoadEntityInfo(serialId, entityId, entityGroup, info));
                return;
            }

            ShowEntity(entityId, entityAssetName, entityGroup, entityInstanceObject.Target, false, 0f, info);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 注册实体实例对象到对象池
 /// </summary>
 public void RegisterEntityInstanceObject(EntityInstanceObject obj, bool spawned = false)
 {
     m_InstancePool.Register(obj, spawned);
 }