ModelK101.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS {
  6. public class ModelK101 : ModelGCBase {
  7. public InputDeviceKSPartUI inputDeviceKSPartUI {
  8. get {
  9. return inputDevicePartUIBase as InputDeviceKSPartUI;
  10. }
  11. }
  12. [Header("Keys")]
  13. public MeshRenderer axkey;
  14. public MeshRenderer bykey;
  15. public MeshRenderer functionKey;
  16. [Header("Joystick")]
  17. public Transform joystick;
  18. public MeshRenderer joystickKey;
  19. [Range(-4,4)]
  20. public float rotationXfactor = 2;
  21. [Range(-4, 4)]
  22. public float rotationZfactor = 2;
  23. public Vector2 joystickInitalValue = new Vector2(8, 8);
  24. public Vector2 joystickTempValue = new Vector2(8, 8);
  25. public Vector3 joystickInitallocalEulerAngles;
  26. [Header("HallForward")]
  27. public MeshRenderer hallFoward;
  28. public Transform HallForward;
  29. public int HallForwardReleaseValue = 10;
  30. public int HallForwardPressValue = 0;
  31. public Vector3 HallForwardReleaseLocalPosition;
  32. public Vector3 HallForwardPressLocalPosition;
  33. public Vector3 HallForwardReleaselocalEulerAngles;
  34. public Vector3 HallForwardPresslocalEulerAngles;
  35. [Header("HallInside")]
  36. public MeshRenderer hallInside;
  37. public Transform HallInside;
  38. public int HallInsideReleaseValue = 10;
  39. public int HallInsidePressValue = 0;
  40. public Vector3 HallInsideReleaseLocalPosition;
  41. public Vector3 HallInsidePressLocalPosition;
  42. public Vector3 HallInsideReleaselocalEulerAngles;
  43. public Vector3 HallInsidePresslocalEulerAngles;
  44. [Header("MaterialVisual")]
  45. public Material _sourcePressMaterial;
  46. public Material _sourceReleaseMaterial;
  47. public Material _sourceTouchEnterMaterial;
  48. protected Material pressMaterial;
  49. protected Material releaseMaterial;
  50. protected Material touchEnterMaterial;
  51. public override void OnSCStart() {
  52. base.OnSCStart();
  53. if (_sourcePressMaterial){
  54. pressMaterial = Instantiate<Material>(_sourcePressMaterial);
  55. }
  56. if (_sourceReleaseMaterial) {
  57. releaseMaterial = Instantiate<Material>(_sourceReleaseMaterial);
  58. }
  59. if (_sourceTouchEnterMaterial){
  60. touchEnterMaterial = Instantiate<Material>(_sourceTouchEnterMaterial);
  61. }
  62. if (axkey)
  63. axkey.sharedMaterial = releaseMaterial;
  64. if (bykey)
  65. bykey.sharedMaterial = releaseMaterial;
  66. if (joystickKey)
  67. joystickKey.sharedMaterial = releaseMaterial;
  68. if (hallFoward)
  69. hallFoward.sharedMaterial = releaseMaterial;
  70. if (hallInside)
  71. hallInside.sharedMaterial = releaseMaterial;
  72. if (functionKey)
  73. functionKey.sharedMaterial = releaseMaterial;
  74. }
  75. void UpdateTransform() {
  76. transform.localPosition = _modelPositionDeltaWithDevice;
  77. }
  78. public override void OnSCLateUpdate() {
  79. base.OnSCLateUpdate();
  80. UpdateTransform();
  81. UpdateJoystickTransform();
  82. UpdateHallVisual();
  83. UpdatePowerUI();
  84. }
  85. public virtual void UpdateHallVisual() {
  86. if(HallForward) {
  87. HallForward.localPosition = (HallForwardPressLocalPosition - HallForwardReleaseLocalPosition) / (HallForwardPressValue - HallForwardReleaseValue) * inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallFoward + HallForwardPressLocalPosition;
  88. if (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallFoward < (HallForwardReleaseValue - HallForwardPressValue) / 2) {
  89. hallFoward.material = pressMaterial;
  90. } else {
  91. hallFoward.material = releaseMaterial;
  92. }
  93. }
  94. if(HallInside) {
  95. HallInside.localPosition = (HallInsidePressLocalPosition - HallInsideReleaseLocalPosition) / (HallInsidePressValue - HallInsideReleaseValue) * inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallInside + HallInsidePressLocalPosition;
  96. if (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallInside < (HallInsideReleaseValue - HallInsidePressValue) / 2) {
  97. hallInside.material = pressMaterial;
  98. } else {
  99. hallInside.material = releaseMaterial;
  100. }
  101. }
  102. }
  103. //[Range(0, 16)]
  104. //public int xx = 8;
  105. //[Range(0, 16)]
  106. //public int yy = 8;
  107. Vector3 biasJoystick = new Vector3(0,0,0);
  108. public virtual void UpdateJoystickTransform()
  109. {
  110. if (joystick)
  111. {
  112. if (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX != joystickTempValue.x || inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY != joystickTempValue.y)
  113. {
  114. biasJoystick.z = Mathf.Clamp(rotationZfactor * (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX - joystickInitalValue.x), -30, 30);
  115. biasJoystick.x = Mathf.Clamp(rotationXfactor * (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY - joystickInitalValue.y), -30, 30);
  116. joystick.localEulerAngles = joystickInitallocalEulerAngles + biasJoystick;
  117. joystickTempValue.x = inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX;
  118. joystickTempValue.y = inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY;
  119. }
  120. }
  121. }
  122. public override void SetHandleKeysColor() {
  123. if (releaseMaterial == null || pressMaterial == null) {
  124. return;
  125. }
  126. foreach (var item in inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.inputKeys.inputKeyPressDic) {
  127. if (item.Key == InputKeyCode.Trigger) {
  128. //triggerKey.material = releaseMaterial;
  129. //if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  130. // triggerKey.material = pressMaterial;
  131. //}
  132. } else if (functionKey && (item.Key == InputKeyCode.RFunction || item.Key == InputKeyCode.LFunction)) {
  133. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  134. functionKey.material = pressMaterial;
  135. } else if (item.Value == InputKeyState.UP) {
  136. functionKey.material = releaseMaterial;
  137. }
  138. } else if (axkey && (item.Key == InputKeyCode.X || item.Key == InputKeyCode.A)) {
  139. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  140. axkey.material = pressMaterial;
  141. } else if (item.Value == InputKeyState.UP) {
  142. axkey.material = releaseMaterial;
  143. }
  144. } else if(bykey && (item.Key == InputKeyCode.Y || item.Key == InputKeyCode.B)) {
  145. if(item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  146. bykey.material = pressMaterial;
  147. } else if (item.Value == InputKeyState.UP) {
  148. bykey.material = releaseMaterial;
  149. }
  150. } else if(joystickKey &&( item.Key == InputKeyCode.LjoystickKey || item.Key == InputKeyCode.RjoystickKey)) {
  151. if(item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  152. joystickKey.material = pressMaterial;
  153. } else if (item.Value == InputKeyState.UP) {
  154. joystickKey.material = releaseMaterial;
  155. }
  156. }
  157. }
  158. }
  159. public virtual void UpdatePowerUI() {
  160. }
  161. }
  162. }