AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
GestureControlCycler.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 
5 using System.Collections;
6 using System.Collections.Generic;
7 using UnityEngine;
8 
9 
10 namespace HoloToolkit.Examples.InteractiveElements
11 {
16  {
17  public struct CycleData
18  {
19  public int Index;
21  }
22 
23  [Tooltip("An array of GameObjects that contain an ICycle component")]
24  public GameObject[] CycleControllers;
25 
26  // the new list of ICycle components so we can track the last index before gesture starts
27  private List<CycleData> mCycleList;
28 
32  private void Start()
33  {
34  mCycleList = new List<CycleData>();
35 
36  for (int i = 0; i < CycleControllers.Length; ++ i)
37  {
38  ICycle cycle = CycleControllers[i].GetComponent<ICycle>();
39  if (cycle != null)
40  {
41  CycleData data = new CycleData();
42  data.Controller = cycle;
43  data.Index = cycle.Index;
44  mCycleList.Add(data);
45  }
46  }
47  }
48 
49  public override void ManipulationUpdate(Vector3 startGesturePosition, Vector3 currentGesturePosition, Vector3 startHeadOrigin, Vector3 startHeadRay, GestureInteractive.GestureManipulationState gestureState)
50  {
51  base.ManipulationUpdate(startGesturePosition, currentGesturePosition, startHeadOrigin, startHeadRay, gestureState);
52 
53  // get gesture data for gesturing along the horizontal axis
54  GestureInteractiveData gestureData = GetGestureData(new Vector3(1, 0, 0), MaxGestureDistance, FlipDirectionOnCameraForward);
55 
56  for (int i = 0; i < mCycleList.Count; ++i)
57  {
58 
59  CycleData data = mCycleList[i];
60  // get the length of ICycle values to loop through
61  float length = data.Controller.GetLastIndex() + 1;
62  float incrament = MaxGestureDistance / length;
63 
64  // get the delta of the current gesture
65  int offset = Mathf.RoundToInt(gestureData.Distance / incrament);
66  if (gestureState == GestureInteractive.GestureManipulationState.Start)
67  {
68  // set the starting index so we can add the delta to it
69  data.Index = data.Controller.Index;
70 
71  mCycleList[i] = data;
72  }
73 
74  // update the ICycle component
75  data.Controller.SetIndex(Mathf.Clamp(offset + data.Index, 0, data.Controller.GetLastIndex()));
76  }
77  }
78  }
79 }
Sample GestureInteractiveControl for scrubbing through ICylce components
override void ManipulationUpdate(Vector3 startGesturePosition, Vector3 currentGesturePosition, Vector3 startHeadOrigin, Vector3 startHeadRay, GestureInteractive.GestureManipulationState gestureState)
Gesture updates called by GestureInteractive
GestureInteractive extends Interactive and handles more advanced gesture events. On Press a gesture b...
void SetIndex(int index)
Assign a specific element from the array. Place your custom logic to assign an element to TargetObjec...
GestureInteractiveControl receives gesture updates from GestureInteractive.
An interface for components that cycle through an array of properties. A component can be built to cy...
Definition: ICycle.cs:13
int GetLastIndex()
Retrieve the last index of the array.