Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class ComeHereGestureController : MonoBehaviour
- {
- enum States
- {
- None,
- InitialOpenHand,
- ClosedHand1,
- OpenHand2,
- ClosedHand2
- }
- static Color highlight1 = new Color(0.1f, 0.1f, 0.5f),
- highlight2 = new Color(0.1f, 0.1f, 0.7f),
- highlight3 = new Color(0.1f, 0.1f, 0.9f);
- States state;
- int correctFrames = 0, wrongFrames = 0, normalDelay = 1, timeout = 20;
- void Update()
- {
- if (!(ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.hand_side == HandSide.Palmside
- && ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.mano_class == ManoClass.GRAB_GESTURE_FAMILY))
- return;
- switch (state)
- {
- case States.None:
- if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 0)
- state = States.InitialOpenHand;
- Debug.Log("InitialOpenHand");
- break;
- case States.InitialOpenHand:
- if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 0)
- correctFrames++;
- else
- wrongFrames++;
- if (correctFrames > normalDelay)
- {
- correctFrames = wrongFrames = 0;
- state = States.ClosedHand1;
- Debug.Log("WaitingForClosedHand1");
- GetComponent<Renderer>().material.color = highlight1;
- }
- break;
- case States.ClosedHand1:
- if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 13)
- correctFrames++;
- else
- wrongFrames++;
- if (correctFrames > normalDelay)
- {
- correctFrames = wrongFrames = 0;
- state = States.OpenHand2;
- Debug.Log("WaitingForOpenHand2");
- GetComponent<Renderer>().material.color = highlight2;
- }
- break;
- case States.OpenHand2:
- if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 0)
- correctFrames++;
- else
- wrongFrames++;
- if (correctFrames > normalDelay)
- {
- correctFrames = wrongFrames = 0;
- state = States.ClosedHand2;
- Debug.Log("WaitingForClosedHand2");
- GetComponent<Renderer>().material.color = highlight3;
- }
- if (wrongFrames > timeout)
- {
- correctFrames = wrongFrames = 0;
- state = States.None;
- Debug.Log("<color=red>States.OpenHand2 - timeout</color>");
- GetComponent<Renderer>().material.color = Color.red;
- }
- break;
- case States.ClosedHand2:
- if (ManomotionManager.Instance.Hand_infos[0].hand_info.gesture_info.state == 13)
- correctFrames++;
- else
- wrongFrames++;
- if (correctFrames > 0)
- {
- correctFrames = wrongFrames = 0;
- Debug.Log("<color=green>COME HERE!</color>");
- state = States.None;
- GetComponent<Renderer>().material.color = Color.green;
- }
- if (wrongFrames > timeout)
- {
- correctFrames = wrongFrames = 0;
- state = States.None;
- Debug.Log("<color=red>States.ClosedHand2 - timeout</color>");
- GetComponent<Renderer>().material.color = Color.red;
- }
- break;
- default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement