Skip to content
This repository was archived by the owner on Nov 16, 2024. It is now read-only.

Commit e1f60a8

Browse files
Support Unity 2019 (#38)
* Replace GetLocalPosition/Rotation (Unity deprecated API) with GetNodeStates. * Disable playmode tests for all assemblies.
1 parent 38065eb commit e1f60a8

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Assets/WorldLocking.Core/Scripts/AnchorManager.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public bool Update()
187187
// The decision between low-level access via InputTracking and high-level access via Camera.main.transform should
188188
// be coordinated with the decision between high-level access to WorldAnchor and low-level access to
189189
// Windows.Perception.Spatial.SpatialAnchor -- see comment at top of SpongyAnchor.cs
190-
Pose spongyHead = new Pose(InputTracking.GetLocalPosition(XRNode.Head), InputTracking.GetLocalRotation(XRNode.Head));
190+
Pose spongyHead = GetHeadPose();
191191

192192
// place new anchors 1m below head
193193
Pose newSpongyAnchorPose = spongyHead;
@@ -276,6 +276,39 @@ public bool Update()
276276
return true;
277277
}
278278

279+
private readonly List<XRNodeState> nodeStates = new List<XRNodeState>();
280+
281+
private Pose headPose = Pose.identity;
282+
283+
public Pose GetHeadPose()
284+
{
285+
// Note:
286+
// The low-level input obtained via InputTracking.GetLocal???(XRNode.Head) is automatically kept in sync with
287+
// Camera.main.transform.local??? (unless XRDevice.DisableAutoXRCameraTracking(Camera.main, true) is used to deactivate
288+
// this mechanism). In theory, both could be used interchangeably, potentially allowing to avoid the dependency
289+
// on low-level code at this point. It is not clear though, whether both values follow exactly the same timing or which
290+
// one is more correct to be used at this point. More research might be necessary.
291+
//
292+
// The decision between low-level access via InputTracking and high-level access via Camera.main.transform should
293+
// be coordinated with the decision between high-level access to WorldAnchor and low-level access to
294+
// Windows.Perception.Spatial.SpatialAnchor -- see comment at top of SpongyAnchor.cs
295+
nodeStates.Clear();
296+
InputTracking.GetNodeStates(nodeStates);
297+
for (int i = 0; i < nodeStates.Count; ++i)
298+
{
299+
if (nodeStates[i].nodeType == XRNode.Head)
300+
{
301+
Vector3 position;
302+
Quaternion rotation;
303+
if (nodeStates[i].tracked && nodeStates[i].TryGetPosition(out position) && nodeStates[i].TryGetRotation(out rotation))
304+
{
305+
headPose = new Pose(position, rotation);
306+
}
307+
}
308+
}
309+
return headPose;
310+
}
311+
279312
private SpongyAnchor CreateAnchor(AnchorId id)
280313
{
281314
var newAnchorObject = new GameObject(id.FormatStr());

ProjectSettings/ProjectSettings.asset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ PlayerSettings:
308308
tvOS: 1
309309
m_BuildTargetGroupLightmapEncodingQuality: []
310310
m_BuildTargetGroupLightmapSettings: []
311-
playModeTestRunnerEnabled: 1
311+
playModeTestRunnerEnabled: 0
312312
runPlayModeTestAsEditModeTest: 0
313313
actionOnDotNetUnhandledException: 1
314314
enableInternalProfiler: 0

0 commit comments

Comments
 (0)