-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetCorrectCameraHeight.cs
60 lines (49 loc) · 1.81 KB
/
SetCorrectCameraHeight.cs
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using UnityEngine;
using UnityEngine.XR;
public class SetCorrectCameraHeight : MonoBehaviour
{
enum TrackingSpace
{
Stationary,
RoomScale
}
[Header("Camera Settings")]
[SerializeField]
[Tooltip("Decide if experience is Room Scale or Stationary. Note this option does nothing for mobile VR experiences, these experience will default to Stationary")]
TrackingSpace m_TrackingSpace = TrackingSpace.Stationary;
[SerializeField]
[Tooltip("Camera Height - overwritten by device settings when using Room Scale ")]
float m_StationaryCameraYOffset = 1.36144f;
[SerializeField]
[Tooltip("GameObject to move to desired height off the floor (defaults to this object if none provided)")]
GameObject m_CameraFloorOffsetObject;
void Awake()
{
if (!m_CameraFloorOffsetObject)
{
Debug.LogWarning("No camera container specified for VR Rig, using attached GameObject");
m_CameraFloorOffsetObject = this.gameObject;
}
}
void Start()
{
SetCameraHeight();
}
void SetCameraHeight()
{
float cameraYOffset = m_StationaryCameraYOffset;
if (m_TrackingSpace == TrackingSpace.Stationary)
{
XRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary);
InputTracking.Recenter();
}
else if (m_TrackingSpace == TrackingSpace.RoomScale)
{
if (XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale))
cameraYOffset = 0;
}
//Move camera to correct height
if (m_CameraFloorOffsetObject)
m_CameraFloorOffsetObject.transform.localPosition = new Vector3(m_CameraFloorOffsetObject.transform.localPosition.x, cameraYOffset, m_CameraFloorOffsetObject.transform.localPosition.z);
}
}