using ObjectScripts; using Status; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Valve.VR; using Valve.VR.Extras; using Valve.VR.InteractionSystem; public class InputHandling : MonoBehaviour { public SteamVR_Action_Boolean TimeSpeedUp = SteamVR_Input.GetAction("CMController", "TimeSpeedUp"); public SteamVR_Action_Boolean TimeSpeedDown = SteamVR_Input.GetAction("CMController", "TimeSpeedDown"); public SteamVR_Action_Boolean LODUp = SteamVR_Input.GetAction("CMController", "LODUp"); public SteamVR_Action_Boolean LODDown = SteamVR_Input.GetAction("CMController", "LODDown"); public SteamVR_Action_Boolean PlayPause = SteamVR_Input.GetAction("CMController", "PlayPause"); public SteamVR_Action_Boolean TimeReverse = SteamVR_Input.GetAction("CMController", "ReverseTime"); [SerializeField] [Tooltip("Object holding the Manager Script")] GameObject ManagerObject; [SerializeField] [Tooltip("Object holding the Details Script")] GameObject DetailsObject; [SerializeField] [Tooltip("Assign Handheld Canvases like 0 = Play, 1 = Stop, 2 = VelocityText")] GameObject[] Buttons; private Interactable Interactable; private ManagerWithProzessor Manager; private DetailsLevel Details; private float lastState; // Start is called before the first frame update void Start() { Manager = ManagerObject.GetComponent(); Interactable = GetComponent(); Details = DetailsObject.GetComponent(); lastState = 0; } // Update is called once per frame void Update() { if (Interactable.attachedToHand) { // Lokales Are good! SteamVR_Input_Sources hand = Interactable.attachedToHand.handType; bool TSU = TimeSpeedUp.GetStateDown(hand); bool TSD = TimeSpeedDown.GetStateDown(hand); bool LU = LODUp.GetStateDown(hand); bool LD = LODDown.GetStateDown(hand); bool PP = PlayPause.GetStateDown(hand); bool TR = TimeReverse.GetStateDown(hand); //Change TimeWarp if (TSU) Manager.PlusPressed(); if (TSD) Manager.MinusPressed(); // Play/Pause Simulation if (PP) CyclePP(); //Cycle LODs if (LU) Details.CycleStates(1); if (LD) Details.CycleStates(-1); //TimeReverse if (TR) Manager.ReverseTime(); } // Update one Handheld UI float v = (Manager.forward ? 1 : -1) * Manager.GameVelocity; if (lastState - v != 0) { Buttons[2].GetComponent().text = "" + v; if (Manager.GameVelocity == 0) { Buttons[1].SetActive(true); Buttons[0].SetActive(false); } else { Buttons[1].SetActive(false); Buttons[0].SetActive(true); } lastState = v; } } private void CyclePP() { if (Manager.GameVelocity == 0) Manager.PlayPressed(); else Manager.StopPressed(); } public ISteamVR_Action_In_Source[] AvalibleButtons() { return new ISteamVR_Action_In_Source[] { TimeSpeedUp, TimeSpeedDown, LODUp, LODDown, PlayPause }; } }