-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathColocationManager.cs
More file actions
40 lines (33 loc) · 1.22 KB
/
ColocationManager.cs
File metadata and controls
40 lines (33 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) Meta Platforms, Inc. and affiliates.
#if FUSION2
using UnityEngine;
using Meta.XR.Samples;
namespace MRMotifs.ColocatedExperiences.Colocation
{
[MetaCodeSample("MRMotifs-ColocatedExperiences")]
public class ColocationManager : MonoBehaviour
{
private Transform m_cameraRigTransform;
private void Awake()
{
m_cameraRigTransform = FindAnyObjectByType<OVRCameraRig>().transform;
}
/// <summary>
/// Aligns the player's tracking space and camera rig to the specified anchor.
/// </summary>
/// <param name="anchor">The spatial anchor to align to.</param>
public void AlignUserToAnchor(OVRSpatialAnchor anchor)
{
if (!anchor || !anchor.Localized)
{
Debug.LogError("Motif: Invalid or un-localized anchor. Cannot align.");
return;
}
var anchorTransform = anchor.transform;
m_cameraRigTransform.position = anchorTransform.InverseTransformPoint(Vector3.zero);
m_cameraRigTransform.eulerAngles = new Vector3(0, -anchorTransform.eulerAngles.y, 0);
Debug.Log("Motif: Alignment complete.");
}
}
}
#endif