Exemple #1
0
    private static string GetOculusProjectConfigAssetPath()
    {
        var    so        = ScriptableObject.CreateInstance(typeof(OVRPluginUpdaterStub));
        var    script    = MonoScript.FromScriptableObject(so);
        string assetPath = AssetDatabase.GetAssetPath(script);
        string editorDir = Directory.GetParent(assetPath).FullName;
        string ovrDir    = Directory.GetParent(editorDir).FullName;
        string oculusDir = Directory.GetParent(ovrDir).FullName;

        if (OVRPluginUpdaterStub.IsInsidePackageDistribution())
        {
            oculusDir = Path.GetFullPath(Path.Combine(Application.dataPath, "Oculus"));
            if (!Directory.Exists(oculusDir))
            {
                Directory.CreateDirectory(oculusDir);
            }
        }

        string configAssetPath = Path.GetFullPath(Path.Combine(oculusDir, "OculusProjectConfig.asset"));
        Uri    configUri       = new Uri(configAssetPath);
        Uri    projectUri      = new Uri(Application.dataPath);
        Uri    relativeUri     = projectUri.MakeRelativeUri(configUri);

        return(relativeUri.ToString());
    }
Exemple #2
0
    private static void AttemptPluginDisable()
    {
        if (OVRPluginUpdaterStub.IsInsidePackageDistribution())
        {
            UnityEngine.Debug.LogError("Unable to change plugin when using package distribution");
            return;
        }

        List <PluginPackage> allUtilsPluginPkgs = GetAllUtilitiesPluginPackages();

        PluginPackage enabledUtilsPluginPkg = null;

        foreach (PluginPackage pluginPkg in allUtilsPluginPkgs)
        {
            if (pluginPkg.IsEnabled())
            {
                if ((enabledUtilsPluginPkg == null) || (pluginPkg.Version > enabledUtilsPluginPkg.Version))
                {
                    enabledUtilsPluginPkg = pluginPkg;
                }
            }
        }

        if (enabledUtilsPluginPkg == null)
        {
            if (unityRunningInBatchmode ||
                EditorUtility.DisplayDialog("Disable Oculus Utilities Plugin",
                                            "The OVRPlugin included with Oculus Utilities is already disabled."
                                            + " The OVRPlugin installed through the Package Manager will continue to be used.\n",
                                            "Ok",
                                            ""))
            {
                return;
            }
        }
        else
        {
            if (unityRunningInBatchmode ||
                EditorUtility.DisplayDialog("Disable Oculus Utilities Plugin",
                                            "Do you want to disable the OVRPlugin included with Oculus Utilities and revert to the OVRPlugin installed through the Package Manager?\n\n"
                                            + "Current version: " + GetVersionDescription(enabledUtilsPluginPkg.Version),
                                            "Yes",
                                            "No"))
            {
                DisableAllUtilitiesPluginPackages();

                if (unityRunningInBatchmode ||
                    EditorUtility.DisplayDialog("Restart Unity",
                                                "Now you will be using the OVRPlugin installed through Package Manager."
                                                + "\n\nPlease restart the Unity Editor to complete the update process.",
                                                "Restart",
                                                "Not Now"))
                {
                    RestartUnityEditor();
                }
            }
        }
    }
Exemple #3
0
    private static void RunPluginUpdate()
    {
        if (OVRPluginUpdaterStub.IsInsidePackageDistribution())
        {
            UnityEngine.Debug.LogError("Unable to change plugin when using package distribution");
            return;
        }

        autoUpdateEnabled = true;
        AttemptPluginUpdate(false);
    }
Exemple #4
0
 private static bool ShouldAttemptPluginUpdate()
 {
     if (unityRunningInBatchmode || OVRPluginUpdaterStub.IsInsidePackageDistribution())
     {
         return(false);
     }
     else
     {
         return(!UnitySupportsEnabledAndroidPlugin() || (autoUpdateEnabled && !restartPending && !Application.isPlaying));
     }
 }
