Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. public class OVRResources : MonoBehaviour
  4. {
  5. private static AssetBundle resourceBundle;
  6. private static List<string> assetNames;
  7. public static UnityEngine.Object Load(string path)
  8. {
  9. if (Debug.isDebugBuild)
  10. {
  11. if(resourceBundle == null)
  12. {
  13. Debug.Log("[OVRResources] Resource bundle was not loaded successfully");
  14. return null;
  15. }
  16. var result = assetNames.Find(s => s.Contains(path.ToLower()));
  17. return resourceBundle.LoadAsset(result);
  18. }
  19. return Resources.Load(path);
  20. }
  21. public static T Load<T>(string path) where T : UnityEngine.Object
  22. {
  23. if (Debug.isDebugBuild)
  24. {
  25. if (resourceBundle == null)
  26. {
  27. Debug.Log("[OVRResources] Resource bundle was not loaded successfully");
  28. return null;
  29. }
  30. var result = assetNames.Find(s => s.Contains(path.ToLower()));
  31. return resourceBundle.LoadAsset<T>(result);
  32. }
  33. return Resources.Load<T>(path);
  34. }
  35. public static void SetResourceBundle(AssetBundle bundle)
  36. {
  37. resourceBundle = bundle;
  38. assetNames = new List<string>();
  39. assetNames.AddRange(resourceBundle.GetAllAssetNames());
  40. }
  41. }