2
0

JoeJeffGestures.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6. namespace Valve.VR.InteractionSystem.Sample
  7. {
  8. public class JoeJeffGestures : MonoBehaviour
  9. {
  10. private const float openFingerAmount = 0.1f;
  11. private const float closedFingerAmount = 0.9f;
  12. private const float closedThumbAmount = 0.4f;
  13. private JoeJeff joeJeff;
  14. private void Awake()
  15. {
  16. joeJeff = this.GetComponent<JoeJeff>();
  17. }
  18. private void Update()
  19. {
  20. if (Player.instance == null)
  21. return;
  22. Transform cam = Camera.main.transform;
  23. bool lookingAt = (Vector3.Angle(cam.forward, transform.position - cam.position) < 90);
  24. if (lookingAt == false)
  25. return;
  26. for (int handIndex = 0; handIndex < Player.instance.hands.Length; handIndex++)
  27. {
  28. if (Player.instance.hands[handIndex] != null)
  29. {
  30. SteamVR_Behaviour_Skeleton skeleton = Player.instance.hands[handIndex].skeleton;
  31. if (skeleton != null)
  32. {
  33. //Debug.LogFormat("{0:0.00}, {1:0.00}, {2:0.00}, {3:0.00}, {4:0.00}", skeleton.thumbCurl, skeleton.indexCurl, skeleton.middleCurl, skeleton.ringCurl, skeleton.pinkyCurl);
  34. if ((skeleton.indexCurl <= openFingerAmount && skeleton.middleCurl <= openFingerAmount) &&
  35. (skeleton.thumbCurl >= closedThumbAmount && skeleton.ringCurl >= closedFingerAmount && skeleton.pinkyCurl >= closedFingerAmount))
  36. {
  37. PeaceSignRecognized(true);
  38. }
  39. else
  40. {
  41. PeaceSignRecognized(false);
  42. }
  43. }
  44. }
  45. }
  46. }
  47. private bool lastPeaceSignState = false;
  48. private void PeaceSignRecognized(bool currentPeaceSignState)
  49. {
  50. if (lastPeaceSignState == false && currentPeaceSignState == true)
  51. {
  52. joeJeff.Jump();
  53. }
  54. lastPeaceSignState = currentPeaceSignState;
  55. }
  56. }
  57. }