Exemple #5
0
    private static void RestoreStandardOVRPlugin()
    {
        if (!unityVersionSupportsAndroidUniversal)         // sanity check
        {
            UnityEngine.Debug.LogError("Unexpected error: Unity must support AndroidUniversal version of Oculus Utilities Plugin for accessing OpenXR");
            return;
        }

        if (OVRPluginUpdaterStub.IsInsidePackageDistribution())
        {
            UnityEngine.Debug.LogError("Unable to change plugin when using package distribution");
            return;
        }

        List <PluginPackage> allUtilsPluginPkgs = GetAllUtilitiesPluginPackages();

        PluginPackage enabledUtilsPluginPkg = null;

        foreach (PluginPackage pluginPkg in allUtilsPluginPkgs)
        {
            if (pluginPkg.IsEnabled())
            {
                enabledUtilsPluginPkg = pluginPkg;
                break;
            }
        }

        if (enabledUtilsPluginPkg == null)
        {
            UnityEngine.Debug.LogError("Unable to Restore Standard Oculus Utilities Plugin: Oculus Utilities Plugin package not activated");
            return;
        }

        if (!enabledUtilsPluginPkg.IsAndroidUniversalPresent() && !enabledUtilsPluginPkg.IsWin64Present())
        {
            UnityEngine.Debug.LogError("Unable to Restore Standard Oculus Utilities Plugin: Both AndroidOpenXR/OVRPlugin.aar and Win64/OVRPlugin.dll does not exist");
            return;
        }

        if (enabledUtilsPluginPkg.IsAndroidUniversalEnabled() && enabledUtilsPluginPkg.IsWin64Enabled())
        {
            if (!unityRunningInBatchmode)
            {
                EditorUtility.DisplayDialog("Unable to Restore Standard Oculus Utilities Plugin", "Both AndroidUniversal/OVRPlugin.aar and Win64/OVRPlugin.dll already enabled", "Ok");
            }
            return;
        }

        if (enabledUtilsPluginPkg.IsAndroidUniversalPresent() && !enabledUtilsPluginPkg.IsAndroidUniversalEnabled())
        {
            if (enabledUtilsPluginPkg.IsAndroidOpenXREnabled())
            {
                string         androidOpenXRPluginPath     = enabledUtilsPluginPkg.Plugins[PluginPlatform.AndroidOpenXR];
                string         androidOpenXRPluginBasePath = GetCurrentProjectPath();
                string         androidOpenXRPluginRelPath  = androidOpenXRPluginPath.Substring(androidOpenXRPluginBasePath.Length + 1);
                PluginImporter pi = PluginImporter.GetAtPath(androidOpenXRPluginRelPath) as PluginImporter;
                if (pi != null)
                {
                    pi.SetCompatibleWithPlatform(BuildTarget.Android, false);
                    AssetDatabase.ImportAsset(androidOpenXRPluginRelPath, ImportAssetOptions.ForceUpdate);
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Unable to find PluginImporter: " + androidOpenXRPluginRelPath);
                }
            }

            {
                string         androidUniveralPluginPath     = enabledUtilsPluginPkg.Plugins[PluginPlatform.AndroidUniversal];
                string         androidUniveralPluginBasePath = GetCurrentProjectPath();
                string         androidUniveralPluginRelPath  = androidUniveralPluginPath.Substring(androidUniveralPluginBasePath.Length + 1);
                PluginImporter pi = PluginImporter.GetAtPath(androidUniveralPluginRelPath) as PluginImporter;
                if (pi != null)
                {
                    pi.SetCompatibleWithPlatform(BuildTarget.Android, true);
                    AssetDatabase.ImportAsset(androidUniveralPluginRelPath, ImportAssetOptions.ForceUpdate);
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Unable to find PluginImporter: " + androidUniveralPluginRelPath);
                }
            }
        }

        bool win64PluginUpdated = false;

        if (enabledUtilsPluginPkg.IsWin64Present() && !enabledUtilsPluginPkg.IsWin64Enabled())
        {
            if (enabledUtilsPluginPkg.IsWin64OpenXREnabled())
            {
                string         win64OpenXRPluginPath     = enabledUtilsPluginPkg.Plugins[PluginPlatform.Win64OpenXR];
                string         win64OpenXRPluginBasePath = GetCurrentProjectPath();
                string         win64OpenXRPluginRelPath  = win64OpenXRPluginPath.Substring(win64OpenXRPluginBasePath.Length + 1);
                PluginImporter pi = PluginImporter.GetAtPath(win64OpenXRPluginRelPath) as PluginImporter;
                if (pi != null)
                {
                    pi.ClearSettings();
                    pi.SetCompatibleWithEditor(false);
                    pi.SetCompatibleWithAnyPlatform(false);
                    AssetDatabase.ImportAsset(win64OpenXRPluginRelPath, ImportAssetOptions.ForceUpdate);
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Unable to find PluginImporter: " + win64OpenXRPluginRelPath);
                }
            }

            {
                string         win64PluginPath     = enabledUtilsPluginPkg.Plugins[PluginPlatform.Win64];
                string         win64PluginBasePath = GetCurrentProjectPath();
                string         win64PluginRelPath  = win64PluginPath.Substring(win64PluginBasePath.Length + 1);
                PluginImporter pi = PluginImporter.GetAtPath(win64PluginRelPath) as PluginImporter;
                if (pi != null)
                {
                    pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, true);
                    pi.SetCompatibleWithEditor(true);
                    pi.SetEditorData("CPU", "X86_64");
                    pi.SetEditorData("OS", "Windows");
                    pi.SetPlatformData("Editor", "CPU", "X86_64");
                    pi.SetPlatformData("Editor", "OS", "Windows");
                    AssetDatabase.ImportAsset(win64PluginRelPath, ImportAssetOptions.ForceUpdate);
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Unable to find PluginImporter: " + win64PluginRelPath);
                }
            }

            win64PluginUpdated = true;
        }

        AssetDatabase.Refresh();
        AssetDatabase.SaveAssets();

        if (!unityRunningInBatchmode)
        {
            EditorUtility.DisplayDialog("Restore Standard OVRPlugin", "Standard version of Oculus Utilities Plugin has been enabled on Android", "Ok");
            if (win64PluginUpdated && EditorUtility.DisplayDialog("Restart Unity",
                                                                  "Win64 plugin updated. Do you want to restart Unity editor?",
                                                                  "Restart",
                                                                  "Not Now"))
            {
                RestartUnityEditor();
            }
        }
    }
