GHZGlassSDKSettings.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reflection;
  5. using UnityEditor;
  6. using UnityEngine;
  7. using UnityEngine.XR;
  8. using UnityEditor.PackageManager;
  9. using UnityEditor.PackageManager.Requests;
  10. using System.Threading;
  11. using System.Collections;
  12. using static UnityEditor.PlayerSettings;
  13. public class GHZGlassSDKSettings
  14. {
  15. [MenuItem("GHZ/GHZGlassSDK/SDK_DreamGlass")]
  16. public static void DreamGlassInit()
  17. {
  18. Debug.Log("DreamGlassInit");
  19. DreamGlassSet();
  20. PlayerSet("DreamGlass");
  21. }
  22. [MenuItem("GHZ/GHZGlassSDK/SDK_Phone")]
  23. public static void PhoneInit()
  24. {
  25. Debug.Log("Phone");
  26. PhoneSet();
  27. PlayerSet("Phone");
  28. }
  29. [MenuItem("GHZ/GHZGlassSDK/SDK_Rhinox")]
  30. public static void RhinoxInit()
  31. {
  32. Debug.Log("RhinoxInit");
  33. RhinoxSet();
  34. PlayerSet("Rhinox");
  35. }
  36. [MenuItem("GHZ/GHZGlassSDK/SDK_Nreal")]
  37. public static void NrealInit()
  38. {
  39. Debug.Log("NrealInit");
  40. NrealSet();
  41. PlayerSet("Nreal");
  42. }
  43. [MenuItem("GHZ/GHZGlassSDK/SDK_A01")]
  44. public static void A01Init()
  45. {
  46. Debug.Log("A01Init");
  47. A01Set();
  48. PlayerSet("A01");
  49. }
  50. static void DreamGlassSet()
  51. {
  52. PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel26;
  53. PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
  54. PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6);
  55. PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, true);
  56. PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false);
  57. PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 });
  58. PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
  59. Android.targetArchitectures = AndroidArchitecture.ARMv7;
  60. PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
  61. EditorSettings.serializationMode = SerializationMode.ForceText;
  62. Type playerSettingsType = typeof(PlayerSettings);
  63. MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
  64. int staticBatchingValue = 1;
  65. int dynamicBatchingValue = 1;
  66. object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue };
  67. method.Invoke(null, param);
  68. QualitySettings.SetQualityLevel(2);
  69. }
  70. static void PhoneSet()
  71. {
  72. PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel28;
  73. PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
  74. PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6);
  75. PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, true);
  76. PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false);
  77. PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 });
  78. PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft;
  79. EditorSettings.serializationMode = SerializationMode.ForceText;
  80. PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
  81. Android.targetArchitectures = AndroidArchitecture.ARM64;
  82. Type playerSettingsType = typeof(PlayerSettings);
  83. MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
  84. int staticBatchingValue = 1;
  85. int dynamicBatchingValue = 1;
  86. object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue };
  87. method.Invoke(null, param);
  88. QualitySettings.SetQualityLevel(2);
  89. }
  90. static void RhinoxSet()
  91. {
  92. PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel28;
  93. PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
  94. PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6);
  95. PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, true);
  96. PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false);
  97. PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 });
  98. PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
  99. EditorSettings.serializationMode = SerializationMode.ForceText;
  100. PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
  101. Android.targetArchitectures = AndroidArchitecture.ARM64;
  102. Type playerSettingsType = typeof(PlayerSettings);
  103. MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
  104. int staticBatchingValue = 1;
  105. int dynamicBatchingValue = 1;
  106. object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue };
  107. method.Invoke(null, param);
  108. QualitySettings.SetQualityLevel(2);
  109. }
  110. static void NrealSet()
  111. {
  112. PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel28;
  113. PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
  114. PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6);
  115. PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, true);
  116. PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false);
  117. PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 });
  118. PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
  119. Android.targetArchitectures = AndroidArchitecture.ARM64;
  120. PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
  121. EditorSettings.serializationMode = SerializationMode.ForceText;
  122. Type playerSettingsType = typeof(PlayerSettings);
  123. MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
  124. int staticBatchingValue = 1;
  125. int dynamicBatchingValue = 1;
  126. object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue };
  127. method.Invoke(null, param);
  128. QualitySettings.SetQualityLevel(2);
  129. }
  130. static void A01Set()
  131. {
  132. PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel26;
  133. PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
  134. PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6);
  135. PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, false);
  136. PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false);
  137. PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 });
  138. PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
  139. Android.targetArchitectures = AndroidArchitecture.ARMv7;
  140. PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft;
  141. EditorSettings.serializationMode = SerializationMode.ForceText;
  142. Type playerSettingsType = typeof(PlayerSettings);
  143. MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
  144. int staticBatchingValue = 1;
  145. int dynamicBatchingValue = 1;
  146. object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue };
  147. method.Invoke(null, param);
  148. QualitySettings.SetQualityLevel(2);
  149. }
  150. IEnumerator MyCoroutine()
  151. {
  152. Debug.Log("Coroutine started");
  153. yield return new WaitForSeconds(2);
  154. Debug.Log("Coroutine finished");
  155. }
  156. static void PlayerSet(string type)
  157. {
  158. GHZSDKSettings.isNewSDK=false;
  159. GHZSDKSettings.loadSDKType = type;
  160. try
  161. {
  162. FileUtil.DeleteFileOrDirectory("Assets/GHZSDK");
  163. }
  164. catch
  165. {
  166. }
  167. EditorApplication.delayCall += () =>
  168. {
  169. System.Threading.Thread.Sleep(1000);
  170. Debug.Log("正在卸载插件:jh.xr.engine");
  171. RemoveRequest rr = Client.Remove("jh.xr.engine");
  172. while (!rr.IsCompleted)
  173. {
  174. // 等待PackageManager请求完成
  175. }
  176. Directory.CreateDirectory("Assets/GHZSDK");
  177. Debug.Log("卸载 完成 :jh.xr.engine");
  178. rr = Client.Remove("com.ximmerse.xr");
  179. Debug.Log("正在卸载插件:com.ximmerse.xr");
  180. while (!rr.IsCompleted)
  181. {
  182. // 等待PackageManager请求完成
  183. }
  184. Debug.Log("卸载 完成 :com.ximmerse.xr");
  185. string[] strlist = new string[4];
  186. strlist[0] = "com.unity.xr.arcore@4.2.8";
  187. strlist[1] = "https://gogs.ghz-tech.com:8843/GHzGlass/GHZClassSDKXR.git#XRSDK_" + type;
  188. strlist[2] = "com.unity.xr.arfoundation@4.2.8";
  189. strlist[3] = "com.unity.xr.openxr@1.5.3";
  190. AddAndRemoveRequest rest = Client.AddAndRemove(strlist);
  191. Debug.Log("正在加载插件包:" + strlist.ToString());
  192. while (!rest.IsCompleted)
  193. {
  194. // 等待PackageManager请求完成
  195. }
  196. // ListRequest request = Client.List(true);
  197. // LoadSamplesSettings.PlayerShadowSDKSamplesSet(request);
  198. };
  199. }
  200. }