Advertisement
daserge

Open Menu gesture for ManoMotion (as in Hololens)

Oct 10th, 2020
2,327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3.  
  4. public class OpenMenuGestureController : MonoBehaviour
  5. {
  6.     enum States
  7.     {
  8.         None,
  9.         InitialClosedHand,
  10.         OpenHand1
  11.     }
  12.  
  13.     States state;
  14.     int correctFrames = 0, wrongFrames = 0, normalDelay = 1, timeout = 20;
  15.  
  16.     public UnityEvent OnMenuOpen;
  17.  
  18.     private void Start()
  19.     {
  20.         ManomotionManager.OnManoMotionFrameProcessed += HandleManoMotionFrameUpdated;
  21.     }
  22.  
  23.     private void OnDestroy()
  24.     {
  25.         ManomotionManager.OnManoMotionFrameProcessed -= HandleManoMotionFrameUpdated;
  26.     }
  27.  
  28.     void HandleManoMotionFrameUpdated()
  29.     {
  30.         if (ManomotionManager.Instance.Hand_infos[0].hand_info.warning == Warning.WARNING_HAND_NOT_FOUND)
  31.             return;
  32.  
  33.         switch (state)
  34.         {
  35.             case States.None:
  36.                 if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 13)
  37.                     state = States.InitialClosedHand;
  38.                 break;
  39.             case States.InitialClosedHand:
  40.                 if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 0
  41.                     && ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.hand_side == HandSide.Palmside)
  42.                     correctFrames++;
  43.                 else
  44.                     wrongFrames++;
  45.  
  46.                 if (correctFrames > normalDelay)
  47.                 {
  48.                     correctFrames = wrongFrames = 0;
  49.                     state = States.OpenHand1;
  50.                 }
  51.  
  52.                 if (wrongFrames > timeout)
  53.                 {
  54.                     correctFrames = wrongFrames = 0;
  55.                     state = States.None;
  56.                 }
  57.  
  58.                 break;
  59.             case States.OpenHand1:
  60.                 if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 0)
  61.                     correctFrames++;
  62.                 else
  63.                     wrongFrames++;
  64.  
  65.                 if (correctFrames > normalDelay)
  66.                 {
  67.                     correctFrames = wrongFrames = 0;
  68.                     state = States.None;
  69.                     OnMenuOpen?.Invoke();
  70.                     enabled = false;
  71.                 }
  72.  
  73.                 break;
  74.             default:
  75.                 break;
  76.         }
  77.     }
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement