ModelK11.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. [Range(0,4)]
  23. public float rotationfactor = 2;
  24. public Vector2 joystickInitalValue = new Vector2(8, 8);
  25. public Vector3 joystickInitallocalEulerAngles;
  26. [Header("MaterialVisual")]
  27. public Material pressMaterial;
  28. public Material releaseMaterial;
  29. void UpdateTransform() {
  30. transform.localPosition = modelPositionDeltaWithDevice;
  31. }
  32. public override void OnSCStart() {
  33. base.OnSCStart();
  34. }
  35. public override void OnSCLateUpdate() {
  36. base.OnSCLateUpdate();
  37. UpdateTransform();
  38. UpdateJoystickTransform();
  39. }
  40. //[Range(0, 16)]
  41. //public int xx = 8;
  42. //[Range(0, 16)]
  43. //public int yy = 8;
  44. Vector3 biasJoystick = new Vector3(0,0,0);
  45. public virtual void UpdateJoystickTransform() {
  46. if (joystick) {
  47. if(inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX != joystickInitalValue.x || inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY != joystickInitalValue.y) {
  48. biasJoystick.z = rotationfactor * (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickX - joystickInitalValue.x);
  49. biasJoystick.x = rotationfactor * (inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.JoystickY - joystickInitalValue.y);
  50. joystick.localEulerAngles = joystickInitallocalEulerAngles + biasJoystick;
  51. }
  52. }
  53. }
  54. public override void SetHandleKeysColor() {
  55. if (releaseMaterial == null || pressMaterial == null) {
  56. return;
  57. }
  58. foreach (var item in inputDeviceKSPartUI.inputDeviceKSPart.inputDataKS.inputKeys.inputKeyDic) {
  59. if(TriggerKey && (item.Key == InputKeyCode.LTrigger || item.Key == InputKeyCode.RTrigger)) {
  60. TriggerKey.material = releaseMaterial;
  61. if(item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  62. TriggerKey.material = pressMaterial;
  63. }
  64. } else if (Upkey && (item.Key == InputKeyCode.RFunction || item.Key == InputKeyCode.LFunction)) {
  65. Upkey.material = releaseMaterial;
  66. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  67. Upkey.material = pressMaterial;
  68. }
  69. } else if(RightKey && (item.Key == InputKeyCode.RFunction || item.Key == InputKeyCode.LFunction)) {
  70. RightKey.material = releaseMaterial;
  71. if(item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  72. RightKey.material = pressMaterial;
  73. }
  74. } else if (Downkey && (item.Key == InputKeyCode.X || item.Key == InputKeyCode.A)) {
  75. Downkey.material = releaseMaterial;
  76. if (item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  77. Downkey.material = pressMaterial;
  78. }
  79. } else if(LeftKey && (item.Key == InputKeyCode.Y || item.Key == InputKeyCode.B)) {
  80. LeftKey.material = releaseMaterial;
  81. if(item.Value == InputKeyState.DOWN || item.Value == InputKeyState.LONG) {
  82. LeftKey.material = pressMaterial;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }