using System; using System.Collections.Generic; using System.IO; using System.Reflection; using UnityEditor; using UnityEngine; using UnityEngine.XR; using UnityEditor.PackageManager; using UnityEditor.PackageManager.Requests; using System.Threading; using System.Collections; using static UnityEditor.PlayerSettings; public class GHZSDKSettings { [MenuItem("GHZ/GHZSDK/SDK_DreamGlass")] public static void DreamGlassInit() { Debug.Log("DreamGlassInit"); DreamGlassSet(); PlayerSet("DreamGlass"); } [MenuItem("GHZ/GHZSDK/SDK_Phone")] public static void PhoneInit() { Debug.Log("Phone"); PhoneSet(); PlayerSet("Phone"); } [MenuItem("GHZ/GHZSDK/SDK_Rhinox")] public static void RhinoxInit() { Debug.Log("RhinoxInit"); RhinoxSet(); PlayerSet("Rhinox"); } [MenuItem("GHZ/GHZSDK/SDK_Nreal")] public static void NrealInit() { Debug.Log("NrealInit"); NrealSet(); PlayerSet("Nreal"); } [MenuItem("GHZ/GHZSDK/SDK_A01")] public static void A01Init() { Debug.Log("A01Init"); A01Set(); PlayerSet("A01"); } static void DreamGlassSet() { PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel26; PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto; PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6); PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, true); PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false); PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 }); PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP); Android.targetArchitectures = AndroidArchitecture.ARMv7; PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait; EditorSettings.serializationMode = SerializationMode.ForceText; Type playerSettingsType = typeof(PlayerSettings); MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static); int staticBatchingValue = 1; int dynamicBatchingValue = 1; object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue }; method.Invoke(null, param); QualitySettings.SetQualityLevel(2); } static void PhoneSet() { PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel28; PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto; PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6); PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, true); PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false); PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 }); PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft; EditorSettings.serializationMode = SerializationMode.ForceText; PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP); Android.targetArchitectures = AndroidArchitecture.ARM64; Type playerSettingsType = typeof(PlayerSettings); MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static); int staticBatchingValue = 1; int dynamicBatchingValue = 1; object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue }; method.Invoke(null, param); QualitySettings.SetQualityLevel(2); } static void RhinoxSet() { PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel28; PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto; PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6); PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, true); PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false); PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 }); PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait; EditorSettings.serializationMode = SerializationMode.ForceText; PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP); Android.targetArchitectures = AndroidArchitecture.ARM64; Type playerSettingsType = typeof(PlayerSettings); MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static); int staticBatchingValue = 1; int dynamicBatchingValue = 1; object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue }; method.Invoke(null, param); QualitySettings.SetQualityLevel(2); } static void NrealSet() { PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel28; PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto; PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6); PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, true); PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false); PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 }); PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP); Android.targetArchitectures = AndroidArchitecture.ARM64; PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait; EditorSettings.serializationMode = SerializationMode.ForceText; Type playerSettingsType = typeof(PlayerSettings); MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static); int staticBatchingValue = 1; int dynamicBatchingValue = 1; object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue }; method.Invoke(null, param); QualitySettings.SetQualityLevel(2); } static void A01Set() { PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel26; PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto; PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6); PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, false); PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false); PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 }); PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP); Android.targetArchitectures = AndroidArchitecture.ARM64; PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft; EditorSettings.serializationMode = SerializationMode.ForceText; Type playerSettingsType = typeof(PlayerSettings); MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static); int staticBatchingValue = 1; int dynamicBatchingValue = 1; object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue }; method.Invoke(null, param); QualitySettings.SetQualityLevel(2); } IEnumerator MyCoroutine() { Debug.Log("Coroutine started"); yield return new WaitForSeconds(2); Debug.Log("Coroutine finished"); } public static string loadSDKType; public static bool isNewSDK; static void PlayerSet(string type) { isNewSDK = true; loadSDKType = type; try { FileUtil.DeleteFileOrDirectory("Assets/GHZSDK"); } catch { } RemoveRequest rr = Client.Remove("jh.xr.engine"); while (!rr.IsCompleted) { // yield return null; // 等待PackageManager请求完成 } Directory.CreateDirectory("Assets/GHZSDK"); Debug.Log("卸载 完成 :jh.xr.engine"); rr = Client.Remove("com.ximmerse.xr"); Debug.Log("正在卸载插件:com.ximmerse.xr"); while (!rr.IsCompleted) { // yield return null; // 等待PackageManager请求完成 } Debug.Log("卸载 完成 :com.ximmerse.xr"); string[] strlist = new string[4]; strlist[0] = "com.unity.xr.arcore@4.2.8"; strlist[1] = "https://gogs.ghz-tech.com:8843/GHzGlass/GHZSDKXR.git#XRSDK_" + GHZSDKSettings.loadSDKType; strlist[2] = "com.unity.xr.arfoundation@4.2.8"; strlist[3] = "com.unity.xr.openxr@1.5.3"; AddAndRemoveRequest rest = Client.AddAndRemove(strlist); Debug.Log("正在加载插件包:" + strlist.ToString()); while (!rest.IsCompleted) { // yield return null; } //pd.PlayerSet(type); } }