using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Collections;
namespace Ximmerse.XR.Tag
{
///
/// Track reference. Anchor set transform to tracked marker.
///
//[AddComponentMenu("Ximmerse XR/Track reference")]
public class XRTrackReference : MonoBehaviour
{
public int referenceID = 0;
private void OnEnable()
{
XRManager.OnTrackUpdate += XRManager_OnTrackUpdate;
}
private void XRManager_OnTrackUpdate(NativeArray tracked, NativeArray unTracked, NativeArray added, NativeArray lost)
{
for (int i = 0; i < tracked.Length; i++)
{
TrackingResult t = tracked[i];
if (t.id == this.referenceID)
{
transform.SetPositionAndRotation(t.worldPose.position, t.worldPose.rotation);
break;
}
}
}
private void OnDisable()
{
XRManager.OnTrackUpdate -= XRManager_OnTrackUpdate;
}
}
}