private void LoadAssetCacheDependenciesAsync <T>(BaseAssetCache Cache, Action <bool> Callback = null) where T : UnityEngine.Object { var LoadCompletedCount = 0; var Dependencies = Cache.GetAllDependencies(); if (Dependencies == null || Dependencies.Length == 0) { Callback?.Invoke(true); return; } foreach (var Dependency in Dependencies) { var AssetPath = Dependency; var AssetType = GetAssetTypeWithName <T>(AssetPath); LoadAssetAsync <T>(AssetType, AssetPath, (IsLoaded) => { if (!IsLoaded) { Callback?.Invoke(false); return; } Cache.AddDependencyCache(AssetCacheList_[AssetPath]); LoadCompletedCount++; if (LoadCompletedCount >= Dependencies.Length) { Callback?.Invoke(true); } }); } }
public void AddDependencyCache(BaseAssetCache Cache) { if (Cache == null) { return; } if (!DependenciesCache_.Contains(Cache)) { DependenciesCache_.Add(Cache); } }
private IEnumerator LoadAssetCacheAsync <T>(BaseAssetCache Cache) where T : UnityEngine.Object { if (!AssetCacheList_.ContainsKey(Cache.AssetPath)) { yield break; } yield return(TaskManager.WaitTask(Cache.LoadAsync())); if (!Cache.IsLoad) { AssetCacheList_.Remove(Cache.AssetPath); } }
public T CreateAssetSync <T>(AssetUri Uri) where T : UnityEngine.Object { var AssetType = GetAssetTypeWithName <T>(Uri.AssetPath); T Asset = null; var AssetName = Uri.AssetName; if (AssetType == AssetCacheType.Asset) { AssetName = $"{AssetName}_{typeof(T).Name.ToLower()}"; } BaseAssetCache Cache = null; if (!AssetCacheList_.ContainsKey(Uri.AssetPath)) { Cache = LoadAssetSync <UnityEngine.Object>(AssetType, Uri.AssetPath); } else { Cache = AssetCacheList_[Uri.AssetPath]; if (!Cache.IsLoad) { Cache.ForeCompleteAsync(); } } if (Cache != null) { Asset = Cache.CreateAsset(AssetName) as T; if (Asset != null) { if (!AssetPathCacheList_.ContainsKey(Asset.GetInstanceID())) { AssetPathCacheList_.Add(Asset.GetInstanceID(), Uri.AssetPath); } } else { LLogger.LWarning($"Can't Create Asset : {Uri}"); } } return(Asset); }
private BaseAssetCache LoadAssetCacheSync <T>(BaseAssetCache Cache) where T : UnityEngine.Object { if (!AssetCacheList_.ContainsKey(Cache.AssetPath)) { return(null); } Cache.LoadSync(); if (!Cache.IsLoad) { AssetCacheList_.Remove(Cache.AssetPath); Cache = null; } return(Cache); }
private void LoadAssetCacheDependenciesSync <T>(BaseAssetCache Cache) where T : UnityEngine.Object { var Dependencies = Cache.GetAllDependencies(); if (Dependencies == null || Dependencies.Length == 0) { return; } foreach (var Dependency in Dependencies) { var AssetPath = Dependency; var AssetType = GetAssetTypeWithName <T>(AssetPath); var DependencyAsset = LoadAssetSync <T>(AssetType, AssetPath); if (DependencyAsset != null) { Cache.AddDependencyCache(DependencyAsset); } } }
protected override BaseAssetCache CreateAssetCache <T>(AssetCacheType AssetType, string AssetPath) { BaseAssetCache Cache = null; switch (AssetType) { case AssetCacheType.Asset: Cache = new AssetBundleCache <UnityEngine.Object>(AssetType, AssetPath, Manifest_); break; case AssetCacheType.Prefab: Cache = new PrefabAssetBundleCache(AssetType, AssetPath, Manifest_); break; case AssetCacheType.Data: Cache = new DataAssetBundleCache(AssetType, AssetPath, Manifest_); break; default: break; } return(Cache); }