Exemple #6
0
    private static void ActivateOVRPluginOpenXR()
    {
        if (!unityVersionSupportsAndroidUniversal)
        {
            UnityEngine.Debug.LogError("Unexpected error: Unity must support AndroidUniversal version of Oculus Utilities Plugin for accessing OpenXR");
            return;
        }

        if (OVRPluginUpdaterStub.IsInsidePackageDistribution())
        {
            UnityEngine.Debug.LogError("Unable to change plugin when using package distribution");
            return;
        }

#if !USING_XR_SDK && !REQUIRES_XR_SDK
        UnityEngine.Debug.LogError("Oculus Utilities Plugin with OpenXR only supports XR Plug-in Managmenent with Oculus XR Plugin");
        return;
#else
        List <PluginPackage> allUtilsPluginPkgs = GetAllUtilitiesPluginPackages();

        PluginPackage enabledUtilsPluginPkg = null;

        foreach (PluginPackage pluginPkg in allUtilsPluginPkgs)
        {
            if (pluginPkg.IsEnabled())
            {
                enabledUtilsPluginPkg = pluginPkg;
                break;
            }
        }

        if (enabledUtilsPluginPkg == null)
        {
            UnityEngine.Debug.LogError("Unable to Activate OVRPlugin with OpenXR: Oculus Utilities Plugin package not activated");
            return;
        }

        if (!enabledUtilsPluginPkg.IsAndroidOpenXRPresent() && !enabledUtilsPluginPkg.IsWin64OpenXRPresent())
        {
            UnityEngine.Debug.LogError("Unable to Activate OVRPlugin with OpenXR: Both AndroidOpenXR/OVRPlugin.aar or Win64OpenXR/OVRPlugin.dll does not exist");
            return;
        }

        if (enabledUtilsPluginPkg.IsAndroidOpenXREnabled() && enabledUtilsPluginPkg.IsWin64OpenXREnabled())
        {
            if (!unityRunningInBatchmode)
            {
                EditorUtility.DisplayDialog("Unable to Activate OVRPlugin with OpenXR", "Both AndroidOpenXR/OVRPlugin.aar and Win64OpenXR/OVRPlugin.dll already enabled", "Ok");
            }
            return;
        }

        if (enabledUtilsPluginPkg.Version < minimalProductionVersionForOpenXR)
        {
            if (!unityRunningInBatchmode)
            {
                bool accepted = EditorUtility.DisplayDialog("Warning",
                                                            "OVRPlugin with OpenXR backend is experimental before v31. You may expect to encounter stability issues and/or missing functionalities, " +
                                                            "including but not limited to, fixed foveated rendering / composition layer / display refresh rates / etc." +
                                                            "\n\n" +
                                                            "Also, OVRPlugin with OpenXR backend only supports XR Plug-in Managmenent with Oculus XR Plugin on Quest",
                                                            "Continue", "Cancel");

                if (!accepted)
                {
                    return;
                }
            }
        }

        if (enabledUtilsPluginPkg.IsAndroidOpenXRPresent() && !enabledUtilsPluginPkg.IsAndroidOpenXREnabled())
        {
            if (enabledUtilsPluginPkg.IsAndroidUniversalEnabled())
            {
                string         androidUniveralPluginPath     = enabledUtilsPluginPkg.Plugins[PluginPlatform.AndroidUniversal];
                string         androidUniveralPluginBasePath = GetCurrentProjectPath();
                string         androidUniveralPluginRelPath  = androidUniveralPluginPath.Substring(androidUniveralPluginBasePath.Length + 1);
                PluginImporter pi = PluginImporter.GetAtPath(androidUniveralPluginRelPath) as PluginImporter;
                if (pi != null)
                {
                    pi.SetCompatibleWithPlatform(BuildTarget.Android, false);
                    AssetDatabase.ImportAsset(androidUniveralPluginRelPath, ImportAssetOptions.ForceUpdate);
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Unable to find PluginImporter: " + androidUniveralPluginRelPath);
                }
            }

            {
                string         androidOpenXRPluginPath     = enabledUtilsPluginPkg.Plugins[PluginPlatform.AndroidOpenXR];
                string         androidOpenXRPluginBasePath = GetCurrentProjectPath();
                string         androidOpenXRPluginRelPath  = androidOpenXRPluginPath.Substring(androidOpenXRPluginBasePath.Length + 1);
                PluginImporter pi = PluginImporter.GetAtPath(androidOpenXRPluginRelPath) as PluginImporter;
                if (pi != null)
                {
                    pi.SetCompatibleWithPlatform(BuildTarget.Android, true);
                    AssetDatabase.ImportAsset(androidOpenXRPluginRelPath, ImportAssetOptions.ForceUpdate);
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Unable to find PluginImporter: " + androidOpenXRPluginRelPath);
                }
            }
        }


        bool win64PluginUpdated = false;

        if (enabledUtilsPluginPkg.IsWin64OpenXRPresent() && !enabledUtilsPluginPkg.IsWin64OpenXREnabled())
        {
            if (enabledUtilsPluginPkg.IsWin64Enabled())
            {
                string         win64PluginPath     = enabledUtilsPluginPkg.Plugins[PluginPlatform.Win64];
                string         win64PluginBasePath = GetCurrentProjectPath();
                string         win64PluginRelPath  = win64PluginPath.Substring(win64PluginBasePath.Length + 1);
                PluginImporter pi = PluginImporter.GetAtPath(win64PluginRelPath) as PluginImporter;
                if (pi != null)
                {
                    pi.ClearSettings();
                    pi.SetCompatibleWithEditor(false);
                    pi.SetCompatibleWithAnyPlatform(false);
                    AssetDatabase.ImportAsset(win64PluginRelPath, ImportAssetOptions.ForceUpdate);
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Unable to find PluginImporter: " + win64PluginRelPath);
                }
            }

            {
                string         win64OpenXRPluginPath     = enabledUtilsPluginPkg.Plugins[PluginPlatform.Win64OpenXR];
                string         win64OpenXRPluginBasePath = GetCurrentProjectPath();
                string         win64OpenXRPluginRelPath  = win64OpenXRPluginPath.Substring(win64OpenXRPluginBasePath.Length + 1);
                PluginImporter pi = PluginImporter.GetAtPath(win64OpenXRPluginRelPath) as PluginImporter;
                if (pi != null)
                {
                    pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, true);
                    pi.SetCompatibleWithEditor(true);
                    pi.SetEditorData("CPU", "X86_64");
                    pi.SetEditorData("OS", "Windows");
                    pi.SetPlatformData("Editor", "CPU", "X86_64");
                    pi.SetPlatformData("Editor", "OS", "Windows");
                    AssetDatabase.ImportAsset(win64OpenXRPluginRelPath, ImportAssetOptions.ForceUpdate);
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Unable to find PluginImporter: " + win64OpenXRPluginRelPath);
                }
            }

            win64PluginUpdated = true;
        }

        AssetDatabase.Refresh();
        AssetDatabase.SaveAssets();

        if (!unityRunningInBatchmode)
        {
            EditorUtility.DisplayDialog("Activate OVRPlugin with OpenXR", "Oculus Utilities Plugin with OpenXR has been enabled on Android", "Ok");
            if (win64PluginUpdated && EditorUtility.DisplayDialog("Restart Unity",
                                                                  "Win64 plugin updated. Do you want to restart Unity editor?",
                                                                  "Restart",
                                                                  "Not Now"))
            {
                RestartUnityEditor();
            }
        }
#endif // !USING_XR_SDK
    }