10using System.Collections;
34 [Tooltip(
"The interval in seconds at which to check this detector's conditions.")]
44 [Tooltip(
"The hand model to watch. Set automatically if detector is on a hand.")]
48 [Header(
"Finger States")]
49 [Tooltip(
"Required state of the thumb.")]
52 [Tooltip(
"Required state of the index finger.")]
55 [Tooltip(
"Required state of the middle finger.")]
58 [Tooltip(
"Required state of the ring finger.")]
61 [Tooltip(
"Required state of the little finger.")]
65 [Header(
"Min and Max Finger Counts")]
67 [Tooltip(
"The minimum number of fingers extended.")]
71 [Tooltip(
"The maximum number of fingers extended.")]
77 [Tooltip(
"Draw this detector's Gizmos, if any. (Gizmos must be on in Unity edtor, too.)")]
80 private IEnumerator watcherCoroutine;
83 int required = 0, forbidden = 0;
85 for(
int i=0; i<stateArray.Length; i++) {
86 var state = stateArray[i];
105 watcherCoroutine = extendedFingerWatcher();
109 StartCoroutine(watcherCoroutine);
113 StopCoroutine(watcherCoroutine);
117 IEnumerator extendedFingerWatcher() {
120 bool fingerState =
false;
124 fingerState = matchFingerState(hand.Fingers[0],
Thumb)
125 && matchFingerState(hand.Fingers[1],
Index)
126 && matchFingerState(hand.Fingers[2],
Middle)
127 && matchFingerState(hand.Fingers[3],
Ring)
128 && matchFingerState(hand.Fingers[4],
Pinky);
130 int extendedCount = 0;
131 for (
int f = 0; f < 5; f++) {
132 if (hand.Fingers[f].IsExtended) {
136 fingerState = fingerState &&
148 yield
return new WaitForSeconds(
Period);
152 private bool matchFingerState (Finger finger,
PointingState requiredState) {
154 (requiredState ==
PointingState.Extended && finger.IsExtended) ||
155 (requiredState ==
PointingState.NotExtended && !finger.IsExtended);
159 void OnDrawGizmos () {
163 int extendedCount = 0;
164 int notExtendedCount = 0;
165 for (
int f = 0; f < 5; f++) {
166 Finger finger = hand.
Fingers[f];
167 if (finger.IsExtended) extendedCount++;
168 else notExtendedCount++;
169 if (matchFingerState(finger, state[f]) &&
176 Gizmos.DrawWireSphere(finger.TipPosition.ToVector3(), finger.Width);
List< Finger > Fingers
The list of Finger objects detected in this frame that are attached to this hand, given in order from...
virtual void Deactivate()
abstract Hand GetLeapHand()
A data structure that represents either a value of type A or a value of type B. The value can never b...