SDKEditorUtility.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using UnityEditor.PackageManager.Requests;
  6. using UnityEditor.PackageManager;
  7. using PackageInfo = UnityEditor.PackageManager.PackageInfo;
  8. using System;
  9. using System.IO;
  10. namespace Ximmerse.XR
  11. {
  12. /// <summary>
  13. /// SDK editor utility.
  14. /// </summary>
  15. public static class SDKEditorUtility
  16. {
  17. /// <summary>
  18. /// The asset path of the ximmerse XR plugin.
  19. /// </summary>
  20. public static string kPluginFolderAssetPath
  21. {
  22. get; private set;
  23. }
  24. /// <summary>
  25. /// The absolute path of the ximmerse XR plugin.
  26. /// </summary>
  27. public static string kPluginFolderResolvePath
  28. {
  29. get; private set;
  30. }
  31. /// <summary>
  32. /// The asset path of the ximmerse XR plugin's tracking profile
  33. /// </summary>
  34. public static string kPluginTrackingProfilePath
  35. {
  36. get; private set;
  37. }
  38. public const string kXimmerseXRPackageName = "com.ximmerse.xr";
  39. /// <summary>
  40. /// The tracking profile's relative path to plugin root
  41. /// </summary>
  42. public const string kTrackingProfileRelativePath = "/TrackingProfiles";
  43. /// <summary>
  44. /// The tracking profile's absolute path.
  45. /// </summary>
  46. public static string kTrackingProfileResolvePath
  47. {
  48. get => kPluginFolderResolvePath + kTrackingProfileRelativePath;
  49. }
  50. [InitializeOnLoadMethod]
  51. static void InitializeEditor()
  52. {
  53. var pkg = GetXimmerseXRSDKPackageInfo();
  54. if (pkg != null)
  55. {
  56. kPluginFolderAssetPath = pkg.assetPath;
  57. kPluginFolderResolvePath = pkg.resolvedPath;
  58. kPluginTrackingProfilePath = pkg.assetPath + kTrackingProfileRelativePath;
  59. //Debug.LogFormat("Ximmerse XR plugin path : {0}, resolve path : {1}, tracking profile path: {2}", pkg.assetPath, pkg.resolvedPath, kPluginTrackingProfilePath);
  60. }
  61. }
  62. /// <summary>
  63. /// Gets the Ximmerse XR package info.
  64. /// </summary>
  65. /// <returns></returns>
  66. public static PackageInfo GetXimmerseXRSDKPackageInfo()
  67. {
  68. ListRequest list = Client.List(offlineMode: true);
  69. while (!list.IsCompleted)
  70. {
  71. }
  72. foreach (PackageInfo packageInfo in list.Result)
  73. {
  74. if (packageInfo.name.Equals(kXimmerseXRPackageName, StringComparison.OrdinalIgnoreCase))
  75. {
  76. return packageInfo;
  77. }
  78. }
  79. return default(PackageInfo);
  80. }
  81. }
  82. }