text stringlengths 0 1.11k |
|---|
290 bool isAnchorSharedSuccessfully = await _sharedAnchorManager.ShareAnchorsWithUser(requestedAnchorOculusId); |
And it is in the ShareAnchorsWithUser method where the actual call to OVRSpatialAnchor.Share takes place. |
// SharedAnchorManager.cs |
127 public async UniTask<bool> ShareAnchorsWithUser(ulong userId) { |
128 _userShareList.Add(new OVRSpaceUser(userId)); |
... |
140 OVRSpatialAnchor.Share( |
141 _localAnchors, |
142 users, |
143 (_, result) => { utcs.TrySetResult(result == OVRSpatialAnchor.OperationResult.Success); } |
144 ); |
A Player Joins an Existing Room |
When a player chooses to join an existing room, the flow is much simpler. If the user is a player, the DiscoverAppController.cs script StartClient() method is called and runs the NUXController.cs method StartNux(). |
// DiscoverAppController.cs |
105 public void StartClient() |
106 { |
... |
114 NUXManager.Instance.StartNux( |
115 NUX_EXPERIENCE_KEY, |
116 () => StartConnection(false)); |
117 } |
118 } |
StartNux is dependent on the DiscoverAppController.cs script method StartConnectionAsync(). As with the host, the OnConnectedToServer action is invoked. However, only the player portions are executed: |
// DiscoverAppController.cs |
317 m_playerObject = runner.Spawn( |
318 m_playerPrefab, onBeforeSpawned: (_, obj) => |
319 { |
320 obj.GetComponent<DiscoverPlayer>().IsRemote = |
321 AvatarColocationManager.Instance.IsCurrentPlayerRemote; |
322 }); |
323 runner.SetPlayerObject(runner.LocalPlayer, m_playerObject); |
324 MainMenuController.Instance.EnableMenuButton(true); |
Colocate the Player |
For the player joining a room, the ColocationLauncher.cs script ColocateAutomaticallyInternal() method, gets all known alignment anchors (for Unity-Discover, there is just one), and aligns the player to them. |
// ColocationLauncher.cs |
144 List<Anchor> alignmentAnchors = GetAllAlignmentAnchors(); |
145 foreach (var anchor in alignmentAnchors) |
146 if (await AttemptToShareAndLocalizeToAnchor(anchor)) { |
147 successfullyAlignedToAnchor = true; |
148 Debug.Log($"ColocationLauncher: successfully aligned to anchor with id: {anchor.uuid}"); |
149 _networkData.AddPlayer(new Player(_myOculusId, anchor.colocationGroupId)); |
150 AlignPlayerToAnchor(); |
151 break; |
152 } |
We will look at how the player is aligned to the SSA next. |
Aligning the Player and Loading the SSA |
As we learned in Sharing the Anchor, each of the colocation methods in the ColocationLauncher.cs script make a call to AttemptToShareAndLocalizeToAnchor. For a joining player, the method calls LocalizeAnchor: |
// ColocationLauncher.cs |
244 private UniTask<bool> AttemptToShareAndLocalizeToAnchor(Anchor anchor) { |
245 Debug.Log( |
246 $"ColocationLauncher: Called AttemptToShareAndLocalizeToAnchor with id: {anchor.uuid} and oculusId: {_myOculusId}" |
247 ); |
... |
254 var sharedAnchorId = new Guid(anchor.uuid.ToString()); |
255 LocalizeAnchor(sharedAnchorId); |
256 return _alignToAnchorTask.Task; |
The LocalizeAnchor method calls the SharedAnchorManager.cs script method RetrieveAnchors: |
// ColocationLauncher.cs |
334 private async void LocalizeAnchor(Guid anchorToLocalize) { |
335 Debug.Log($"ColocationLauncher: Localize Anchor Called id: {_myOculusId}"); |
336 IReadOnlyList<OVRSpatialAnchor> sharedAnchors = null; |
337 Guid[] anchorIds = {anchorToLocalize}; |
338 sharedAnchors = await _sharedAnchorManager.RetrieveAnchors(anchorIds); |
And in RetrieveAnchors, the anchors are loaded and bound. |
// SharedAnchorManager.cs |
72 public async UniTask<IReadOnlyList<OVRSpatialAnchor>> RetrieveAnchors(Guid[] anchorIds) { |
... |
79 OVRSpatialAnchor.LoadUnboundAnchors( |
80 new OVRSpatialAnchor.LoadOptions { |
81 StorageLocation = OVRSpace.StorageLocation.Cloud, |
82 Timeout = 0, |
83 Uuids = anchorIds |
84 }, |
... |
103 foreach (var unboundAnchor in unboundAnchors) { |
104 var anchor = InstantiateAnchor(); |
105 try { |
106 unboundAnchor.BindTo(anchor); |
107 _sharedAnchors.Add(anchor); |
108 createdAnchors.Add(anchor); |
109 createTasks.Add(UniTask.WaitWhile(() => anchor.PendingCreation, PlayerLoopTiming.PreUpdate)); |
110 }``` |
At this point the user can participate in any multiuser activity. All gameplay is relative to the one SSA. |
More Information on Unity-Discover |
The GitHub page Unity-Discover Documentation provides the developer’s information on building, using, and understanding the app.Shared Spatial Anchors Troubleshooting Guide |
Unity |
All-In-One VR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.