AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
PlaneTargetGroup.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 namespace HoloToolkit.Unity.Tests
7 {
8  public class PlaneTargetGroup : MonoBehaviour
9  {
10  [Tooltip("Enter in same target consecutively to turn on velocity tracking for that target.")]
11  public Transform[] Targets;
12 
13  public bool UseVelocity { get; private set; }
14 
15  [HideInInspector]
16  public Transform CurrentTarget;
17  private int currentTargetIndex;
18 
19  private void Start()
20  {
21  currentTargetIndex = 0;
22  if (Targets.Length > 0)
23  {
24  CurrentTarget = Targets[currentTargetIndex];
25  }
26  }
27 
28  // Pick a new target within this group. Targets are cycled through in
29  // the order in which they exist in the Targets property. Velocity can
30  // be tracked for targets if they exist in Targets array twice and
31  // consecutively
32  public void PickNewTarget()
33  {
34  if (Targets.Length == 0)
35  {
36  return;
37  }
38 
39  UseVelocity = false;
40 
41  ++currentTargetIndex;
42  currentTargetIndex %= Targets.Length;
43 
44  // Track velocity for consecutive duplicate entries
45  Transform newTarget = Targets[currentTargetIndex];
46  if (CurrentTarget == newTarget)
47  {
48  UseVelocity = true;
49  }
50  CurrentTarget = newTarget;
51  }
52  }
53 }