Skip to content

Commit b2ad543

Browse files
committed
Merge remote-tracking branch 'remotes/origin/master' into fix_subsystemregistration
2 parents 1ac7c63 + f416ee8 commit b2ad543

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

Packages/webxr/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
- Issues when using more than one WebXRManager components.
11+
912
## [0.16.0] - 2023-02-02
1013
### Added
1114
- Support for Spectator Camera.

Packages/webxr/Runtime/Scripts/WebXRCamera.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ public enum CameraID
2626

2727
private bool hasFollower = false;
2828

29-
private void Awake()
30-
{
31-
SwitchXRState();
32-
}
33-
3429
private void OnEnable()
3530
{
3631
WebXRManager.OnXRChange += OnXRChange;
3732
WebXRManager.OnHeadsetUpdate += OnHeadsetUpdate;
3833
hasFollower = cameraFollower != null;
34+
OnXRChange(WebXRManager.Instance.XRState,
35+
WebXRManager.Instance.ViewsCount,
36+
WebXRManager.Instance.ViewsLeftRect,
37+
WebXRManager.Instance.ViewsRightRect);
3938
}
4039

4140
private void OnDisable()

Packages/webxr/Runtime/Scripts/WebXRManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ public class WebXRManager : SubsystemLifecycleManager<WebXRSubsystem, WebXRSubsy
1717
public class WebXRManager : SubsystemLifecycleManager<WebXRSubsystem, WebXRSubsystemDescriptor>
1818
#endif
1919
{
20+
private static readonly Rect defaultRect = new Rect(0, 0, 1, 1);
21+
2022
public static WebXRManager Instance { get; private set; }
2123

2224
public WebXRState XRState => subsystem == null ? WebXRState.NORMAL : subsystem.xrState;
25+
public int ViewsCount => subsystem == null ? 1 : subsystem.viewsCount;
26+
public Rect ViewsLeftRect => subsystem == null ? defaultRect : subsystem.leftRect;
27+
public Rect ViewsRightRect => subsystem == null ? defaultRect : subsystem.rightRect;
2328

2429
public static event WebXRSubsystem.XRCapabilitiesUpdate OnXRCapabilitiesUpdate
2530
{
@@ -124,6 +129,11 @@ public void StopViewerHitTest()
124129
protected override void Awake()
125130
{
126131
base.Awake();
132+
if (Instance != null)
133+
{
134+
Debug.LogError("More than one WebXRManager components in scene. Disabling previous one.");
135+
Instance.enabled = false;
136+
}
127137
Instance = this;
128138
enabled = subsystem != null;
129139
}

Packages/webxr/Runtime/XRPlugin/WebXRSubsystem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ public static extern void SetWebXREvents(StartXREvent on_start_ar,
271271
#endif
272272

273273
internal WebXRState xrState = WebXRState.NORMAL;
274-
private int viewsCount = 1;
275-
private Rect leftRect;
276-
private Rect rightRect;
274+
internal int viewsCount = 1;
275+
internal Rect leftRect;
276+
internal Rect rightRect;
277277
private bool reportedXRStateSwitch = true;
278278
internal WebXRVisibilityState visibilityState = WebXRVisibilityState.VISIBLE;
279279
private bool visibilityStateChanged = false;

0 commit comments

Comments
 (0)