Пример #1
0
        private bool SetEnableLoderForTarget(BuildTargetGroup buildTargetGroup, bool enable)
        {
            if (buildTargetGroup != BuildTargetGroup.Standalone && buildTargetGroup != BuildTargetGroup.WSA)
            {
                return(false);
            }

            XRGeneralSettings settings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(buildTargetGroup);

            if (settings == null)
            {
                return(false);
            }

            bool ret = false;

            if (enable)
            {
                ret = XRPackageMetadataStore.AssignLoader(settings.Manager, typeof(WindowsMRLoader).Name, buildTargetGroup);
            }
            else
            {
                ret = XRPackageMetadataStore.RemoveLoader(settings.Manager, typeof(WindowsMRLoader).Name, buildTargetGroup);
            }

            return(ret);
        }
Пример #2
0
    internal void TeardownXR()
    {
        XRGeneralSettings.Instance.Manager.StopSubsystems();
        XRGeneralSettings.Instance.Manager.DeinitializeLoader();
#if UNITY_EDITOR
        XRPackageMetadataStore.RemoveLoader(XRGeneralSettings.Instance.Manager, typeof(WindowsMRLoader).Name, BuildTargetGroup.Standalone);
#endif
    }
    public void UpdateConfig()
    {
        EditorUserBuildSettings.development = DevelopmentBuild;
        AppConfig.IsDebug       = DevelopmentBuild;
        AppConfig.IsHotfix      = IsHotfix;
        AppConfig.IsLoadAB      = IsLoadAB;
        AppConfig.IsProServer   = IsProServer;
        AppConfig.RunXLua       = RunXLuaScripts;
        AppConfig.AppFrameRate  = AppFrameRate;
        AppConfig.TargetPackage = ApkTarget;

        EditorUtility.SetDirty(AppConfig);

        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
        {
            EditorUserBuildSettings.exportAsGoogleAndroidProject = NativeApp;

            XRGeneralSettings androidXRSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.Android);

            if (androidXRSettings == null)
            {
                var assignedSettings = ScriptableObject.CreateInstance <XRManagerSettings>() as XRManagerSettings;
                androidXRSettings.AssignedSettings = assignedSettings;
                EditorUtility.SetDirty(androidXRSettings); // Make sure this gets picked up for serialization later.
            }

            //取消当前选择的
            IReadOnlyList <XRLoader> list = androidXRSettings.Manager.activeLoaders;
            int hasCount = list.Count;
            //Debug.Log(hasCount);
            for (int i = 0; i < hasCount; i++)
            {
                string nameTemp = list[0].GetType().FullName;
                Debug.Log("disable xr plug:" + nameTemp);
                XRPackageMetadataStore.RemoveLoader(androidXRSettings.Manager, nameTemp, BuildTargetGroup.Android);
            }
            androidXRSettings.InitManagerOnStart = false;
            if (ApkTarget == TargetPackage.Pico)
            {
                androidXRSettings.InitManagerOnStart = true;
                //启用
                string loaderTypeName = "Unity.XR.PXR.PXR_Loader";
                XRPackageMetadataStore.AssignLoader(androidXRSettings.Manager, loaderTypeName, BuildTargetGroup.Android);
            }
            EditorUtility.SetDirty(androidXRSettings); // Make sure this gets picked up for serialization later.
        }
        AssetDatabase.Refresh();
    }
Пример #4
0
        private static void SetXRPluginsEnabled(bool enabled)
        {
            XRGeneralSettings SetForBuildTarget(XRGeneralSettingsPerBuildTarget bts, BuildTargetGroup btg, string btgName)
            {
                XRGeneralSettings btSettings = bts.SettingsForBuildTarget(btg);

                if (btSettings == null)
                {
                    btSettings              = ScriptableObject.CreateInstance <XRGeneralSettings>();
                    btSettings.name         = btgName + " Settings";
                    btSettings.Manager      = ScriptableObject.CreateInstance <XRManagerSettings>();
                    btSettings.Manager.name = btgName + " Providers";
                    AssetDatabase.AddObjectToAsset(btSettings, bts);
                    AssetDatabase.AddObjectToAsset(btSettings.Manager, bts);
                    bts.SetSettingsForBuildTarget(btg, btSettings);
                }

                return(btSettings);
            }

            if (!EditorBuildSettings.TryGetConfigObject(XRGeneralSettings.k_SettingsKey, out XRGeneralSettingsPerBuildTarget buildTargetSettings))
            {
                if (!AssetDatabase.IsValidFolder("Assets/XR"))
                {
                    AssetDatabase.CreateFolder("Assets", "XR");
                }

                buildTargetSettings = ScriptableObject.CreateInstance <XRGeneralSettingsPerBuildTarget>();
                AssetDatabase.CreateAsset(buildTargetSettings, "Assets/XR/XRGeneralSettings.asset");
                EditorBuildSettings.AddConfigObject(XRGeneralSettings.k_SettingsKey, buildTargetSettings, true);
            }

            XRGeneralSettings standaloneSettings = SetForBuildTarget(buildTargetSettings, BuildTargetGroup.Standalone, "Standalone");
            XRGeneralSettings androidSettings    = SetForBuildTarget(buildTargetSettings, BuildTargetGroup.Android, "Android");

            // Enable Oculus XR plugin
            if (enabled)
            {
                XRPackageMetadataStore.AssignLoader(standaloneSettings.Manager, "Unity.XR.Oculus.OculusLoader", BuildTargetGroup.Standalone);
                XRPackageMetadataStore.AssignLoader(androidSettings.Manager, "Unity.XR.Oculus.OculusLoader", BuildTargetGroup.Android);
            }
            else
            {
                XRPackageMetadataStore.RemoveLoader(standaloneSettings.Manager, "Unity.XR.Oculus.OculusLoader", BuildTargetGroup.Standalone);
                XRPackageMetadataStore.RemoveLoader(androidSettings.Manager, "Unity.XR.Oculus.OculusLoader", BuildTargetGroup.Android);
            }
        }
