ModelK11.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 ModelK11 : 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 Upkey;
  16. public MeshRenderer Downkey;
  17. public MeshRenderer LeftKey;
  18. public MeshRenderer RightKey;
  19. public MeshRenderer TriggerKey;
  20. [Header("Joystick")]
  21. public Transform joystick;
  22. private Vector3 joystickInitLocalPosition;
  23. [Range(0,4)]
  24. public float rotationfactor = 2;
  25. public Vector2 joystickInitalValue = new Vector2(8, 8);
  26. public Vector3 joystickInitallocalEulerAngles;
  27. [Header("MaterialVisual")]
  28. public Material pressMaterial;
  29. public Material releaseMaterial;
  30. void UpdateTransform() {
  31. transform.localPosition = modelPositionDeltaWithDevice;
  32. }
  33. public override void OnSCStart() {
  34. base.OnSCStart();
  35. if (joystick)
  36. joystickInitLocalPosition = joystick.localPosition;
  37. }
  38. public override void OnSCLateUpdate() {
  39. base.OnSCLateUpdate();
  40. UpdateTransform();
  41. UpdateJoystickTransform();
  42. }
  43. ////[Range(0, 16)]
  44. //public int xx = 8;
  45. ////[Range(0, 16)]
  46. //public int yy = 8;
  47. Vector3 biasJoystick = new Vector3(0,0,0);
  48. public virtual void UpdateJoystickTransform() {
  49. if (joystick) {
  50. if(inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX != joystickInitalValue.x || inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY != joystickInitalValue.y) {
  51. if (inputDeviceKSPartUI.inputDeviceKSPart.PartType == InputDevicePartType.KSLeft) {
  52. biasJoystick.z = joystickInitLocalPosition.z + (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY - joystickInitalValue.y) * 0.0002f;
  53. biasJoystick.x = joystickInitLocalPosition.x + (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX - joystickInitalValue.x) * 0.0002f;
  54. biasJoystick.y = joystickInitLocalPosition.y;
  55. } else if (inputDeviceKSPartUI.inputDeviceKSPart.PartType == InputDevicePartType.KSRight) {
  56. biasJoystick.z = joystickInitLocalPosition.z + (joystickInitalValue.y - inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY) * 0.0002f;
  57. biasJoystick.x = joystickInitLocalPosition.x + (joystickInitalValue.x - inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX) * 0.0002f;
  58. biasJoystick.y = joystickInitLocalPosition.y;
  59. }
  60. joystick.localPosition = biasJoystick;
  61. }
  62. }
  63. }
  64. public override void SetHandleKeysColor() {
  65. if (releaseMaterial == null || pressMaterial == null) {
  66. return;
  67. }
  68. foreach (var item in inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.inputKeys.inputKeyPressDic) {
  69. if(TriggerKey && (item.Key == InputKeyCode.LTrigger || item.Key == InputKeyCode.RTrigger)) {
  70. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  71. TriggerKey.material = pressMaterial;
  72. } else if (item.Value == InputKeyState.UP) {
  73. TriggerKey.material = releaseMaterial;
  74. }
  75. } else if (Upkey && (item.Key == InputKeyCode.UP || item.Key == InputKeyCode.Y)) {
  76. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  77. Upkey.material = pressMaterial;
  78. } else if (item.Value == InputKeyState.UP) {
  79. Upkey.material = releaseMaterial;
  80. }
  81. } else if(RightKey && (item.Key == InputKeyCode.RIGHT || item.Key == InputKeyCode.B)) {
  82. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  83. RightKey.material = pressMaterial;
  84. } else if (item.Value == InputKeyState.UP) {
  85. RightKey.material = releaseMaterial;
  86. }
  87. } else if (Downkey && (item.Key == InputKeyCode.DOWN || item.Key == InputKeyCode.A)) {
  88. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  89. Downkey.material = pressMaterial;
  90. } else if (item.Value == InputKeyState.UP) {
  91. Downkey.material = releaseMaterial;
  92. }
  93. } else if(LeftKey && (item.Key == InputKeyCode.LEFT || item.Key == InputKeyCode.X)) {
  94. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  95. LeftKey.material = pressMaterial;
  96. } else if (item.Value == InputKeyState.UP) {
  97. LeftKey.material = releaseMaterial;
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }