using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using UnityEditor.PackageManager.Requests; using UnityEditor.PackageManager; using PackageInfo = UnityEditor.PackageManager.PackageInfo; using System; using System.IO; namespace Ximmerse.XR { /// /// SDK editor utility. /// public static class SDKEditorUtility { /// /// The asset path of the ximmerse XR plugin. /// public static string kPluginFolderAssetPath { get; private set; } /// /// The absolute path of the ximmerse XR plugin. /// public static string kPluginFolderResolvePath { get; private set; } /// /// The asset path of the ximmerse XR plugin's tracking profile /// public static string kPluginTrackingProfilePath { get; private set; } public const string kXimmerseXRPackageName = "com.ximmerse.xr"; /// /// The tracking profile's relative path to plugin root /// public const string kTrackingProfileRelativePath = "/TrackingProfiles"; /// /// The tracking profile's absolute path. /// public static string kTrackingProfileResolvePath { get => kPluginFolderResolvePath + kTrackingProfileRelativePath; } [InitializeOnLoadMethod] static void InitializeEditor() { var pkg = GetXimmerseXRSDKPackageInfo(); if (pkg != null) { kPluginFolderAssetPath = pkg.assetPath; kPluginFolderResolvePath = pkg.resolvedPath; kPluginTrackingProfilePath = pkg.assetPath + kTrackingProfileRelativePath; //Debug.LogFormat("Ximmerse XR plugin path : {0}, resolve path : {1}, tracking profile path: {2}", pkg.assetPath, pkg.resolvedPath, kPluginTrackingProfilePath); } } /// /// Gets the Ximmerse XR package info. /// /// public static PackageInfo GetXimmerseXRSDKPackageInfo() { ListRequest list = Client.List(offlineMode: true); while (!list.IsCompleted) { } foreach (PackageInfo packageInfo in list.Result) { if (packageInfo.name.Equals(kXimmerseXRPackageName, StringComparison.OrdinalIgnoreCase)) { return packageInfo; } } return default(PackageInfo); } } }