LipSyncDemo_SetCurrentTarget.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using UnityEngine;
  3. public class LipSyncDemo_SetCurrentTarget : MonoBehaviour
  4. {
  5. private void Start()
  6. {
  7. OVRMessenger.AddListener<OVRTouchpad.TouchEvent>("Touchpad", new OVRCallback<OVRTouchpad.TouchEvent>(this.LocalTouchEventCallback));
  8. this.targetSet = 0;
  9. this.SwitchTargets[0].SetActive(0);
  10. this.SwitchTargets[1].SetActive(0);
  11. }
  12. private void Update()
  13. {
  14. if (Input.GetKeyDown(KeyCode.Alpha1))
  15. {
  16. this.targetSet = 0;
  17. this.SetCurrentTarget();
  18. }
  19. else if (Input.GetKeyDown(KeyCode.Alpha2))
  20. {
  21. this.targetSet = 1;
  22. this.SetCurrentTarget();
  23. }
  24. else if (Input.GetKeyDown(KeyCode.Alpha3))
  25. {
  26. this.targetSet = 2;
  27. this.SetCurrentTarget();
  28. }
  29. else if (Input.GetKeyDown(KeyCode.Alpha4))
  30. {
  31. this.targetSet = 3;
  32. this.SetCurrentTarget();
  33. }
  34. else if (Input.GetKeyDown(KeyCode.Alpha5))
  35. {
  36. this.targetSet = 4;
  37. this.SetCurrentTarget();
  38. }
  39. else if (Input.GetKeyDown(KeyCode.Alpha6))
  40. {
  41. this.targetSet = 5;
  42. this.SetCurrentTarget();
  43. }
  44. if (Input.GetKeyDown(KeyCode.Escape))
  45. {
  46. Application.Quit();
  47. }
  48. }
  49. private void SetCurrentTarget()
  50. {
  51. switch (this.targetSet)
  52. {
  53. case 0:
  54. this.SwitchTargets[0].SetActive(0);
  55. this.SwitchTargets[1].SetActive(0);
  56. break;
  57. case 1:
  58. this.SwitchTargets[0].SetActive(0);
  59. this.SwitchTargets[1].SetActive(1);
  60. break;
  61. case 2:
  62. this.SwitchTargets[0].SetActive(1);
  63. this.SwitchTargets[1].SetActive(2);
  64. break;
  65. case 3:
  66. this.SwitchTargets[0].SetActive(1);
  67. this.SwitchTargets[1].SetActive(3);
  68. break;
  69. case 4:
  70. this.SwitchTargets[0].SetActive(2);
  71. this.SwitchTargets[1].SetActive(4);
  72. break;
  73. case 5:
  74. this.SwitchTargets[0].SetActive(2);
  75. this.SwitchTargets[1].SetActive(5);
  76. break;
  77. }
  78. }
  79. private void LocalTouchEventCallback(OVRTouchpad.TouchEvent touchEvent)
  80. {
  81. if (touchEvent != OVRTouchpad.TouchEvent.Left)
  82. {
  83. if (touchEvent == OVRTouchpad.TouchEvent.Right)
  84. {
  85. this.targetSet++;
  86. if (this.targetSet > 3)
  87. {
  88. this.targetSet = 0;
  89. }
  90. this.SetCurrentTarget();
  91. }
  92. }
  93. else
  94. {
  95. this.targetSet--;
  96. if (this.targetSet < 0)
  97. {
  98. this.targetSet = 3;
  99. }
  100. this.SetCurrentTarget();
  101. }
  102. }
  103. public EnableSwitch[] SwitchTargets;
  104. private int targetSet;
  105. }