OvrControllerButtons.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using System;
  2. using UnityEngine;
  3. public class OvrControllerButtons : AVRControllerButtons
  4. {
  5. protected override void Awake()
  6. {
  7. base.Awake();
  8. this.m_eType = AVRControllerButtons.TYPE.TOUCH;
  9. this.m_goHandModel = base.transform.Find("HandPlayer").gameObject;
  10. }
  11. public override bool ShowHand
  12. {
  13. get
  14. {
  15. return this.m_goHandModel.activeSelf;
  16. }
  17. set
  18. {
  19. this.m_goHandModel.SetActive(value);
  20. }
  21. }
  22. public override void Haptic(byte f_byFoce, float f_fTime)
  23. {
  24. byte[] array = new byte[(int)(320f * f_fTime)];
  25. for (int i = 0; i < array.Length; i++)
  26. {
  27. array[i] = f_byFoce;
  28. }
  29. this.m_HapticsClip = new OVRHapticsClip(array, array.Length);
  30. if (this.m_bHandL)
  31. {
  32. OVRHaptics.LeftChannel.Mix(this.m_HapticsClip);
  33. }
  34. else
  35. {
  36. OVRHaptics.RightChannel.Mix(this.m_HapticsClip);
  37. }
  38. }
  39. public override bool GetPressDown(AVRControllerButtons.BTN f_eBtn)
  40. {
  41. if (f_eBtn != AVRControllerButtons.BTN.VIRTUAL_GRUB)
  42. {
  43. return OVRInput.GetDown((OVRInput.RawButton)this.m_aryBtn2RealOvr[(int)f_eBtn, (!this.m_bHandL) ? 1 : 0], OVRInput.Controller.Active);
  44. }
  45. if (this.m_bHandL)
  46. {
  47. return (OVRInput.GetDown(OVRInput.RawButton.LHandTrigger, OVRInput.Controller.Active) && OVRInput.GetDown(OVRInput.RawButton.LIndexTrigger, OVRInput.Controller.Active)) || (!OVRInput.Get(OVRInput.RawButton.LHandTrigger, OVRInput.Controller.Active) && OVRInput.GetDown(OVRInput.RawButton.LIndexTrigger, OVRInput.Controller.Active)) || (!OVRInput.Get(OVRInput.RawButton.LIndexTrigger, OVRInput.Controller.Active) && OVRInput.GetDown(OVRInput.RawButton.LHandTrigger, OVRInput.Controller.Active));
  48. }
  49. return (OVRInput.GetDown(OVRInput.RawButton.RHandTrigger, OVRInput.Controller.Active) && OVRInput.GetDown(OVRInput.RawButton.RIndexTrigger, OVRInput.Controller.Active)) || (!OVRInput.Get(OVRInput.RawButton.RHandTrigger, OVRInput.Controller.Active) && OVRInput.GetDown(OVRInput.RawButton.RIndexTrigger, OVRInput.Controller.Active)) || (!OVRInput.Get(OVRInput.RawButton.RIndexTrigger, OVRInput.Controller.Active) && OVRInput.GetDown(OVRInput.RawButton.RHandTrigger, OVRInput.Controller.Active));
  50. }
  51. public override bool GetPress(AVRControllerButtons.BTN f_eBtn)
  52. {
  53. if (f_eBtn == AVRControllerButtons.BTN.VIRTUAL_GRUB)
  54. {
  55. return (!this.m_bHandL) ? (OVRInput.Get(OVRInput.RawButton.RHandTrigger, OVRInput.Controller.Active) || OVRInput.Get(OVRInput.RawButton.RIndexTrigger, OVRInput.Controller.Active)) : (OVRInput.Get(OVRInput.RawButton.LHandTrigger, OVRInput.Controller.Active) || OVRInput.Get(OVRInput.RawButton.LIndexTrigger, OVRInput.Controller.Active));
  56. }
  57. return OVRInput.Get((OVRInput.RawButton)this.m_aryBtn2RealOvr[(int)f_eBtn, (!this.m_bHandL) ? 1 : 0], OVRInput.Controller.Active);
  58. }
  59. public override bool GetPressUp(AVRControllerButtons.BTN f_eBtn)
  60. {
  61. if (f_eBtn == AVRControllerButtons.BTN.VIRTUAL_GRUB)
  62. {
  63. return (!this.m_bHandL) ? ((!OVRInput.Get(OVRInput.RawButton.RIndexTrigger, OVRInput.Controller.Active) && OVRInput.GetUp(OVRInput.RawButton.RHandTrigger, OVRInput.Controller.Active)) || (!OVRInput.Get(OVRInput.RawButton.RHandTrigger, OVRInput.Controller.Active) && OVRInput.GetUp(OVRInput.RawButton.RIndexTrigger, OVRInput.Controller.Active))) : ((!OVRInput.Get(OVRInput.RawButton.LIndexTrigger, OVRInput.Controller.Active) && OVRInput.GetUp(OVRInput.RawButton.LHandTrigger, OVRInput.Controller.Active)) || (!OVRInput.Get(OVRInput.RawButton.LHandTrigger, OVRInput.Controller.Active) && OVRInput.GetUp(OVRInput.RawButton.LIndexTrigger, OVRInput.Controller.Active)));
  64. }
  65. return OVRInput.GetUp((OVRInput.RawButton)this.m_aryBtn2RealOvr[(int)f_eBtn, (!this.m_bHandL) ? 1 : 0], OVRInput.Controller.Active);
  66. }
  67. public override bool GetTouchDown(AVRControllerButtons.TOUCH f_eTouch)
  68. {
  69. return OVRInput.GetDown((OVRInput.RawTouch)this.m_aryTouch2RealOvr[(int)f_eTouch, (!this.m_bHandL) ? 1 : 0], OVRInput.Controller.Active);
  70. }
  71. public override bool GetTouch(AVRControllerButtons.TOUCH f_eTouch)
  72. {
  73. return OVRInput.Get((OVRInput.RawTouch)this.m_aryTouch2RealOvr[(int)f_eTouch, (!this.m_bHandL) ? 1 : 0], OVRInput.Controller.Active);
  74. }
  75. public override bool GetTouchUp(AVRControllerButtons.TOUCH f_eTouch)
  76. {
  77. return OVRInput.GetUp((OVRInput.RawTouch)this.m_aryTouch2RealOvr[(int)f_eTouch, (!this.m_bHandL) ? 1 : 0], OVRInput.Controller.Active);
  78. }
  79. public override Vector2 GetAxis()
  80. {
  81. return OVRInput.Get((!this.m_bHandL) ? OVRInput.RawAxis2D.RThumbstick : OVRInput.RawAxis2D.LThumbstick, OVRInput.Controller.Active);
  82. }
  83. public override float GetTriggerRate()
  84. {
  85. if (this.m_bHandL)
  86. {
  87. return OVRInput.Get(OVRInput.RawAxis1D.LIndexTrigger, OVRInput.Controller.Active);
  88. }
  89. return OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger, OVRInput.Controller.Active);
  90. }
  91. private void Update()
  92. {
  93. }
  94. private uint[,] m_aryBtn2RealOvr = new uint[,]
  95. {
  96. {
  97. 512U,
  98. 2U
  99. },
  100. {
  101. 256U,
  102. 1U
  103. },
  104. {
  105. 1024U,
  106. 4U
  107. },
  108. {
  109. 536870912U,
  110. 134217728U
  111. },
  112. {
  113. 1048576U,
  114. 1048576U
  115. },
  116. {
  117. 268435456U,
  118. 67108864U
  119. },
  120. {
  121. 1024U,
  122. 4U
  123. },
  124. {
  125. 536870912U,
  126. 134217728U
  127. }
  128. };
  129. private uint[,] m_aryTouch2RealOvr = new uint[,]
  130. {
  131. {
  132. 4096U,
  133. 16U
  134. },
  135. {
  136. 1024U,
  137. 4U
  138. },
  139. {
  140. 2048U,
  141. 8U
  142. },
  143. {
  144. 512U,
  145. 2U
  146. },
  147. {
  148. 256U,
  149. 1U
  150. }
  151. };
  152. private GameObject m_goHandModel;
  153. private OVRHapticsClip m_HapticsClip;
  154. }