5using UnityEditor.PackageManager;
6using UnityEditor.PackageManager.Requests;
7using UnityEngine.UIElements;
8using System.Threading.Tasks;
10public static class PixoVREditorCommands
12 [MenuItem(
"PixoVR/Setup")]
13 public static void PixoVRPluginSetup()
15 string pluginPath = FindPluginPath();
16 string destinationManifestPath = Path.Combine(pluginPath,
"Plugins/Android/AndroidManifest.xml");
17 string destinationJavaUtilsPath = Path.Combine(pluginPath,
"Plugins/Android/PixoUtils.java");
18 string sourceManifestPath =
"";
19 string sourceJavaUtilsPath =
"";
20#if UNITY_6000_0_OR_NEWER
21 sourceManifestPath = Path.Combine(pluginPath,
"Editor/Others/AndroidManifest_Game.xml");
22 sourceJavaUtilsPath = Path.Combine(pluginPath,
"Editor/Others/PixoUtils_Game.java");
24 sourceManifestPath = Path.Combine(pluginPath,
"Editor/Others/AndroidManifest_Main.xml");
25 sourceJavaUtilsPath = Path.Combine(pluginPath,
"Editor/Others/PixoUtils_Main.java");
27 File.Copy(sourceManifestPath, destinationManifestPath,
true);
28 File.Copy(sourceJavaUtilsPath, destinationJavaUtilsPath,
true);
29 AssetDatabase.Refresh();
32 [MenuItem(
"PixoVR/Update Plugin Version")]
33 public static async Task PixoVRVersionUpdate()
35 await VersionUpdate();
39 public static async Task VersionUpdate()
41 var packageList = Client.List(
true);
43 while (!packageList.IsCompleted)
45 await Task.Delay(500);
48 if (packageList.Status != StatusCode.Success)
50 Debug.Log(
"Failed to get a list of packages.");
55 Debug.Log(
"Was successful in finding all of the packages.");
58 string packageVersion =
"", packageAssetPath =
"";
59 foreach (var package
in packageList.Result)
61 if (package.name.Equals(
"com.pixovr.apexunitysdk"))
63 Debug.Log($
"Package info: {package.name} v{package.version} - {package.assetPath}");
64 packageVersion = package.version;
65 packageAssetPath = package.assetPath;
69 if(
string.IsNullOrEmpty(packageVersion))
71 Debug.LogError($
"Failed to find the PixoVR SDK package or it did not contain a valid version.");
75 if (
string.IsNullOrEmpty(packageAssetPath))
77 Debug.LogError($
"Failed to find the PixoVR SDK package location.");
81 string projectAssetsPath = Application.dataPath;
84 string projectRootPath = Directory.GetParent(projectAssetsPath).FullName;
85 string generatedPixoUtils = $
"namespace PixoVR.Apex.Utils {{ public static partial class ApexUtils {{ public static string SDKVersion => \"{packageVersion}\"; }} }}";
86 string generatedUtilsFile = Path.Combine(projectRootPath, packageAssetPath,
"Runtime/SDK/ApexUtilsGenerated.cs");
88 Debug.Log($
"Generated file {generatedUtilsFile}");
90 if(File.Exists(generatedPixoUtils))
92 File.Delete(generatedPixoUtils);
95 File.WriteAllText(generatedUtilsFile, generatedPixoUtils);
97 AssetDatabase.Refresh();
102 private static string FindPluginPath()
104 string[] guids = AssetDatabase.FindAssets(
"PixoVRPreBuilder t:Script");
105 if (guids.Length > 0)
107 string path = AssetDatabase.GUIDToAssetPath(guids[0]);
108 string[] pathParts = path.Split(
"/");
109 path = Path.Combine(pathParts[0], pathParts[1]);
110 Debug.Log(
"Prebuild Script path: " + path);