OVRResources.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. }