6 #if UNITY_2017_2_OR_NEWER 28 private enum AlignmentType
32 UsePresetXAndZWithHeadHeight
36 [Tooltip(
"Optional container object reference. If null, this script will move the object it's attached to.")]
37 private Transform containerObject = null;
39 #if UNITY_2017_2_OR_NEWER 41 [Tooltip(
"Select this if the container should be placed in front of the head on app launch in a room scale app.")]
42 private AlignmentType alignmentType = AlignmentType.AlignWithHeadHeight;
45 [Tooltip(
"Use this to set the desired position of the container in a stationary app. This will be ignored if AlignWithHeadHeight is set.")]
46 private Vector3 stationarySpaceTypePosition = Vector3.zero;
49 [Tooltip(
"Use this to set the desired position of the container in a room scale app. This will be ignored if AlignWithHeadHeight is set.")]
50 private Vector3 roomScaleSpaceTypePosition = Vector3.zero;
52 private Vector3 contentPosition = Vector3.zero;
54 private int frameWaitHack = 0;
59 if (containerObject == null)
61 containerObject = transform;
64 #if UNITY_2017_2_OR_NEWER 68 if (XRDevice.isPresent)
70 StartCoroutine(SetContentHeight());
77 #if UNITY_2017_2_OR_NEWER 78 private IEnumerator SetContentHeight()
80 if (frameWaitHack < 1)
87 if (alignmentType == AlignmentType.UsePresetPositions || alignmentType == AlignmentType.UsePresetXAndZWithHeadHeight)
89 if (XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale)
91 containerObject.position = roomScaleSpaceTypePosition;
93 else if (XRDevice.GetTrackingSpaceType() == TrackingSpaceType.Stationary)
95 containerObject.position = stationarySpaceTypePosition;
99 if (alignmentType == AlignmentType.AlignWithHeadHeight || alignmentType == AlignmentType.UsePresetXAndZWithHeadHeight)
101 contentPosition.x = containerObject.position.x;
102 contentPosition.y = containerObject.position.y +
CameraCache.
Main.transform.position.y;
103 contentPosition.z = containerObject.position.z;
105 containerObject.position = contentPosition;
Use this script on GameObjects you wish to be aligned in certain ways depending on the application sp...