Пример #5
0
        public void TestLoaderRemoval()
        {
            Assert.IsNotNull(m_Settings);
            string loaderTypeName = LoaderTypeNameForBuildTarget(BuildTargetGroup.Standalone);

            Assert.IsFalse(String.IsNullOrEmpty(loaderTypeName));
            AssignLoaderToSettings(m_Settings, loaderTypeName);
            Assert.IsTrue(SettingsHasLoaderOfType(m_Settings, loaderTypeName));

            Assert.IsTrue(XRPackageMetadataStore.RemoveLoader(m_Settings, loaderTypeName, BuildTargetGroup.Standalone));

            m_Settings = null;
            var settings = EditorUtilities.GetInstanceOfTypeFromAssetDatabase <XRManagerSettings>();

            m_Settings = settings as XRManagerSettings;
            Assert.IsNotNull(m_Settings);
            Assert.IsFalse(SettingsHasLoaderOfType(m_Settings, loaderTypeName));

            Assert.IsTrue(TestLoaderBase.WasUnassigned);
        }
Пример #6
0
        internal bool OnGUI(BuildTargetGroup buildTargetGroup)
        {
            var settings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(buildTargetGroup);

            if (buildTargetGroup != CurrentBuildTargetGroup || m_LoaderMetadata == null)
            {
                CurrentBuildTargetGroup = buildTargetGroup;

                if (m_LoaderMetadata == null)
                {
                    m_LoaderMetadata = new List <LoaderInformation>();
                }
                else
                {
                    m_LoaderMetadata.Clear();
                }

                foreach (var pmd in XRPackageMetadataStore.GetLoadersForBuildTarget(buildTargetGroup))
                {
                    var newLi = new LoaderInformation()
                    {
                        packageName    = pmd.packageName,
                        packageId      = pmd.packageId,
                        loaderName     = pmd.loaderName,
                        loaderType     = pmd.loaderType,
                        toggled        = XRPackageMetadataStore.IsLoaderAssigned(pmd.loaderType, buildTargetGroup),
                        disabled       = false,
                        customLoaderUI = XRCustomLoaderUIManager.GetCustomLoaderUI(pmd.loaderType, buildTargetGroup)
                    };

                    if (newLi.customLoaderUI != null)
                    {
                        newLi.customLoaderUI.IsLoaderEnabled        = newLi.toggled;
                        newLi.customLoaderUI.ActiveBuildTargetGroup = CurrentBuildTargetGroup;
                    }
                    m_LoaderMetadata.Add(newLi);
                }

                if (settings != null)
                {
                    List <LoaderInformation> loadersWantingToDisableOtherLoaders = new List <LoaderInformation>();

                    LoaderInformation li;
                    for (int i = 0; i < m_LoaderMetadata.Count; i++)
                    {
                        li = m_LoaderMetadata[i];
                        if (XRPackageMetadataStore.IsLoaderAssigned(settings.AssignedSettings, li.loaderType))
                        {
                            li.toggled          = true;
                            m_LoaderMetadata[i] = li;

                            if (li.customLoaderUI != null)
                            {
                                loadersWantingToDisableOtherLoaders.Add(li);
                            }
                            break;
                        }
                    }

                    foreach (var loader in loadersWantingToDisableOtherLoaders)
                    {
                        SetDisablesStateOnLoadersFromLoader(loader);
                    }
                }

                m_OrderedList = new ReorderableList(m_LoaderMetadata, typeof(LoaderInformation), false, true, false, false);
                m_OrderedList.drawHeaderCallback = (rect) =>
                {
                    var labelSize = EditorStyles.label.CalcSize(Content.k_LoaderUITitle);
                    var labelRect = new Rect(rect);
                    labelRect.width = labelSize.x;

                    labelSize = EditorStyles.label.CalcSize(Content.k_HelpContent);
                    var imageRect = new Rect(rect);
                    imageRect.xMin  = labelRect.xMax + 1;
                    imageRect.width = labelSize.x;

                    EditorGUI.LabelField(labelRect, Content.k_LoaderUITitle, EditorStyles.label);
                    if (GUI.Button(imageRect, Content.k_HelpContent, EditorStyles.label))
                    {
                        System.Diagnostics.Process.Start(Content.k_HelpUri);
                    }
                };
                m_OrderedList.drawElementCallback           = (rect, index, isActive, isFocused) => DrawElementCallback(rect, index, isActive, isFocused);
                m_OrderedList.drawElementBackgroundCallback = (rect, index, isActive, isFocused) =>
                {
                    var tex = GUI.skin.label.normal.background;
                    if (tex == null && GUI.skin.label.normal.scaledBackgrounds.Length > 0)
                    {
                        tex = GUI.skin.label.normal.scaledBackgrounds[0];
                    }
                    if (tex == null)
                    {
                        return;
                    }

                    GUI.DrawTexture(rect, GUI.skin.label.normal.background);
                };
                m_OrderedList.drawFooterCallback = (rect) =>
                {
                    var status = XRPackageMetadataStore.GetCurrentStatusDisplayText();
                    GUI.Label(rect, EditorGUIUtility.TrTextContent(status), EditorStyles.label);
                };
                m_OrderedList.elementHeightCallback = (index) => GetElementHeight(index);
            }

            if (m_LoaderMetadata == null || m_LoaderMetadata.Count == 0)
            {
                EditorGUILayout.HelpBox(k_AtNoLoaderInstance, MessageType.Info);
            }
            else
            {
                m_OrderedList.DoLayoutList();
                if (settings != null)
                {
                    LoaderInformation li;
                    for (int i = 0; i < m_LoaderMetadata.Count; i++)
                    {
                        li = m_LoaderMetadata[i];
                        if (li.stateChanged && li.customLoaderUI != null)
                        {
                            SetDisablesStateOnLoadersFromLoader(li);
                        }
                    }

                    for (int i = 0; i < m_LoaderMetadata.Count; i++)
                    {
                        li = m_LoaderMetadata[i];
                        if (li.stateChanged)
                        {
                            if (li.toggled)
                            {
                                XRPackageMetadataStore.InstallPackageAndAssignLoaderForBuildTarget(li.packageId, li.loaderType, buildTargetGroup);
                            }
                            else
                            {
                                XRPackageMetadataStore.RemoveLoader(settings.AssignedSettings, li.loaderType, buildTargetGroup);
                            }
                            li.stateChanged     = false;
                            m_LoaderMetadata[i] = li;
                        }
                    }
                }
            }

            return(false);
        }
