public void LoadAssetSync(System.Action <Object> onLoaded) { switch (LoadState) { case AssetLoadState.NotLoad: LoadState = AssetLoadState.Loading; assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(ABManifest.GetAssetBundleByAssetPath(assetPath)); var directDependencies = ABManifest.AssetBundleManifest.GetDirectDependencies(ABManifest.GetAssetNameByAssetPath(assetPath)); totalDirectDependecntCount = directDependencies.Length; foreach (var directDependent in directDependencies) { assetLoader.LoadAssetBundleSync(directDependent, DirectDependentCallback); } this.onLoaded += onLoaded; break; case AssetLoadState.Loading: case AssetLoadState.Loaded: this.onLoaded += onLoaded; break; case AssetLoadState.Unload: Debug.LogError("资源已卸载,任在加载。"); break; } }
public void LoadAsset() { switch (LoadState) { case AssetLoadState.NotLoad: LoadState = AssetLoadState.Loading; string abName = ABManifest.GetAssetBundleByAssetPath(assetPath); var assetBundle = AssetBundle.LoadFromFile(abName); if (loadType.Equals(typeAB) == false) { asset = assetBundle.LoadAsset(ABManifest.GetAssetNameByAssetPath(this.assetPath), loadType); } var directDependencies = ABManifest.AssetBundleManifest.GetDirectDependencies(System.IO.Path.GetFileName(abName)); totalDirectDependecntCount = directDependencies.Length; foreach (var directDependent in directDependencies) { assetLoader.LoadAssetBundle(directDependent); } LoadState = AssetLoadState.Loaded; break; case AssetLoadState.Loading: Debug.LogError("资源已在异步加载队列中,无法立即加载。AssetPath:" + this.assetPath); break; case AssetLoadState.Loaded: break; case AssetLoadState.Unload: Debug.LogError("资源已卸载,任在加载。"); break; case AssetLoadState.LoadError: break; } }