InputHandling.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using ObjectScripts;
  2. using Status;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using Valve.VR;
  8. using Valve.VR.Extras;
  9. using Valve.VR.InteractionSystem;
  10. public class InputHandling : MonoBehaviour
  11. {
  12. public SteamVR_Action_Boolean TimeSpeedUp = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("CMController", "TimeSpeedUp");
  13. public SteamVR_Action_Boolean TimeSpeedDown = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("CMController", "TimeSpeedDown");
  14. public SteamVR_Action_Boolean LODUp = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("CMController", "LODUp");
  15. public SteamVR_Action_Boolean LODDown = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("CMController", "LODDown");
  16. public SteamVR_Action_Boolean PlayPause = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("CMController", "PlayPause");
  17. public SteamVR_Action_Boolean TimeReverse = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("CMController", "ReverseTime");
  18. [SerializeField]
  19. [Tooltip("Object holding the Manager Script")]
  20. GameObject ManagerObject;
  21. [SerializeField]
  22. [Tooltip("Object holding the Details Script")]
  23. GameObject DetailsObject;
  24. [SerializeField]
  25. [Tooltip("Assign Handheld Canvases like 0 = Play, 1 = Stop, 2 = VelocityText")]
  26. GameObject[] Buttons;
  27. private Interactable Interactable;
  28. private ManagerWithProzessor Manager;
  29. private DetailsLevel Details;
  30. private float lastState;
  31. // Start is called before the first frame update
  32. void Start()
  33. {
  34. Manager = ManagerObject.GetComponent<ManagerWithProzessor>();
  35. Interactable = GetComponent<Interactable>();
  36. Details = DetailsObject.GetComponent<DetailsLevel>();
  37. lastState = 0;
  38. }
  39. // Update is called once per frame
  40. void Update()
  41. {
  42. if (Interactable.attachedToHand)
  43. {
  44. // Lokales Are good!
  45. SteamVR_Input_Sources hand = Interactable.attachedToHand.handType;
  46. bool TSU = TimeSpeedUp.GetStateDown(hand);
  47. bool TSD = TimeSpeedDown.GetStateDown(hand);
  48. bool LU = LODUp.GetStateDown(hand);
  49. bool LD = LODDown.GetStateDown(hand);
  50. bool PP = PlayPause.GetStateDown(hand);
  51. bool TR = TimeReverse.GetStateDown(hand);
  52. //Change TimeWarp
  53. if (TSU)
  54. Manager.PlusPressed();
  55. if (TSD)
  56. Manager.MinusPressed();
  57. // Play/Pause Simulation
  58. if (PP)
  59. CyclePP();
  60. //Cycle LODs
  61. if (LU)
  62. Details.CycleStates(1);
  63. if (LD)
  64. Details.CycleStates(-1);
  65. //TimeReverse
  66. if (TR)
  67. Manager.ReverseTime();
  68. }
  69. // Update one Handheld UI
  70. float v = (Manager.forward ? 1 : -1) * Manager.GameVelocity;
  71. if (lastState - v != 0)
  72. {
  73. Buttons[2].GetComponent<UnityEngine.UI.Text>().text = "" + v;
  74. if (Manager.GameVelocity == 0)
  75. {
  76. Buttons[1].SetActive(true);
  77. Buttons[0].SetActive(false);
  78. }
  79. else
  80. {
  81. Buttons[1].SetActive(false);
  82. Buttons[0].SetActive(true);
  83. }
  84. lastState = v;
  85. }
  86. }
  87. private void CyclePP()
  88. {
  89. if (Manager.GameVelocity == 0)
  90. Manager.PlayPressed();
  91. else
  92. Manager.StopPressed();
  93. }
  94. public ISteamVR_Action_In_Source[] AvalibleButtons()
  95. {
  96. return new ISteamVR_Action_In_Source[] { TimeSpeedUp, TimeSpeedDown, LODUp, LODDown, PlayPause };
  97. }
  98. }