Пример #7
0
        internal bool OnGUI(BuildTargetGroup buildTargetGroup)
        {
            var settings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(buildTargetGroup);

            if (buildTargetGroup != CurrentBuildTargetGroup || m_LoaderMetadata == null)
            {
                CurrentBuildTargetGroup = buildTargetGroup;

                if (m_LoaderMetadata == null)
                {
                    m_LoaderMetadata = new List <LoaderInformation>();
                }
                else
                {
                    m_LoaderMetadata.Clear();
                }

                foreach (var pmd in XRPackageMetadataStore.GetLoadersForBuildTarget(buildTargetGroup))
                {
                    m_LoaderMetadata.Add(new LoaderInformation()
                    {
                        packageName = pmd.packageName,
                        packageId   = pmd.packageId,
                        loaderName  = pmd.loaderName,
                        loaderType  = pmd.loaderType,
                        toggled     = XRPackageMetadataStore.IsLoaderAssigned(pmd.loaderType, buildTargetGroup)
                    });
                }

                if (settings != null)
                {
                    LoaderInformation li;
                    for (int i = 0; i < m_LoaderMetadata.Count; i++)
                    {
                        li = m_LoaderMetadata[i];
                        if (XRPackageMetadataStore.IsLoaderAssigned(settings.AssignedSettings, li.loaderType))
                        {
                            li.toggled          = true;
                            m_LoaderMetadata[i] = li;
                            break;
                        }
                    }
                }

                m_OrderedList = new ReorderableList(m_LoaderMetadata, typeof(LoaderInformation), false, true, false, false);
                m_OrderedList.drawHeaderCallback    = (rect) => GUI.Label(rect, EditorGUIUtility.TrTextContent("Plug-in Providers"), EditorStyles.label);
                m_OrderedList.drawElementCallback   = (rect, index, isActive, isFocused) => DrawElementCallback(rect, index, isActive, isFocused);
                m_OrderedList.elementHeightCallback = (index) => GetElementHeight(index);
            }

            if (m_LoaderMetadata == null || m_LoaderMetadata.Count == 0)
            {
                EditorGUILayout.HelpBox(k_AtNoLoaderInstance, MessageType.Info);
            }
            else
            {
                m_OrderedList.DoLayoutList();
                if (settings != null)
                {
                    LoaderInformation li;
                    for (int i = 0; i < m_LoaderMetadata.Count; i++)
                    {
                        li = m_LoaderMetadata[i];
                        if (li.stateChanged)
                        {
                            if (li.toggled)
                            {
                                if (XRPackageMetadataStore.IsPackageInstalled(li.packageId))
                                {
                                    XRPackageMetadataStore.AssignLoader(settings.AssignedSettings, li.loaderType, buildTargetGroup);
                                }
                                else
                                {
                                    XRPackageMetadataStore.InstallPackageAndAssignLoaderForBuildTarget(li.packageId, li.loaderType, buildTargetGroup);
                                }
                            }
                            else
                            {
                                XRPackageMetadataStore.RemoveLoader(settings.AssignedSettings, li.loaderType, buildTargetGroup);
                            }
                            li.stateChanged     = false;
                            m_LoaderMetadata[i] = li;
                        }
                    }
                }
            }

            return(false);
        }
