Beispiel #1
0
    static void ResetPluginSettings(PluginImporter plugin, string CPU, string OS)
    {
#if UNITY_5_5_OR_NEWER
        plugin.ClearSettings();
#endif
        plugin.SetCompatibleWithAnyPlatform(false);
        plugin.SetCompatibleWithEditor(true);
        plugin.SetEditorData("CPU", CPU);
        plugin.SetEditorData("OS", OS);
    }
Beispiel #2
0
        private static bool DisableDLL(string pathToDLL)
        {
            if (HasCompatibility(pathToDLL, new BuildTarget[] {}, false))
            {
                return(false);
            }

            PluginImporter pluginImporter = (PluginImporter)AssetImporter.GetAtPath(pathToDLL);

            pluginImporter.ClearSettings();
            pluginImporter.SetCompatibleWithAnyPlatform(false);

            pluginImporter.SaveAndReimport();

            return(true);
        }
        private static void SetIl2cppConfig(bool isCpp, PluginImporter dll)
        {
#if !UNITY_2018_1_OR_NEWER
            var target = BuildTarget.StandaloneOSX;
#else
            var target = BuildTarget.StandaloneOSX;
#endif
            dll.ClearSettings();
            dll.SetCompatibleWithAnyPlatform(false);

            if (isCpp)
            {
                dll.SetCompatibleWithPlatform(target, true); //StandaloneOSX
            }

            dll.SaveAndReimport();
        }
Beispiel #4
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();
            }
        }
    }
Beispiel #5
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
    }
        static void SetCompatibility(string guid, PlatformSupport[] platformSupport)
        {
            string pluginPath = AssetDatabase.GUIDToAssetPath(guid);

            PluginImporter plugin = AssetImporter.GetAtPath(pluginPath) as PluginImporter;

            if (plugin == null)
            {
                return;
            }

            bool updateRequired = false;

            if (platformSupport.Length == 0)
            {
                // Just set every platform to disabled before enabling the correct ones
                foreach (BuildTarget bt in Enum.GetValues(typeof(BuildTarget)))
                {
                    // If the build target is obsolete
                    if (bt < 0)
                    {
                        continue;
                    }

                    // Use a string here to handle issue where a platform dependency may not be installed
                    // within the current Unity Editor install
                    if (plugin.GetCompatibleWithPlatform(bt.ToString()))
                    {
                        updateRequired = true;
                    }
                }
            }
            else
            {
                foreach (PlatformSupport s in platformSupport)
                {
                    if (!plugin.GetCompatibleWithPlatform(s.platformName))
                    {
                        updateRequired = true;
                    }

                    if (plugin.GetCompatibleWithEditor() != s.editorSupport)
                    {
                        updateRequired = true;
                    }

                    if (s.editorSupport)
                    {
                        if (plugin.GetEditorData("OS") != s.editorOS ||
                            plugin.GetEditorData("CPU") != s.editorCPU)
                        {
                            updateRequired = true;
                        }
                    }
                }
            }

            if (updateRequired)
            {
#if UNITY_5_5_OR_NEWER
                plugin.ClearSettings();
#endif
                plugin.SetCompatibleWithEditor(false);
                plugin.SetCompatibleWithAnyPlatform(false);

                // Just set every platform to disabled before enabling the correct ones
                foreach (BuildTarget bt in Enum.GetValues(typeof(BuildTarget)))
                {
                    // If the build target is obsolete
                    if (bt < 0)
                    {
                        continue;
                    }

                    // Use a string here to handle issue where a platform dependency may not be installed
                    // within the current Unity Editor install
                    plugin.SetCompatibleWithPlatform(bt.ToString(), false);
                }

                foreach (PlatformSupport s in platformSupport)
                {
                    plugin.SetCompatibleWithPlatform(s.platformName, s.platformSupport);

                    plugin.SetPlatformData("Any", "Exclude Editor", (s.editorSupport ? 0 : 1).ToString());
                    plugin.SetPlatformData("Any", "Exclude " + s.platformName, (s.platformSupport ? 0 : 1).ToString());

                    if (!string.IsNullOrEmpty(s.platformCPU))
                    {
                        plugin.SetPlatformData(s.platformName, "CPU", s.platformCPU);
                    }

                    plugin.SetCompatibleWithEditor(s.editorSupport);

                    if (s.editorSupport)
                    {
                        plugin.SetEditorData("OS", s.editorOS);
                        plugin.SetEditorData("CPU", s.editorCPU);
                    }
                }

                plugin.SaveAndReimport();
            }
        }