/
SDK_OculusVRBoundaries.cs
118 lines (106 loc) · 4.56 KB
/
SDK_OculusVRBoundaries.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// OculusVR Boundaries|SDK_OculusVR|004
namespace VRTK
{
#if VRTK_SDK_OCULUSVR
using UnityEngine;
/// <summary>
/// The OculusVR Boundaries SDK script provides a bridge to the OculusVR SDK play area.
/// </summary>
public class SDK_OculusVRBoundaries : SDK_BaseBoundaries
{
/// <summary>
/// The InitBoundaries method is run on start of scene and can be used to initialse anything on game start.
/// </summary>
public override void InitBoundaries()
{
#if VRTK_SDK_OCULUSVR_AVATAR
GetAvatar();
#endif
}
/// <summary>
/// The GetPlayArea method returns the Transform of the object that is used to represent the play area in the scene.
/// </summary>
/// <returns>A transform of the object representing the play area in the scene.</returns>
public override Transform GetPlayArea()
{
cachedPlayArea = GetSDKManagerPlayArea();
if (cachedPlayArea == null)
{
var ovrManager = FindObjectOfType<OVRManager>();
if (ovrManager)
{
cachedPlayArea = ovrManager.transform;
}
}
return cachedPlayArea;
}
/// <summary>
/// The GetPlayAreaVertices method returns the points of the play area boundaries.
/// </summary>
/// <param name="playArea">The GameObject containing the play area representation.</param>
/// <returns>A Vector3 array of the points in the scene that represent the play area boundaries.</returns>
public override Vector3[] GetPlayAreaVertices(GameObject playArea)
{
var area = new OVRBoundary();
if (area.GetConfigured())
{
var outerBoundary = area.GetDimensions(OVRBoundary.BoundaryType.OuterBoundary);
var thickness = 0.1f;
var vertices = new Vector3[8];
vertices[0] = new Vector3(outerBoundary.x - thickness, 0f, outerBoundary.z - thickness);
vertices[1] = new Vector3(0f + thickness, 0f, outerBoundary.z - thickness);
vertices[2] = new Vector3(0f + thickness, 0f, 0f + thickness);
vertices[3] = new Vector3(outerBoundary.x - thickness, 0f, 0f + thickness);
vertices[4] = new Vector3(outerBoundary.x, 0f, outerBoundary.z);
vertices[5] = new Vector3(0f, 0f, outerBoundary.z);
vertices[6] = new Vector3(0f, 0f, 0f);
vertices[7] = new Vector3(outerBoundary.x, 0f, 0f);
return vertices;
}
return new Vector3[0];
}
/// <summary>
/// The GetPlayAreaBorderThickness returns the thickness of the drawn border for the given play area.
/// </summary>
/// <param name="playArea">The GameObject containing the play area representation.</param>
/// <returns>The thickness of the drawn border.</returns>
public override float GetPlayAreaBorderThickness(GameObject playArea)
{
return 0.1f;
}
/// <summary>
/// The IsPlayAreaSizeCalibrated method returns whether the given play area size has been auto calibrated by external sensors.
/// </summary>
/// <param name="playArea">The GameObject containing the play area representation.</param>
/// <returns>Returns true if the play area size has been auto calibrated and set by external sensors.</returns>
public override bool IsPlayAreaSizeCalibrated(GameObject playArea)
{
return true;
}
#if VRTK_SDK_OCULUSVR_AVATAR
private OvrAvatar avatarContainer;
/// <summary>
/// The GetAvatar method is used to retrieve the Oculus Avatar object if it exists in the scene. This method is only available if the Oculus Avatar package is installed.
/// </summary>
/// <returns>The OvrAvatar script for managing the Oculus Avatar.</returns>
public virtual OvrAvatar GetAvatar()
{
if (avatarContainer == null)
{
avatarContainer = FindObjectOfType<OvrAvatar>();
if (avatarContainer)
{
var objectFollow = avatarContainer.gameObject.AddComponent<VRTK_TransformFollow>();
objectFollow.gameObjectToFollow = GetPlayArea().gameObject;
}
}
return avatarContainer;
}
#endif
}
#else
public class SDK_OculusVRBoundaries : SDK_FallbackBoundaries
{
}
#endif
}