XRLoaderInfo.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using UnityEngine.XR.Management;
  6. namespace UnityEditor.XR.Management
  7. {
  8. internal class XRLoaderInfo : IEquatable<XRLoaderInfo>
  9. {
  10. public Type loaderType;
  11. public string assetName;
  12. public XRLoader instance;
  13. public override bool Equals(object obj)
  14. {
  15. if (ReferenceEquals(null, obj)) return false;
  16. return obj is XRLoaderInfo && Equals((XRLoaderInfo)obj);
  17. }
  18. public override int GetHashCode()
  19. {
  20. unchecked
  21. {
  22. var hashCode = (loaderType != null ? loaderType.GetHashCode() : 0);
  23. hashCode = (hashCode * 397) ^ (instance != null ? instance.GetHashCode() : 0);
  24. return hashCode;
  25. }
  26. }
  27. public bool Equals(XRLoaderInfo other)
  28. {
  29. return other != null && Equals(loaderType, other.loaderType) && Equals(instance, other.instance);
  30. }
  31. static string[] s_LoaderBlackList = { "DummyLoader", "SampleLoader", "XRLoaderHelper" };
  32. internal static void GetAllKnownLoaderInfos(List<XRLoaderInfo> newInfos)
  33. {
  34. var loaderTypes = TypeLoaderExtensions.GetAllTypesWithInterface<XRLoader>();
  35. foreach (Type loaderType in loaderTypes)
  36. {
  37. if (loaderType.IsAbstract)
  38. continue;
  39. if (s_LoaderBlackList.Contains(loaderType.Name))
  40. continue;
  41. var assets = AssetDatabase.FindAssets(String.Format("t:{0}", loaderType));
  42. if (!assets.Any())
  43. {
  44. XRLoaderInfo info = new XRLoaderInfo();
  45. info.loaderType = loaderType;
  46. newInfos.Add(info);
  47. }
  48. else
  49. {
  50. foreach (var asset in assets)
  51. {
  52. string path = AssetDatabase.GUIDToAssetPath(asset);
  53. XRLoaderInfo info = new XRLoaderInfo();
  54. info.loaderType = loaderType;
  55. info.instance = AssetDatabase.LoadAssetAtPath(path, loaderType) as XRLoader;
  56. info.assetName = Path.GetFileNameWithoutExtension(path);
  57. newInfos.Add(info);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }