private static void RestoreStandardOVRPlugin()

in RealityMaterialExplorer/Assets/Oculus/VR/Editor/OVRPluginUpdater.cs [790:935]


	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();
			}
		}
	}