Пример #8
0
    private static void DoBuildIOSInternal(iOSBuildType buildType, iOSSdkVersion sdkVersion)
    {
        Debug.Log("Building iOS...");

        CurrentGroup = BuildTargetGroup.iOS;

        var xrGeneralSettings         = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.iOS);
        var prevCompilerConfiguration = PlayerSettings.GetIl2CppCompilerConfiguration(BuildTargetGroup.iOS);
        var prevScriptingDefines      = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS);
        var prev_sdkVersion           = PlayerSettings.iOS.sdkVersion;
        var isDebug       = !(buildType == iOSBuildType.Debug);
        var disabledARKit = false;

        using var revertSettings = new Disposable(() =>
        {
            CurrentGroup = null;

            PlayerSettings.iOS.sdkVersion = prev_sdkVersion;
            PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, prevCompilerConfiguration);

            if (!Application.isBatchMode)
            {
                PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, prevScriptingDefines);
            }

            if (disabledARKit)
            {
                XRPackageMetadataStore.AssignLoader(
                    xrGeneralSettings.AssignedSettings,
                    typeof(UnityEngine.XR.ARKit.ARKitLoader).FullName,
                    BuildTargetGroup.iOS);
            }
        });

        var compilerConfiguration = isDebug ? Il2CppCompilerConfiguration.Debug : Il2CppCompilerConfiguration.Master;

        PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.iOS, compilerConfiguration);
        PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, ProcessDefines(prevScriptingDefines, isDebug));
        PlayerSettings.iOS.sdkVersion = sdkVersion;

        if (sdkVersion == iOSSdkVersion.SimulatorSDK &&
            xrGeneralSettings.AssignedSettings.activeLoaders.Any(m => m.GetType() == typeof(UnityEngine.XR.ARKit.ARKitLoader)))
        {
            // ARKit is not supported on iOS Simulator - disable it temporairly
            XRPackageMetadataStore.RemoveLoader(
                xrGeneralSettings.AssignedSettings,
                typeof(UnityEngine.XR.ARKit.ARKitLoader).FullName,
                BuildTargetGroup.iOS);
            disabledARKit = true;
        }

        string exportPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../ios/UnityExport"));
        string buildPath  = iosBuildPath;

        if (Directory.Exists(buildPath))
        {
            Directory.Delete(buildPath, true);
        }

        EditorUserBuildSettings.iOSBuildConfigType = buildType;

        try
        {
            var options = (buildType == iOSBuildType.Debug ? BuildOptions.AllowDebugging : BuildOptions.None);
            var report  = BuildPipeline.BuildPlayer(
                GetEnabledScenes(),
                buildPath,
                BuildTarget.iOS,
                options
                );

            if (report.summary.result != BuildResult.Succeeded)
            {
                throw new Exception("Build failed");
            }

            // Clear UnityExport
            DeleteFolderContent(exportPath);

            // Copy build output to UnityExport
            Debug.Log("Copy to UnityExport");
            CopyDirectory(
                buildPath,
                exportPath,
                mergeDirectories: false,
                overwriteFiles: true);
        }
        catch (Exception e)
        {
            Debug.Log("Export failed!");

            if (Application.isBatchMode)
            {
                Debug.LogError(e);
                EditorApplication.Exit(-1);
            }
            else
            {
                throw;
            }
        }
        finally
        {
            Debug.Log("Export completed!");

            if (Application.isBatchMode)
            {
                EditorApplication.Exit(0);
            }
        }
    }