Skip to content

Commit f9b266d

Browse files
PPV2 - Fix VR/XR detection when using XR plugins (#5698)
* Fix VR/XR detection when using XR plugins This detection was only working at run-time or with a pre-2020.1 Editor... So any recent Editor that fully rely on XR system will not work. With XR extensions, we can query the XR Management system to see if there is any active XR extension. * Add changelog entry * Fix formatting issue * Fix issue with Unity 2019.3 The warning was not appearing with XR module, but was there with old VR extension.
1 parent b536833 commit f9b266d

File tree

6 files changed

+57
-7
lines changed

6 files changed

+57
-7
lines changed

com.unity.postprocessing/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this package will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
### Fixed
8+
- Fix missing XR warnings for XR non-friendly effects when using XR plugins (case 1328062)
9+
710
## [3.2.1] - 2021-11-15
811

912

com.unity.postprocessing/PostProcessing/Editor/Effects/BloomEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public override void OnInspectorGUI()
5454
PropertyField(m_DirtTexture);
5555
PropertyField(m_DirtIntensity);
5656

57-
if (RuntimeUtilities.isVREnabled)
57+
if (EditorUtilities.isVREnabled)
5858
{
5959
if ((m_DirtIntensity.overrideState.boolValue && m_DirtIntensity.value.floatValue > 0f)
6060
|| (m_DirtTexture.overrideState.boolValue && m_DirtTexture.value.objectReferenceValue != null))

com.unity.postprocessing/PostProcessing/Editor/Effects/LensDistortionEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal sealed class LensDistortionEditor : DefaultPostProcessEffectEditor
77
{
88
public override void OnInspectorGUI()
99
{
10-
if (RuntimeUtilities.isVREnabled)
10+
if (EditorUtilities.isVREnabled)
1111
EditorGUILayout.HelpBox("Lens Distortion is available only for non-stereo cameras.", MessageType.Warning);
1212

1313
base.OnInspectorGUI();

com.unity.postprocessing/PostProcessing/Editor/Effects/MotionBlurEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal sealed class MotionBlurEditor : DefaultPostProcessEffectEditor
77
{
88
public override void OnInspectorGUI()
99
{
10-
if (RuntimeUtilities.isVREnabled)
10+
if (EditorUtilities.isVREnabled)
1111
EditorGUILayout.HelpBox("Motion Blur is available only for non-stereo cameras.", MessageType.Warning);
1212

1313
base.OnInspectorGUI();
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "Unity.Postprocessing.Editor",
3+
"rootNamespace": "",
34
"references": [
4-
"Unity.Postprocessing.Runtime"
5+
"Unity.Postprocessing.Runtime",
6+
"Unity.XR.Management",
7+
"Unity.XR.Management.Editor"
58
],
6-
"optionalUnityReferences": [],
79
"includePlatforms": [
810
"Editor"
911
],
@@ -12,5 +14,23 @@
1214
"overrideReferences": false,
1315
"precompiledReferences": [],
1416
"autoReferenced": true,
15-
"defineConstraints": []
16-
}
17+
"defineConstraints": [],
18+
"versionDefines": [
19+
{
20+
"name": "com.unity.xr.management",
21+
"expression": "4.0.1",
22+
"define": "XR_MANAGEMENT_4_0_1_OR_NEWER"
23+
},
24+
{
25+
"name": "com.unity.modules.vr",
26+
"expression": "1.0.0",
27+
"define": "ENABLE_VR_MODULE"
28+
},
29+
{
30+
"name": "com.unity.modules.xr",
31+
"expression": "1.0.0",
32+
"define": "ENABLE_XR_MODULE"
33+
}
34+
],
35+
"noEngineReferences": false
36+
}

com.unity.postprocessing/PostProcessing/Editor/Utils/EditorUtilities.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
using UnityEngine.Assertions;
66
using UnityEngine.Rendering.PostProcessing;
77

8+
#if XR_MANAGEMENT_4_0_1_OR_NEWER
9+
using UnityEditor.XR.Management;
10+
#endif
11+
812
namespace UnityEditor.Rendering.PostProcessing
913
{
1014
/// <summary>
@@ -360,5 +364,28 @@ static bool CanPaste(PostProcessEffectSettings target)
360364
return s_ClipboardContent != null
361365
&& s_ClipboardContent.GetType() == target.GetType();
362366
}
367+
368+
internal static bool isVREnabled
369+
{
370+
get
371+
{
372+
#if ENABLE_VR_MODULE && ENABLE_VR
373+
#if ENABLE_XR_MODULE && XR_MANAGEMENT_4_0_1_OR_NEWER
374+
// If XR manager extension is available, we can query it to know if any XR extension is currently active
375+
var buildTargetSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(BuildTargetGroup.Standalone);
376+
return (buildTargetSettings != null && buildTargetSettings.AssignedSettings != null &&
377+
buildTargetSettings.AssignedSettings.activeLoaders.Count > 0);
378+
#elif !UNITY_2020_1_OR_NEWER
379+
// This will only work with 2019.3 and older since it rely on the old VR module
380+
return UnityEditorInternal.VR.VREditor.GetVREnabledOnTargetGroup(BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget));
381+
#else
382+
// If we reach this code-path, it means we can't really detect if VR/XR is active in the Editor, so return false
383+
return false;
384+
#endif
385+
#else
386+
return false;
387+
#endif
388+
}
389+
}
363390
}
364391
}

0 commit comments

Comments
 (0)