Documentation for the Unity C# Library
Loading...
Searching...
No Matches
PixoVREditorCommands.cs
Go to the documentation of this file.
1#if UNITY_EDITOR
2using System.IO;
3using UnityEditor;
4using UnityEngine;
5using UnityEditor.PackageManager;
6using UnityEditor.PackageManager.Requests;
7using UnityEngine.UIElements;
8using System.Threading.Tasks;
9
10public static class PixoVREditorCommands
11{
12 [MenuItem("PixoVR/Setup")]
13 public static void PixoVRPluginSetup()
14 {
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");
23#else
24 sourceManifestPath = Path.Combine(pluginPath, "Editor/Others/AndroidManifest_Main.xml");
25 sourceJavaUtilsPath = Path.Combine(pluginPath, "Editor/Others/PixoUtils_Main.java");
26#endif
27 File.Copy(sourceManifestPath, destinationManifestPath, true);
28 File.Copy(sourceJavaUtilsPath, destinationJavaUtilsPath, true);
29 AssetDatabase.Refresh();
30 }
31
32 [MenuItem("PixoVR/Update Plugin Version")]
33 public static async Task PixoVRVersionUpdate()
34 {
35 await VersionUpdate();
36
37 }
38
39 public static async Task VersionUpdate()
40 {
41 var packageList = Client.List(true);
42
43 while (!packageList.IsCompleted)
44 {
45 await Task.Delay(500);
46 }
47
48 if (packageList.Status != StatusCode.Success)
49 {
50 Debug.Log("Failed to get a list of packages.");
51 return;
52 }
53 else
54 {
55 Debug.Log("Was successful in finding all of the packages.");
56 }
57
58 string packageVersion = "", packageAssetPath = "";
59 foreach (var package in packageList.Result)
60 {
61 if (package.name.Equals("com.pixovr.apexunitysdk"))
62 {
63 Debug.Log($"Package info: {package.name} v{package.version} - {package.assetPath}");
64 packageVersion = package.version;
65 packageAssetPath = package.assetPath;
66 }
67 }
68
69 if(string.IsNullOrEmpty(packageVersion))
70 {
71 Debug.LogError($"Failed to find the PixoVR SDK package or it did not contain a valid version.");
72 return;
73 }
74
75 if (string.IsNullOrEmpty(packageAssetPath))
76 {
77 Debug.LogError($"Failed to find the PixoVR SDK package location.");
78 return;
79 }
80
81 string projectAssetsPath = Application.dataPath;
82
83 // Navigate up one level to get the project root path
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");
87
88 Debug.Log($"Generated file {generatedUtilsFile}");
89
90 if(File.Exists(generatedPixoUtils))
91 {
92 File.Delete(generatedPixoUtils);
93 }
94
95 File.WriteAllText(generatedUtilsFile, generatedPixoUtils);
96
97 AssetDatabase.Refresh();
98
99 return;
100 }
101
102 private static string FindPluginPath()
103 {
104 string[] guids = AssetDatabase.FindAssets("PixoVRPreBuilder t:Script");
105 if (guids.Length > 0)
106 {
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);
111 return path;
112 }
113
114 return null;
115 }
116}
117#endif