IEnumerator _LoadDependenceInfo() { string filename = Path.Combine(AssetBundleLoader.STREAMING_ASSET_PATH, AssetBundleLoader.GetPlatformFolderForAssetBundles()); WWW www = new WWW(filename); yield return(www); if (www.error != null) { Debug.LogWarning(www.error); www.Dispose(); yield break; } AssetBundle assetBundle = AssetBundle.LoadFromMemory(www.bytes); AssetBundleManifest manifest = assetBundle.LoadAsset("assetbundlemanifest") as AssetBundleManifest; string[] assetBundleNames = manifest.GetAllAssetBundles(); foreach (string assetBundleName in assetBundleNames) { string[] dependencies = manifest.GetAllDependencies(assetBundleName); s_AssetBundleDependencies.Add(assetBundleName, dependencies); } www.Dispose(); assetBundle.Unload(true); }
// load assetbuddle // ref++ public static AssetBundle LoadAssetBundle(string assetBundleName) { assetBundleName = assetBundleName.ToLower(); assetBundleName += ".unity3d"; if (s_AssetBundleDependencies.ContainsKey(assetBundleName)) { string[] dependencies = s_AssetBundleDependencies [assetBundleName]; foreach (string dependency in dependencies) { if (s_LoadedAssetBundles.ContainsKey(dependency)) { s_LoadedAssetBundles [dependency].refCount++; } else { // 加载 //string filename = Path.Combine(Application.persistentDataPath, dependency); string filename = Path.Combine(Application.streamingAssetsPath, dependency); AssetBundle ab = AssetBundle.LoadFromFile(filename); if (ab) { Debug.LogFormat("AssetBundle(Dependency) loaded : {0}", dependency); LoadedAssetBundle loadedAssetBundle = new LoadedAssetBundle(ab); s_LoadedAssetBundles.Add(dependency, loadedAssetBundle); continue; } } } } if (s_LoadedAssetBundles.ContainsKey(assetBundleName)) { s_LoadedAssetBundles [assetBundleName].refCount++; return(s_LoadedAssetBundles [assetBundleName].assetBundle); } else { // 加载 //string filename = Path.Combine(Application.persistentDataPath, assetBundleName); string filename = Path.Combine(Application.streamingAssetsPath, AssetBundleLoader.GetPlatformFolderForAssetBundles()); filename = Path.Combine(filename, assetBundleName); AssetBundle ab = AssetBundle.LoadFromFile(filename); if (ab) { Debug.LogFormat("AssetBundle loaded : {0}", assetBundleName); LoadedAssetBundle loadedAssetBundle = new LoadedAssetBundle(ab); s_LoadedAssetBundles.Add(assetBundleName, loadedAssetBundle); return(s_LoadedAssetBundles [assetBundleName].assetBundle); } return(null); } }
void Awake() { // download path for platforms s_BaseDownloadingURL += AssetBundleLoader.GetPlatformFolderForAssetBundles(); }