private AssetOperationHandle LoadInternal(string location, System.Type assetType, IAssetParam param) { string assetName = Path.GetFileName(location); AssetLoaderBase cacheLoader = AssetSystem.CreateLoader(location); return(cacheLoader.LoadAssetAsync(assetName, assetType, param)); }
internal static AssetLoaderBase CreateLoaderInternal(AssetBundleInfo bundleInfo) { // 如果加载器已经存在 AssetLoaderBase loader = TryGetLoader(bundleInfo.ManifestPath); if (loader != null) { loader.Reference(); //引用计数 return(loader); } // 创建加载器 AssetLoaderBase newLoader; if (SimulationOnEditor) { newLoader = new AssetDatabaseLoader(bundleInfo); } else { newLoader = new AssetBundleLoader(bundleInfo); } // 新增下载需求 _loaders.Add(newLoader); newLoader.Reference(); //引用计数 return(newLoader); }
private AssetOperationHandle LoadInternal(string assetName, System.Type assetType, IAssetParam param) { if (_cacheLoader == null) { _cacheLoader = AssetSystem.CreateLoader(Location, Variant); } return(_cacheLoader.LoadAssetAsync(assetName, assetType, param)); }
/// <summary> /// 异步加载场景 /// </summary> public AssetOperationHandle LoadSceneAsync(string location, SceneInstanceParam instanceParam) { string sceneName = Path.GetFileName(location); AssetLoaderBase cacheLoader = AssetSystem.CreateLoader(location); var handle = cacheLoader.LoadSceneAsync(sceneName, instanceParam); return(handle); }
/// <summary> /// 释放资源 /// </summary> public void Release() { if (_cacheLoader != null) { _cacheLoader.Release(); _cacheLoader = null; } Location = string.Empty; }
/// <summary> /// 获取当前所有正在使用的Bundle信息 /// </summary> public static List <AssetBundleInfo> GetAllBundleInfos() { List <AssetBundleInfo> infos = new List <AssetBundleInfo>(_loaders.Count); for (int i = 0; i < _loaders.Count; i++) { AssetLoaderBase loader = _loaders[i]; infos.Add(loader.BundleInfo); } return(infos); }
/// <summary> /// 更新场景 /// 注意:因为场景比较特殊,需要立刻回收 /// </summary> private static void UpdateScene() { for (int i = _loaders.Count - 1; i >= 0; i--) { AssetLoaderBase loader = _loaders[i]; if (loader.IsSceneLoader && loader.CanDestroy()) { loader.Destroy(true); _loaders.RemoveAt(i); } } }
/// <summary> /// 资源回收 /// 卸载引用计数为零的资源 /// </summary> public static void UnloadUnusedAssets() { for (int i = _loaders.Count - 1; i >= 0; i--) { AssetLoaderBase loader = _loaders[i]; if (loader.CanDestroy()) { loader.Destroy(true); _loaders.RemoveAt(i); } } }
/// <summary> /// 资源回收 /// 卸载引用计数为零的资源 /// </summary> public static void Release() { for (int i = _loaders.Count - 1; i >= 0; i--) { AssetLoaderBase loader = _loaders[i]; if (loader.IsDone() && loader.RefCount <= 0) { loader.Destroy(true); _loaders.RemoveAt(i); } } }
/// <summary> /// 强制回收所有资源 /// </summary> public static void ForceReleaseAll() { for (int i = 0; i < _loaders.Count; i++) { AssetLoaderBase loader = _loaders[i]; loader.Destroy(true); } _loaders.Clear(); // 释放所有资源 Resources.UnloadUnusedAssets(); }
private AssetOperationHandle LoadSubAssetsInternal(string location, System.Type assetType, bool forceSyncLoad) { string assetName = Path.GetFileName(location); AssetLoaderBase cacheLoader = AssetSystem.CreateLoader(location); var handle = cacheLoader.LoadSubAssetsAsync(assetName, assetType); if (forceSyncLoad) { cacheLoader.ForceSyncLoad(); } return(handle); }
internal static int GetLoaderFailedCount() { int count = 0; for (int i = 0; i < _loaders.Count; i++) { AssetLoaderBase temp = _loaders[i]; if (temp.States == ELoaderStates.Fail || temp.GetFailedProviderCount() > 0) { count++; } } return(count); }
/// <summary> /// 从列表里获取加载器 /// </summary> private static AssetLoaderBase TryGetLoader(string bundleName) { AssetLoaderBase loader = null; for (int i = 0; i < _loaders.Count; i++) { AssetLoaderBase temp = _loaders[i]; if (temp.BundleInfo.BundleName.Equals(bundleName)) { loader = temp; break; } } return(loader); }
/// <summary> /// 从列表里获取加载器 /// </summary> private static AssetLoaderBase TryGetLoader(string manifestPath) { AssetLoaderBase loader = null; for (int i = 0; i < _loaders.Count; i++) { AssetLoaderBase temp = _loaders[i]; if (temp.BundleInfo.ManifestPath.Equals(manifestPath)) { loader = temp; break; } } return(loader); }
public AssetBundleLoader(AssetBundleInfo bundleInfo) : base(bundleInfo) { // 准备依赖列表 string[] dependencies = AssetSystem.BundleServices.GetDirectDependencies(bundleInfo.BundleName); if (dependencies != null && dependencies.Length > 0) { foreach (string dependBundleName in dependencies) { AssetBundleInfo dependBundleInfo = AssetSystem.BundleServices.GetAssetBundleInfo(dependBundleName); AssetLoaderBase dependLoader = AssetSystem.CreateLoaderInternal(dependBundleInfo); _depends.Add(dependLoader); } } }
internal static AssetLoaderBase CreateLoaderInternal(AssetBundleInfo bundleInfo) { // 如果加载器已经存在 AssetLoaderBase loader = TryGetLoader(bundleInfo.BundleName); if (loader != null) { return(loader); } // 创建加载器 if (SimulationOnEditor) { loader = new AssetDatabaseLoader(bundleInfo); } else { loader = new AssetBundleLoader(bundleInfo); } // 新增下载需求 _loaders.Add(loader); return(loader); }
public AssetSceneProvider(AssetLoaderBase owner, string assetName, SceneInstanceParam param) : base(owner, assetName, null) { _param = param; }
public override void Update() { // 如果资源文件加载完毕 if (States == ELoaderStates.Success || States == ELoaderStates.Fail) { UpdateAllProvider(); return; } if (States == ELoaderStates.None) { // 检测加载地址是否为空 if (string.IsNullOrEmpty(BundleInfo.LocalPath)) { States = ELoaderStates.Fail; return; } if (string.IsNullOrEmpty(BundleInfo.RemoteURL)) { States = ELoaderStates.LoadDepends; } else { States = ELoaderStates.Download; } } // 1. 从服务器下载 if (States == ELoaderStates.Download) { _downloader = new WebFileRequest(BundleInfo.RemoteURL, BundleInfo.LocalPath); _downloader.DownLoad(); States = ELoaderStates.CheckDownload; } // 2. 检测服务器下载结果 if (States == ELoaderStates.CheckDownload) { if (_downloader.IsDone() == false) { return; } if (_downloader.HasError()) { _downloader.ReportError(); States = ELoaderStates.Fail; } else { // 校验文件完整性 if (AssetSystem.BundleServices.CheckContentIntegrity(BundleInfo.ManifestPath) == false) { MotionLog.Error($"Check download content integrity is failed : {BundleInfo.ManifestPath}"); States = ELoaderStates.Fail; } else { States = ELoaderStates.LoadDepends; } } // 释放网络资源下载器 if (_downloader != null) { _downloader.Dispose(); _downloader = null; } } // 3. 加载所有依赖项 if (States == ELoaderStates.LoadDepends) { string[] dependencies = AssetSystem.BundleServices.GetDirectDependencies(BundleInfo.ManifestPath); if (dependencies != null && dependencies.Length > 0) { foreach (string dpManifestPath in dependencies) { AssetBundleInfo dpBundleInfo = AssetSystem.BundleServices.GetAssetBundleInfo(dpManifestPath); AssetLoaderBase dpLoader = AssetSystem.CreateLoaderInternal(dpBundleInfo); _depends.Add(dpLoader); } } States = ELoaderStates.CheckDepends; } // 4. 检测所有依赖完成状态 if (States == ELoaderStates.CheckDepends) { foreach (var dpLoader in _depends) { if (dpLoader.IsDone() == false) { return; } } States = ELoaderStates.LoadFile; } // 5. 加载AssetBundle if (States == ELoaderStates.LoadFile) { #if UNITY_EDITOR // 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。 if (System.IO.File.Exists(BundleInfo.LocalPath) == false) { MotionLog.Warning($"Not found assetBundle file : {BundleInfo.LocalPath}"); States = ELoaderStates.Fail; return; } #endif // Load assetBundle file if (BundleInfo.IsEncrypted) { if (AssetSystem.DecryptServices == null) { throw new Exception($"{nameof(AssetBundleLoader)} need IDecryptServices : {BundleInfo.ManifestPath}"); } EDecryptMethod decryptType = AssetSystem.DecryptServices.DecryptType; if (decryptType == EDecryptMethod.GetDecryptOffset) { ulong offset = AssetSystem.DecryptServices.GetDecryptOffset(BundleInfo); _cacheRequest = AssetBundle.LoadFromFileAsync(BundleInfo.LocalPath, 0, offset); } else if (decryptType == EDecryptMethod.GetDecryptBinary) { byte[] binary = AssetSystem.DecryptServices.GetDecryptBinary(BundleInfo); _cacheRequest = AssetBundle.LoadFromMemoryAsync(binary); } else { throw new NotImplementedException($"{decryptType}"); } } else { _cacheRequest = AssetBundle.LoadFromFileAsync(BundleInfo.LocalPath); } States = ELoaderStates.CheckFile; } // 6. 检测AssetBundle加载结果 if (States == ELoaderStates.CheckFile) { if (_cacheRequest.isDone == false) { return; } CacheBundle = _cacheRequest.assetBundle; // Check error if (CacheBundle == null) { MotionLog.Warning($"Failed to load assetBundle file : {BundleInfo.ManifestPath}"); States = ELoaderStates.Fail; } else { States = ELoaderStates.Success; } } }
public AssetSceneProvider(AssetLoaderBase owner, string assetName, System.Type assetType, SceneInstanceParam param) : base(owner, assetName, assetType) { _param = param; }
public override void Update() { // 如果资源文件加载完毕 if (States == ELoaderStates.Success || States == ELoaderStates.Fail) { UpdateAllProvider(); return; } if (States == ELoaderStates.None) { States = ELoaderStates.LoadDepends; } // 1. 加载所有依赖项 if (States == ELoaderStates.LoadDepends) { string[] dependencies = AssetSystem.BundleServices.GetDirectDependencies(_manifestPath); if (dependencies.Length > 0) { foreach (string dpManifestPath in dependencies) { string dpLoadPath = AssetSystem.BundleServices.GetAssetBundleLoadPath(dpManifestPath); AssetLoaderBase dpLoader = AssetSystem.CreateLoaderInternal(dpLoadPath, dpManifestPath); _depends.Add(dpLoader); } } States = ELoaderStates.CheckDepends; } // 2. 检测所有依赖完成状态 if (States == ELoaderStates.CheckDepends) { foreach (var dpLoader in _depends) { if (dpLoader.IsDone() == false) { return; } } States = ELoaderStates.LoadFile; } // 3. 加载AssetBundle if (States == ELoaderStates.LoadFile) { #if UNITY_EDITOR // 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。 if (System.IO.File.Exists(LoadPath) == false) { MotionLog.Log(ELogLevel.Warning, $"Not found assetBundle file : {LoadPath}"); States = ELoaderStates.Fail; return; } #endif // Load assetBundle file if (AssetSystem.DecryptServices != null) { if (AssetSystem.DecryptServices.DecryptType == EDecryptMethod.GetDecryptOffset) { ulong offset = AssetSystem.DecryptServices.GetDecryptOffset(LoadPath); _cacheRequest = AssetBundle.LoadFromFileAsync(LoadPath, 0, offset); } else if (AssetSystem.DecryptServices.DecryptType == EDecryptMethod.GetDecryptBinary) { byte[] binary = AssetSystem.DecryptServices.GetDecryptBinary(LoadPath); _cacheRequest = AssetBundle.LoadFromMemoryAsync(binary); } else { throw new NotImplementedException($"{AssetSystem.DecryptServices.DecryptType}"); } } else { _cacheRequest = AssetBundle.LoadFromFileAsync(LoadPath); } States = ELoaderStates.CheckFile; } // 4. 检测AssetBundle加载结果 if (States == ELoaderStates.CheckFile) { if (_cacheRequest.isDone == false) { return; } CacheBundle = _cacheRequest.assetBundle; // Check error if (CacheBundle == null) { MotionLog.Log(ELogLevel.Warning, $"Failed to load assetBundle file : {LoadPath}"); States = ELoaderStates.Fail; } else { States = ELoaderStates.Success; } } }
public AssetBundleProvider(AssetLoaderBase owner, string assetName, System.Type assetType) : base(owner, assetName, assetType) { _loader = owner as AssetBundleLoader; }
public AssetDatabaseProvider(AssetLoaderBase owner, string assetName, System.Type assetType) : base(owner, assetName, assetType) { }