Hi, before steamvr 2.0 came out, I could do input events in custom scripts like this: Code (CSharp): public SteamVR_TrackedController cr1; void Start () { cr1.TriggerClicked += HandleTrigger; } void HandleTrigger(object sender,ClickedEventArgs e){ //DoStuff(); } After the update however, with the new binding system, I have no idea how to achieve the same thing. How can I add a method to an input that will be called automaticly like before? I can't find an example of that anywhere. Thanks for any help.
You don't check triggers or individual buttons anymore but instead check actions. I suggest you read this https://steamcommunity.com/sharedfiles/filedetails/?id=1416820276 There is example code of checking a boolean action like a button press in that article.
Thanks, that's not what Iam asking though. I know I can check that manually but that means the update loop will have 40 ifs, each asking for a different input and state. Having the events call methods automaticaly like in the previous verions saves a lot of code and makes it far more readable. How can I do that with the new system? Did they just straight up remove the feature?
Each action type has an OnChangeListener but it's slightly different for each action type I think. I would look in the editor input components they supply such as SteamVR_Behaviour_Single, SteamVR_Behaviour_Boolean etc that watch for changes in state and then call a method like you want to do. Here is the code for a SteamVR_Behaviour_Single. Code (CSharp): private void OnEnable() { singleAction.AddOnChangeListener(ActionChanged, inputSource); } private void OnDisable() { singleAction.RemoveOnChangeListener(ActionChanged, inputSource); } private void ActionChanged(SteamVR_Action_In action) { if (onChange != null) { onChange.Invoke((SteamVR_Action_Single)action); } }