//private void OnEffectLoadComplete(string effectPath, UnityObject unityObject, SystemObject userData) //{ // effectAssetHandle = null; // GameObject effectGO = (GameObject)unityObject; // string poolGroup = userData as string; // // 读取完的时候, 特效已经销毁了 // if (m_Status == EffectStatus.Recycled) // { // RecycleFX(); // return; // } // // 读取资源错误 // if (unityObject == null) // { // DebugLogger.LogError($"EffectController::OnEffectLoadComplete. 读取资源失败: {effectPath}"); // RecycleFX(); // return; // } // // 指定了池子组的名字, 但是找不到池子组 // if (!string.IsNullOrEmpty(poolGroup) && !PoolManager.GetInstance().HasSpawnPool(poolGroup)) // { // DebugLogger.LogError($"EffectController::OnEffectLoadComplete. 找不到SpawnPool. SpawnPoolName: {poolGroup}. effectPath: {effectPath}"); // RecycleFX(); // return; // } // // 没挂脚本, 就不自动挂了, 省的老是忽略这个错误 // VFXController vfx = effectGO.GetComponent<VFXController>(); // if (vfx == null) // { // DebugLogger.LogError($"EffectController::OnEffectLoadComplete. 特效没有正确地挂脚本: {effectPath}"); // RecycleFX(); // return; // } // if (string.IsNullOrEmpty(poolGroup)) // { // _SetEffectAndUpdateEffectStatus(vfx); // } // else // { // SpawnPool spawnPool = PoolManager.GetInstance().GetSpawnPool(poolGroup); // GameObjectPool objPool = spawnPool.GetGameObjectPool(effectPath); // if (objPool == null) // { // GameObject template = Instantiate(effectGO); // objPool = spawnPool.CreateGameObjectPool(effectPath, template); // } // _SetEffectAndUpdateEffectStatus(objPool.GetComponentItem<VFXController>()); // } //} void OnEffectLoadComplete(string pathOrAddress, UnityObject returnObject, SystemObject userData) { LoadData d = userData as LoadData; if (!m_AssetName.Equals(d.assetName)) { // 可能有这种情况: // A特效 请求加载. 没加载完的时候A特效就回收了. B 特效使用了同一个EffectController, 也请求加载. 这时候A刚加载完 return; } if (!m_EffectID.Equals(d.effectID)) { return; } if (returnObject == null) { return; } m_AssetLoadHandler = null; GameObject effectGO = (GameObject)returnObject; // 读取完的时候, 特效已经销毁了 if (m_Status == EffectStatus.Recycled) { RecycleFX(); return; } // 读取资源错误 if (effectGO == null) { DebugUtility.LogError(LOG_TAG, $"EffectController::OnEffectLoadComplete. 读取资源失败: {m_AssetName}"); RecycleFX(); return; } // 没挂脚本, 就不自动挂了, 省的老是忽略这个错误 VFXController vfx = effectGO.GetComponent <VFXController>(); if (vfx == null) { DebugUtility.LogError(LOG_TAG, $"EffectController::OnEffectLoadComplete. 特效没有正确地挂脚本: {m_AssetName}"); RecycleFX(); return; } if (!effectGO.IsPooled()) { effectGO.CreatePool(1, pathOrAddress); } VFXController vfxInstance = vfx.Spawn(); vfxInstance.DoSpawned(); _SetEffectAndUpdateEffectStatus(vfxInstance); }
/// <summary> /// 使用PoolData进行资源加载,资源加载完成后创建对应的缓存池 /// </summary> /// <param name="poolData"></param> public void LoadAssetToCreateGameObjectPool(PoolData poolData) { SpawnPool spawnPool = GetSpawnPool(poolData.SpawnName); if (spawnPool == null) { CreateSpawnPool(poolData.SpawnName); } else { if (spawnPool.HasGameObjectPool(poolData.AssetPath)) { Debug.LogWarning("PoolManager::LoadAssetToCreateGameObjectPool->GameObjectPool has been created!"); return; } } for (int i = 0; i < m_PoolDatas.Count; i++) { PoolData pData = m_PoolDatas[i]; if (pData.SpawnName == poolData.SpawnName && pData.AssetPath == poolData.AssetPath) { Debug.LogError("PoolManager::CreateGameObjectPool->pool data has been added"); return; } } AssetLoaderHandle assetHandle = Loader.AssetManager.GetInstance().LoadAssetAsync(poolData.AssetPath, OnLoadComplete, AssetLoaderPriority.Default, null, poolData); poolData.LoaderHandle = assetHandle; m_PoolDatas.Add(poolData); }
public void RequestInitialize(MapController owner, AreaInfo areaInfo) { m_AreaRoot = new GameObject(Constants.AREA_GAMEOBJECT_NAME_STARTWITHS + areaInfo.Uid).transform; m_AreaRoot.SetPositionAndRotation(Vector3.zero, areaInfo.Rotation); m_IsReleasing = false; m_Owner = owner; m_AreaInfo = areaInfo; DoUpdate_AreaRoot(true); string areaDetailInfoAddressableKey = string.Format(Constants.AREA_DETAIL_INFO_FILENAME_FORMAT , owner.GetMapUid() , areaInfo.Uid); m_AreaDetailLoaderHandle = AssetUtil.LoadAssetAsync(areaDetailInfoAddressableKey, OnLoadAreaDetailInfoCompleted); }
private void OnDestroy() { if (!SafeDestroy) { m_DestroyedUnsafe = true; //Debug.LogErrorFormat("EffectController 不该被直接 Destroy. {0}", name); } if (m_AssetLoadHandler != null && m_VFXController == null) { AssetUtil.UnloadAssetLoader(m_AssetLoadHandler); m_AssetLoadHandler = null; } ClearTimer(); EffectManager.GetInstance().OnDestroyEffect(this); }
/// <summary> /// 特效的初始化 /// </summary> /// <param name="effectPath"></param> /// <param name="poolGroup"></param> public void Initialize(string effectPath, string poolGroup = "", OnEffectLoaded OnEffectLoaded = null, System.Object usedata = null) { m_OnEffectLoaded += OnEffectLoaded; this.usedata = usedata; m_AssetName = effectPath; m_Status = EffectStatus.Playing; m_EffectID = EffectID(); MyName = "EffectController_" + m_AssetName + "_" + m_EffectID; name = MyName; LoadData d = new LoadData(); d.effectID = m_EffectID; d.assetName = m_AssetName; if (!string.IsNullOrEmpty(m_AssetName) && effectPath != "None") { m_AssetLoadHandler = AssetUtil.LoadAssetAsync(effectPath, OnEffectLoadComplete, Loader.AssetLoaderPriority.Default, null, d); } }
/// <summary> /// 卸载一个加载任务 /// </summary> /// <param name="handle"></param> /// <param name="destroyIfLoaded"></param> public static void UnloadAssetLoader(AssetLoaderHandle handle, bool destroyIfLoaded = false) { AssetMgr.GetInstance().UnloadAssetLoader(handle, destroyIfLoaded); }