text
stringlengths 0
1.11k
|
|---|
m_headsetGuid,
|
NetworkAdapter.NetworkData,
|
NetworkAdapter.NetworkMessenger,
|
sharedAnchorManager,
|
m_alignmentAnchorManager,
|
overrideEventCode
|
);
|
```
|
Using the AlignmentAnchorManager class
|
The AlignmentAnchorManager class plays a significant role in the overall flow because it handles player alignment to the spatial anchor. It is defined in /Packages/com.meta.xr.sdk.colocation/Anchors/AlignmentAnchorManager.cs.
|
The AlignmentAnchorManager class contains the AlignPlayerToAnchor function, as shown here:
|
public void AlignPlayerToAnchor(OVRSpatialAnchor anchor) {
|
Debug.Log("AlignmentAnchorManager: Called AlignPlayerToAnchor");
|
if (_alignmentCoroutine != null) {
|
StopCoroutine(_alignmentCoroutine);
|
_alignmentCoroutine = null;
|
}
|
_alignmentCoroutine = StartCoroutine(AlignmentCoroutine(anchor, 2));
|
}
|
Invoking the AlignPlayerToAnchor function gets the spatial anchor used by the Colocation package. It connects to the Spatial Anchors API in order to align a player to the anchor.
|
ColocationLauncher class
|
Back in the Colocation package, in the ColocationLauncher class, defined in /Packages/com.meta.xr.sdk.colocation/ColocationLauncher/ColocationLauncher.cs.
|
ExecuteAction function
|
This class contains the ExecuteAction function:
|
private void ExecuteAction(ColocationMethod colocationMethod) {
|
switch (colocationMethod) {
|
case ColocationMethod.ColocateAutomatically:
|
ColocateAutomaticallyInternal();
|
break;
|
case ColocationMethod.ColocateByPlayerWithOculusId:
|
ColocateByPlayerWithOculusIdInternal(_oculusIdToColocateTo);
|
break;
|
case ColocationMethod.CreateColocatedSpace:
|
CreateColocatedSpaceInternal();
|
break;
|
default:
|
Debug.LogError($"ColocationLauncher: Unknown action: {colocationMethod}");
|
break;
|
}
|
}
|
ColocationAutomaticallyInternal function
|
The ExecuteAction function can, in turn, call the ColocateAutomaticallyInternal() function. This is where the shared spatial anchors come to play:
|
private async void ColocateAutomaticallyInternal() {
|
Debug.Log("ColocationLauncher: Called Init Anchor Flow");
|
var successfullyAlignedToAnchor = false;
|
List<Anchor> alignmentAnchors = GetAllAlignmentAnchors();
|
foreach (var anchor in alignmentAnchors)
|
if (await AttemptToShareAndLocalizeToAnchor(anchor)) {
|
successfullyAlignedToAnchor = true;
|
Debug.Log($"ColocationLauncher: successfully aligned to anchor with id: {anchor.uuid}");
|
_networkData.AddPlayer(new Player(_myOculusId, anchor.colocationGroupId));
|
AlignPlayerToAnchor();
|
break;
|
}
|
if (!successfullyAlignedToAnchor) {
|
if (CreateAnchorIfColocationFailed)
|
{
|
CreateNewColocatedSpace().Forget();
|
}
|
else
|
{
|
OnAutoColocationFailed?.Invoke();
|
}
|
}
|
}
|
This gets all the alignment anchors by calling the List<Anchor> GetAllAlignmentAnchors() function, as shown here:
|
private List<Anchor> GetAllAlignmentAnchors() {
|
var alignmentAnchors = new List<Anchor>();
|
List<Anchor> allAnchors = _networkData.GetAllAnchors();
|
foreach (var anchor in allAnchors)
|
if (anchor.isAlignmentAnchor) {
|
alignmentAnchors.Add(anchor);
|
}
|
return alignmentAnchors;
|
}
|
The important line here is:
|
List<Anchor> allAnchors = _networkData.GetAllAnchors();
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.