// Start is called before the first frame update // Update is called once per frame void Update() { if (VarjoMarkers.IsVarjoMarkersEnabled()) { VarjoMarkers.GetVarjoMarkers(out markers); foreach (var marker in markers) { for (var i = 0; i < trackedObjects.Length; i++) { if (trackedObjects[i].id == marker.id) { trackedObjects[i].gameObject.SetActive(true); trackedObjects[i].gameObject.transform.localPosition = marker.pose.position; trackedObjects[i].gameObject.transform.localRotation = marker.pose.rotation; } } } VarjoMarkers.GetRemovedVarjoMarkerIds(out removedMarkerIds); foreach (var id in removedMarkerIds) { for (var i = 0; i < trackedObjects.Length; i++) { if (trackedObjects[i].id == id) { trackedObjects[i].gameObject.SetActive(false); } } } } }
void Update() { if (markersEnabled != _markersEnabled) { markersEnabled = VarjoMarkers.EnableVarjoMarkers(markersEnabled); _markersEnabled = markersEnabled; } if (VarjoMarkers.IsVarjoMarkersEnabled()) { markers.Clear(); markerIds.Clear(); int foundMarkers = VarjoMarkers.GetVarjoMarkers(out markers); if (markers.Count > 0) { foreach (var marker in markers) { markerIds.Add(marker.id); if (markerVisualizers.ContainsKey(marker.id)) { UpdateMarkerVisualizer(marker); } else { CreateMarkerVisualizer(marker); VarjoMarkers.SetVarjoMarkerTimeout(marker.id, markerTimeout); } } if (markerTimeout != _markerTimeout) { SetMarkerTimeOuts(); _markerTimeout = markerTimeout; } } VarjoMarkers.GetRemovedVarjoMarkerIds(out absentIds); foreach (var id in absentIds) { if (markerVisualizers.ContainsKey(id)) { Destroy(markerVisualizers[id].gameObject); markerVisualizers.Remove(id); } markerIds.Remove(id); } absentIds.Clear(); } if (markerIds.Count == 0 && markerVisualizers.Count > 0) { var ids = markerVisualizers.Keys.ToArray(); foreach (var id in ids) { Destroy(markerVisualizers[id].gameObject); markerVisualizers.Remove(id); } } }
// Update is called once per frame void Update() { // Check if Varjo Marker tracking is enabled and functional. if (VarjoMarkers.IsVarjoMarkersEnabled()) { // Get a list of markers with up-to-date data. VarjoMarkers.GetVarjoMarkers(out markers); // Loop through found markers and update gameobjects matching the marker ID in the array. foreach (var marker in markers) { for (var i = 0; i < trackedObjects.Length; i++) { if (trackedObjects[i].id == marker.id) { // This simple marker manager controls only visibility and pose of the GameObjects. trackedObjects[i].gameObject.SetActive(true); trackedObjects[i].gameObject.transform.localPosition = marker.pose.position; trackedObjects[i].gameObject.transform.localRotation = marker.pose.rotation; } } } // Get a list of IDs of removed markers. VarjoMarkers.GetRemovedVarjoMarkerIds(out removedMarkerIds); // Loop through removed marker IDs and deactivate gameobjects matching the marker IDs in the array. foreach (var id in removedMarkerIds) { for (var i = 0; i < trackedObjects.Length; i++) { if (trackedObjects[i].id == id) { trackedObjects[i].gameObject.SetActive(false); } } } } }