Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System.Collections;
  2. using UnityEngine;
  3.  
  4. public class BundleTest : MonoBehaviour
  5. {
  6.     public Object[] AllAssets;
  7.     public Object[] AllAssetsAnew;
  8.  
  9.     private IEnumerator Start()
  10.     {
  11.         //var bundlePath = Application.dataPath + "/../StreamingAssets/Windows/assets/content/characters/animations/character_animations.bundle"
  12.         //var bundlePath = Application.dataPath + "/../StreamingAssets/Windows/assets/content/weapons/animations/simple_animations.bundle";
  13.         var bundlePath = "E:/simple_animations.bundle";
  14.  
  15.         Debug.Log("Start loading bundle: " + Time.frameCount);
  16.  
  17.         var bundleLoading = AssetBundle.LoadFromFileAsync(bundlePath);
  18.  
  19.         yield return bundleLoading;
  20.  
  21.         Debug.Log("Bundle loaded: " + Time.frameCount);
  22.  
  23.         var bundle = bundleLoading.assetBundle;
  24.  
  25.         StartCoroutine(LoadAssets(bundle));
  26.  
  27.         yield return null;
  28.  
  29.         Debug.Log("Unloading bundle: " + Time.frameCount);
  30.  
  31.         bundle.Unload(unloadAllLoadedObjects: true);
  32.  
  33.         var nextBundleLoading = AssetBundle.LoadFromFileAsync(bundlePath);
  34.         yield return nextBundleLoading;
  35.  
  36.         Debug.Log("Loaded bundle anew: " + Time.frameCount);
  37.  
  38.         var nextAssetsLoading = nextBundleLoading.assetBundle.LoadAllAssetsAsync();
  39.         yield return nextAssetsLoading;
  40.  
  41.         Debug.Log("Loaded assets anew: " + Time.frameCount + " -- " + nextAssetsLoading.allAssets.Length);
  42.  
  43.         AllAssetsAnew = nextAssetsLoading.allAssets;
  44.     }
  45.  
  46.     private IEnumerator LoadAssets(AssetBundle bundle)
  47.     {
  48.         Debug.Log("Start loading assets: " + Time.frameCount);
  49.  
  50.         var assetsLoading = bundle.LoadAllAssetsAsync();
  51.         yield return assetsLoading;
  52.  
  53.         Debug.Log("Assets loaded: " + Time.frameCount + " -- " + assetsLoading.allAssets.Length);
  54.  
  55.         AllAssets = assetsLoading.allAssets;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement