Advertisement
daserge

"Come Here" gesture for Manomotion

May 30th, 2019
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class ComeHereGestureController : MonoBehaviour
  4. {
  5.     enum States
  6.     {
  7.         None,
  8.         InitialOpenHand,
  9.         ClosedHand1,
  10.         OpenHand2,
  11.         ClosedHand2
  12.     }
  13.  
  14.     static Color highlight1 = new Color(0.1f, 0.1f, 0.5f),
  15.         highlight2 = new Color(0.1f, 0.1f, 0.7f),
  16.         highlight3 = new Color(0.1f, 0.1f, 0.9f);
  17.  
  18.     States state;
  19.     int correctFrames = 0, wrongFrames = 0, normalDelay = 1, timeout = 20;
  20.     void Update()
  21.     {
  22.         if (!(ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.hand_side == HandSide.Palmside
  23.             && ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.mano_class == ManoClass.GRAB_GESTURE_FAMILY))
  24.             return;
  25.  
  26.         switch (state)
  27.         {
  28.             case States.None:
  29.                 if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 0)
  30.                     state = States.InitialOpenHand;
  31.                     Debug.Log("InitialOpenHand");
  32.                 break;
  33.             case States.InitialOpenHand:
  34.                 if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 0)
  35.                     correctFrames++;
  36.                 else
  37.                     wrongFrames++;
  38.  
  39.                 if (correctFrames > normalDelay)
  40.                 {
  41.                     correctFrames = wrongFrames = 0;
  42.                     state = States.ClosedHand1;
  43.                     Debug.Log("WaitingForClosedHand1");
  44.                     GetComponent<Renderer>().material.color = highlight1;
  45.                 }
  46.  
  47.                 break;
  48.             case States.ClosedHand1:
  49.                 if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 13)
  50.                     correctFrames++;
  51.                 else
  52.                     wrongFrames++;
  53.  
  54.                 if (correctFrames > normalDelay)
  55.                 {
  56.                     correctFrames = wrongFrames = 0;
  57.                     state = States.OpenHand2;
  58.                     Debug.Log("WaitingForOpenHand2");
  59.                     GetComponent<Renderer>().material.color = highlight2;
  60.                 }
  61.  
  62.                 break;
  63.             case States.OpenHand2:
  64.                 if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 0)
  65.                     correctFrames++;
  66.                 else
  67.                     wrongFrames++;
  68.  
  69.                 if (correctFrames > normalDelay)
  70.                 {
  71.                     correctFrames = wrongFrames = 0;
  72.                     state = States.ClosedHand2;
  73.                     Debug.Log("WaitingForClosedHand2");
  74.                     GetComponent<Renderer>().material.color = highlight3;
  75.                 }
  76.  
  77.                 if (wrongFrames > timeout)
  78.                 {
  79.                     correctFrames = wrongFrames = 0;
  80.                     state = States.None;
  81.                     Debug.Log("<color=red>States.OpenHand2 - timeout</color>");
  82.                     GetComponent<Renderer>().material.color = Color.red;
  83.                 }
  84.  
  85.                 break;
  86.             case States.ClosedHand2:
  87.                 if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 13)
  88.                     correctFrames++;
  89.                 else
  90.                     wrongFrames++;
  91.  
  92.                 if (correctFrames > 0)
  93.                 {
  94.                     correctFrames = wrongFrames = 0;
  95.                     Debug.Log("<color=green>COME HERE!</color>");
  96.                     state = States.None;
  97.                     GetComponent<Renderer>().material.color = Color.green;
  98.                 }
  99.  
  100.                 if (wrongFrames > timeout)
  101.                 {
  102.                     correctFrames = wrongFrames = 0;
  103.                     state = States.None;
  104.                     Debug.Log("<color=red>States.ClosedHand2 - timeout</color>");
  105.                     GetComponent<Renderer>().material.color = Color.red;
  106.                 }
  107.  
  108.                 break;
  109.             default:
  110.                 break;
  111.         }
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement