ModelK101.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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("3DofBias")]
  13. public Vector3 modelPositionDeltaWithDevice = new Vector3(0, 0, 0f);
  14. [Header("Keys")]
  15. public MeshRenderer axkey;
  16. public MeshRenderer bykey;
  17. public MeshRenderer functionKey;
  18. [Header("Joystick")]
  19. public Transform joystick;
  20. public MeshRenderer joystickKey;
  21. [Range(0,4)]
  22. public float rotationfactor = 2;
  23. public Vector2 joystickInitalValue = new Vector2(8, 8);
  24. public Vector3 joystickInitallocalEulerAngles;
  25. [Header("HallForward")]
  26. public MeshRenderer hallFoward;
  27. public Transform HallForward;
  28. public int HallForwardReleaseValue = 10;
  29. public int HallForwardPressValue = 0;
  30. public Vector3 HallForwardReleaseLocalPosition;
  31. public Vector3 HallForwardPressLocalPosition;
  32. [Header("HallInside")]
  33. public MeshRenderer hallInside;
  34. public Transform HallInside;
  35. public int HallInsideReleaseValue = 10;
  36. public int HallInsidePressValue = 0;
  37. public Vector3 HallInsideReleaseLocalPosition;
  38. public Vector3 HallInsidePressLocalPosition;
  39. [Header("MaterialVisual")]
  40. public Material pressMaterial;
  41. public Material releaseMaterial;
  42. void UpdateTransform() {
  43. transform.localPosition = modelPositionDeltaWithDevice;
  44. }
  45. public override void OnSCStart() {
  46. base.OnSCStart();
  47. }
  48. public override void OnSCLateUpdate() {
  49. base.OnSCLateUpdate();
  50. UpdateTransform();
  51. UpdateJoystickTransform();
  52. UpdateHallVisual();
  53. }
  54. public virtual void UpdateHallVisual() {
  55. if(HallForward) {
  56. HallForward.localPosition = (HallForwardPressLocalPosition - HallForwardReleaseLocalPosition) / (HallForwardPressValue - HallForwardReleaseValue) * inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallFoward + HallForwardPressLocalPosition;
  57. if(inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallFoward < (HallForwardReleaseValue - HallForwardPressValue) / 2) {
  58. hallFoward.material = pressMaterial;
  59. } else {
  60. hallFoward.material = releaseMaterial;
  61. }
  62. }
  63. if(HallInside) {
  64. HallInside.localPosition = (HallInsidePressLocalPosition - HallInsideReleaseLocalPosition) / (HallInsidePressValue - HallInsideReleaseValue) * inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallInside + HallInsidePressLocalPosition;
  65. if(inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.HallInside < (HallInsideReleaseValue - HallInsidePressValue) / 2) {
  66. hallInside.material = pressMaterial;
  67. } else {
  68. hallInside.material = releaseMaterial;
  69. }
  70. }
  71. }
  72. //[Range(0, 16)]
  73. //public int xx = 8;
  74. //[Range(0, 16)]
  75. //public int yy = 8;
  76. Vector3 biasJoystick = new Vector3(0,0,0);
  77. public virtual void UpdateJoystickTransform() {
  78. if (joystick) {
  79. if(inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX != joystickInitalValue.x || inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY != joystickInitalValue.y) {
  80. biasJoystick.z = rotationfactor * (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX - joystickInitalValue.x);
  81. biasJoystick.x = rotationfactor * (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY - joystickInitalValue.y);
  82. joystick.localEulerAngles = joystickInitallocalEulerAngles + biasJoystick;
  83. }
  84. }
  85. }
  86. public override void SetHandleKeysColor() {
  87. if (releaseMaterial == null || pressMaterial == null) {
  88. return;
  89. }
  90. foreach (var item in inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.inputKeys.inputKeyDic) {
  91. if (item.Key == InputKeyCode.Trigger) {
  92. //triggerKey.material = releaseMaterial;
  93. //if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  94. // triggerKey.material = pressMaterial;
  95. //}
  96. } else if (functionKey && (item.Key == InputKeyCode.RFunction || item.Key == InputKeyCode.LFunction)) {
  97. functionKey.material = releaseMaterial;
  98. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  99. functionKey.material = pressMaterial;
  100. }
  101. } else if (axkey && (item.Key == InputKeyCode.X || item.Key == InputKeyCode.A)) {
  102. axkey.material = releaseMaterial;
  103. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  104. axkey.material = pressMaterial;
  105. }
  106. } else if(bykey && (item.Key == InputKeyCode.Y || item.Key == InputKeyCode.B)) {
  107. bykey.material = releaseMaterial;
  108. if(item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  109. bykey.material = pressMaterial;
  110. }
  111. } else if(joystickKey &&( item.Key == InputKeyCode.LjoystickKey || item.Key == InputKeyCode.RjoystickKey)) {
  112. joystickKey.material = releaseMaterial;
  113. if(item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  114. joystickKey.material = pressMaterial;
  115. }
  116. }
  117. }
  118. }
  119. }
  120. }