text
stringlengths 0
1.11k
|
|---|
The m_colocationLauncher variable is a ColocationLauncher object. In the ColocationLauncher.cs script, the CreateColocatedSpace() method calls CreateAlignmentAnchor, which creates the spatial anchor and saves it to the cloud. We look into this more deeply in the following sections.
|
// ColocationLauncher.cs
|
213 private async UniTaskVoid CreateNewColocatedSpace() {
|
214 _myAlignmentAnchor = await CreateAlignmentAnchor();
|
215 if (_myAlignmentAnchor == null) {
|
216 Debug.LogError("ColocationLauncher: Could not create the anchor");
|
217 return;
|
218 }
|
Create the Anchor
|
Here’s how the anchor is created. CreateAlignmentAnchor is also in the ColocationLauncher.cs script. It immediately calls the SharedAnchorManager.cs script CreateAnchor method, which in turn calls InstantiateAnchor right away. InstantiateAnchor uses the game object to create a new anchor based on the AnchorPrefab prefab.
|
// ColocationLauncher.cs
|
316 private async UniTask<OVRSpatialAnchor> CreateAlignmentAnchor() {
|
315 var anchor = await _sharedAnchorManager.CreateAnchor(Vector3.zero, Quaternion.identity);
|
316 if (anchor == null) {
|
317 Debug.Log("ColocationLauncher: _sharedAnchorManager.CreateAnchor returned null");
|
318 }
|
// SharedAnchorManager.cs
|
31 public async UniTask<OVRSpatialAnchor> CreateAnchor(Vector3 position, Quaternion orientation) {
|
32 Debug.Log("CreateAnchor: Attempt to InstantiateAnchor");
|
33 var anchor = InstantiateAnchor();
|
34 Debug.Log("CreateAnchor: Attempt to Set Position and Rotation of Anchor");
|
...
|
153 private OVRSpatialAnchor InstantiateAnchor() {
|
154 GameObject anchorGo;
|
155 if (AnchorPrefab != null) {
|
156 anchorGo = Object.Instantiate(AnchorPrefab);
|
157 } else {
|
158 anchorGo = new GameObject();
|
159 anchorGo.AddComponent<OVRSpatialAnchor>();
|
160 }
|
Save the Anchor
|
With the anchor created, we need to save it to the cloud. Back in ColocationLauncher.cs, CreateAlignmentAnchor calls the SharedAnchorManager.cs script SavelocalAnchorsToCloud method.
|
// ColocationLauncher.cs
|
316 private async UniTask<OVRSpatialAnchor> CreateAlignmentAnchor() {
|
...
|
322 Debug.Log($"ColocationLauncher: Anchor created: {anchor?.Uuid}");
|
323
|
324 bool isAnchorSavedToCloud = await _sharedAnchorManager.SaveLocalAnchorsToCloud();
|
In the SharedAnchorManager.cs script, the SavelocalAnchorsToCloud method is where we finally see the call to OVRSpatialAnchor.Save, which saves the new anchor to the cloud.
|
// SharedAnchorManager.cs
|
56 public async UniTask<bool> SaveLocalAnchorsToCloud() {
|
...
|
63 OVRSpatialAnchor.Save(
|
64 _localAnchors,
|
65 new OVRSpatialAnchor.SaveOptions {Storage = OVRSpace.StorageLocation.Cloud},
|
66 (_, result) => { utcs.TrySetResult(result == OVRSpatialAnchor.OperationResult.Success); }
|
67 );
|
The anchor is now ready to be shared to other players.
|
Align the Host and Anchor
|
Earlier we described how in the ColocationLauncher.cs script, the CreateColocatedSpace() method calls CreateAlignmentAnchor. Later in that same method, it calls AlignPlayerToAnchor:
|
// ColocationLauncher.cs
|
220 uint newColocationGroupdId = _networkData.GetColocationGroupCount();
|
221 _networkData.IncrementColocationGroupCount();
|
222 _networkData.AddAnchor(new Anchor(true, _myAlignmentAnchor.Uuid.ToString(), _myOculusId, newColocationGroupdId));
|
223 _networkData.AddPlayer(new Player(_myOculusId, newColocationGroupdId));
|
224 AlignPlayerToAnchor();
|
225 await UniTask.Yield();
|
226 }
|
This method is part of the AlignmentAnchorManager.cs script, and is called for every player, including the host. This is a async operation, so the actual work falls to the AlignmentCoroutine method to align both the user camera and hands.
|
// AlignmentAnchorManager.cs
|
62 private IEnumerator AlignmentCoroutine(OVRSpatialAnchor anchor, int alignmentCount) {
|
63 Debug.Log("AlignmentAnchorManager: called AlignmentCoroutine");
|
...
|
66 _cameraRigTransform.position = anchorTransform.InverseTransformPoint(Vector3.zero);
|
66 _cameraRigTransform.eulerAngles = new Vector3(0, -anchorTransform.eulerAngles.y, 0);
|
...
|
75 _playerHandsTransform.localPosition = -_cameraRigTransform.position;
|
76 _playerHandsTransform.localEulerAngles = -_cameraRigTransform.eulerAngles;
|
At this point, the game options are displayed to the host. In the following graphic, you can see the location of the SSA (the 0,0,0 point for all room activity). This is the point where the host was standing when the spatial anchor was created.
|
App Selection and SSA
|
Sharing the Anchor
|
Each of the colocation methods in the ColocationLauncher.cs script make a call to AttemptToShareAndLocalizeToAnchor (also in ColocationLauncher.cs). At the end of this method, a call to TellOwnerToShareAnchor transfers control to that method later in the script.`
|
// ColocationLauncher.cs
|
244 private UniTask<bool> AttemptToShareAndLocalizeToAnchor(Anchor anchor) {
|
245 Debug.Log(
|
246 $"ColocationLauncher: Called AttemptToShareAndLocalizeToAnchor with id: {anchor.uuid} and oculusId: {_myOculusId}"
|
247 );
|
...
|
277 _networkMessenger.SendMessageUsingOculusId(
|
278 _caapEventCodeDictionary[CaapEventCode.TellOwnerToShareAnchor],
|
279 anchorOwner,
|
280 data
|
281 );
|
The TellOwnerToShareAnchor method calls the SharedAnchorManager.cs script ShareAnchorsWithUser method.
|
// ColocationLauncher.cs
|
286 private async void TellOwnerToShareAnchor(object data) {
|
287 Debug.Log($"ColocationLauncher: TellOwnerToShareAnchor with oculusId: {_myOculusId}");
|
288 var shareAndLocalizeParams = (ShareAndLocalizeParams) data;
|
289 ulong requestedAnchorOculusId = shareAndLocalizeParams.oculusIdAnchorRequester;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.