//========================================================== // // Copyright (c) Guangzhou Shixiang Technology Co.,Ltd. // All rights reserved. // //========================================================== using System.IO; using UnityEditor; using UnityEngine; using UnityEditor.XR.Management.Metadata; namespace GxrSdk.Editor { /// /// (gxrsdk_android_plugin.aar)插件校验 /// /// UnityPlayer的构造函数在Unity2022和之前的版本中是不兼容的,这样就导致了需要2份不同的 /// gxrsdk_android_plugin.aar(2022和2021(2022之前的是一样的)),aar存放在GxrSdk/Plugins/Android/gxrsdk_android_plugin中, /// 每次打开工程时需要判断当前编辑器版本把对应的aar文件复制出来 /// [InitializeOnLoad] public class GxrAndroidPluginVerify { /// /// 本地存放不同版本插件的路径 /// private static readonly string GxrSdkAndroidPluginFolder = "Assets/GxrSdk/Sdk/Plugins/Android/gxrsdk_android_plugin/"; /// /// 2022版本插件路径 /// private static readonly string AndroidPluginPath2022 = GxrSdkAndroidPluginFolder + "gxrsdk_android_plugin-release.aar.2022"; private static readonly string AndroidPluginPath2022XrSdk = GxrSdkAndroidPluginFolder + "gxrsdk_android_plugin-release.aar.2022.xrsdk"; /// /// 2021版本插件路径 /// private static readonly string AndroidPluginPath2021 = GxrSdkAndroidPluginFolder + "gxrsdk_android_plugin-release.aar.2021"; private static readonly string AndroidPluginPath2021XrSdk = GxrSdkAndroidPluginFolder + "gxrsdk_android_plugin-release.aar.2021.xrsdk"; /// /// 插件目标路径 /// private static readonly string AndroidPluginDestPath = "Assets/GxrSdk/Sdk/Plugins/Android/gxrsdk_android_plugin-release.aar"; static GxrAndroidPluginVerify() { EditorApplication.update += Update; } private static void Update() { EditorApplication.update -= Update; bool xrProviderToggled = IsGxrSdkXrProviderToggled(); string srcPath = null; #if UNITY_2022_1_OR_NEWER srcPath = xrProviderToggled ? AndroidPluginPath2022XrSdk : AndroidPluginPath2022; #else srcPath = xrProviderToggled ? AndroidPluginPath2021XrSdk : AndroidPluginPath2021; #endif if (string.IsNullOrEmpty(srcPath)) { Debug.LogError($"[GxrAndroidPluginVerify] The source path is null or empty."); return; } if (!File.Exists(srcPath)) { Debug.Log($"[GxrAndroidPluginVerify] Cannot find {srcPath}."); return; } if (File.Exists(AndroidPluginDestPath)) { File.Delete(AndroidPluginDestPath); } File.Copy(srcPath, AndroidPluginDestPath); } /// /// XR Plugin Management中是否勾选了GxrSdk xr plugin /// 勾选了就是要使用XrSdk模式,就得使用对应版本的gxrsdk_android_plugin.aar /// [已知问题]如果在修改了是否勾选后,没有其它修改也就没有重新触发这里进行重新检测,那么使用的aar就可能不是预期的版本。 /// /// private static bool IsGxrSdkXrProviderToggled() { // 正常的话应该使用typeof(GxrLoader).FullName去获取这个名字, // 暂时为了不引用插件模块,直接写名字在这里,注意名字要保持一致 string loaderFullName = "Unity.XR.GXRSDK.GxrLoader"; var toggled = XRPackageMetadataStore.IsLoaderAssigned(loaderFullName, BuildTargetGroup.Android); return toggled; } } }