예제 #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
        public IEnumerator TestLoaderAssignment()
        {
            Assert.IsNotNull(m_Settings);

            string loaderTypeName = LoaderTypeNameForBuildTarget(BuildTargetGroup.Standalone);

            Assert.IsFalse(String.IsNullOrEmpty(loaderTypeName));

            bool wasFound = false;

            foreach (var l in m_Settings.loaders)
            {
                if (String.Compare(l.GetType().FullName, loaderTypeName) == 0)
                {
                    wasFound = true;
                }
            }
            Assert.IsFalse(wasFound);

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

            yield return(null);

            Assert.IsTrue(SettingsHasLoaderOfType(m_Settings, loaderTypeName));
            Assert.IsTrue(TestLoaderBase.WasAssigned);
        }
예제 #3
0
    internal void SetupXR()
    {
#if UNITY_EDITOR
        XRPackageMetadataStore.AssignLoader(XRGeneralSettings.Instance.Manager, typeof(WindowsMRLoader).Name, BuildTargetGroup.Standalone);
#endif
        XRGeneralSettings.Instance.Manager.InitializeLoaderSync();
        XRGeneralSettings.Instance.Manager.StartSubsystems();
    }
예제 #4
0
        private bool AssignLoaderToSettings(XRManagerSettings settings, string loaderTypeName, BuildTargetGroup buildTargetGroup = BuildTargetGroup.Standalone)
        {
            if (String.IsNullOrEmpty(loaderTypeName))
            {
                return(false);
            }

            return(XRPackageMetadataStore.AssignLoader(m_Settings, loaderTypeName, buildTargetGroup));
        }
    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();
    }
예제 #6
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);
            }
        }
예제 #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);
            }
        }
    }
        public static void EnableLoader()
        {
            if (skipEditorFrames > 0)
            {
                skipEditorFrames--;
                return;
            }

            if (enabledLoaderKey == null)
            {
                enabledLoaderKey = string.Format(valveEnabledLoaderKeyTemplate, SteamVR_Settings.instance.editorAppKey);
            }

            if (EditorPrefs.HasKey(enabledLoaderKey) == false)
            {
                if (UnityEditor.PlayerSettings.virtualRealitySupported == true)
                {
                    UnityEditor.PlayerSettings.virtualRealitySupported = false;
                    Debug.Log("<b>[SteamVR Setup]</b> Disabled virtual reality support in Player Settings. <b>Because you're using XR Manager. Make sure OpenVR Loader is enabled in XR Manager UI.</b> (you can disable this by unchecking Assets/SteamVR/SteamVR_Settings.autoEnableVR)");
                }

                var generalSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.Standalone);
                if (generalSettings == null)
                {
                    if (settingsWindow == null)
                    {
                        settingsWindow = SettingsService.OpenProjectSettings("Project/XR Plug-in Management");
                        settingsWindow.Repaint();
                        return;
                    }

                    if (settingsWindow == null || generalSettings == null)
                    {
                        Debug.LogWarning("<b>[SteamVR Setup]</b> Unable to access standalone xr settings while trying to enable OpenVR Loader. <b>You may need to manually enable OpenVR Loader in XR Plug-in Management (Project Settings).</b> (you can disable this by unchecking Assets/SteamVR/SteamVR_Settings.autoEnableVR)");
                        return;
                    }
                }

                if (generalSettings.AssignedSettings == null)
                {
                    var assignedSettings = ScriptableObject.CreateInstance <XRManagerSettings>() as XRManagerSettings;
                    generalSettings.AssignedSettings = assignedSettings;
                    EditorUtility.SetDirty(generalSettings);
                }

                bool existing = generalSettings.AssignedSettings.loaders.Any(loader => loader.name == valveOpenVRLoaderType);

                foreach (var loader in generalSettings.AssignedSettings.loaders)
                {
                    Debug.Log("loader: " + loader.name);
                }

                if (!existing)
                {
                    bool status = XRPackageMetadataStore.AssignLoader(generalSettings.AssignedSettings, valveOpenVRLoaderType, BuildTargetGroup.Standalone);
                    if (status)
                    {
                        Debug.Log("<b>[SteamVR Setup]</b> Enabled OpenVR Loader in XR Management");
                    }
                    else
                    {
                        Debug.LogError("<b>[SteamVR Setup]</b> Failed to enable enable OpenVR Loader in XR Management. You may need to manually open the XR Plug-in Management tab in project settings and check the OpenVR Loader box.");
                    }
                }

                EditorPrefs.SetBool(enabledLoaderKey, true);
            }

            End();
        }