var anchors = new List<OVRAnchor>();
var result = await OVRAnchor.FetchAnchorsAsync(anchors, new OVRAnchor.FetchOptions
{
SingleComponentType = typeof(OVRRoomLayout),
});
// no rooms - call Space Setup or check Scene permission
if (!result.Success || anchors.Count == 0)
return;
// get the component to access its data
foreach (var room in anchors)
{
if (!room.TryGetComponent(out OVRAnchorContainer container))
continue;
// use the component helper function to access all child anchors
await container.FetchChildrenAsync(anchors);
}
// the transform of the OVRCameraRig's TrackingSpace
Transform trackingSpace;
foreach (var anchor in anchors)
{
// check that this anchor is the floor
if (!anchor.TryGetComponent(out OVRSemanticLabels labels) ||
!labels.Labels.Contains(OVRSceneManager.Classification.Floor)))
{
continue;
}
// enable locatable/tracking
if (!anchor.TryGetComponent(out OVRLocatable locatable))
continue;
await locatable.SetEnabledAsync(true);
// localize the anchor
locatable.TryGetSceneAnchorPose(out var pose);
this.transform.SetPositionAndRotation(
pose.ComputeWorldPosition(trackingSpace).GetValueOrDefault(),
pose.ComputeWorldRotation(trackingSpace).GetValueOrDefault()
);
// get the floor dimensions
anchor.TryGetComponent(out OVRBounded2D bounded2D);
var size = bounded2D.BoundingBox.size;
// only interested in the first floor anchor
break;
}
// you should previously have set this object's transform using the OVRLocatable pose
var parent = this.gameObject;
// create a child Unity game object
var plane = GameObject.CreatePrimitive(PrimitiveType.Cube);
plane.transform.SetParent(parent.transform, false);
// set the object transform to the bounds
anchor.TryGetComponent(out OVRBounded2D bounded2D);
plane.transform.localScale = new Vector3(
bounded2D.BoundingBox.size.x,
bounded2D.BoundingBox.size.y,
0.01f);