Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- public class BundleTest : MonoBehaviour
- {
- public Object[] AllAssets;
- public Object[] AllAssetsAnew;
- private IEnumerator Start()
- {
- //var bundlePath = Application.dataPath + "/../StreamingAssets/Windows/assets/content/characters/animations/character_animations.bundle"
- //var bundlePath = Application.dataPath + "/../StreamingAssets/Windows/assets/content/weapons/animations/simple_animations.bundle";
- var bundlePath = "E:/simple_animations.bundle";
- Debug.Log("Start loading bundle: " + Time.frameCount);
- var bundleLoading = AssetBundle.LoadFromFileAsync(bundlePath);
- yield return bundleLoading;
- Debug.Log("Bundle loaded: " + Time.frameCount);
- var bundle = bundleLoading.assetBundle;
- StartCoroutine(LoadAssets(bundle));
- yield return null;
- Debug.Log("Unloading bundle: " + Time.frameCount);
- bundle.Unload(unloadAllLoadedObjects: true);
- var nextBundleLoading = AssetBundle.LoadFromFileAsync(bundlePath);
- yield return nextBundleLoading;
- Debug.Log("Loaded bundle anew: " + Time.frameCount);
- var nextAssetsLoading = nextBundleLoading.assetBundle.LoadAllAssetsAsync();
- yield return nextAssetsLoading;
- Debug.Log("Loaded assets anew: " + Time.frameCount + " -- " + nextAssetsLoading.allAssets.Length);
- AllAssetsAnew = nextAssetsLoading.allAssets;
- }
- private IEnumerator LoadAssets(AssetBundle bundle)
- {
- Debug.Log("Start loading assets: " + Time.frameCount);
- var assetsLoading = bundle.LoadAllAssetsAsync();
- yield return assetsLoading;
- Debug.Log("Assets loaded: " + Time.frameCount + " -- " + assetsLoading.allAssets.Length);
- AllAssets = assetsLoading.allAssets;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement