ValveSoftware / steamvr_unity_plugin

SteamVR Unity Plugin - Documentation at: https://valvesoftware.github.io/steamvr_unity_plugin/
BSD 3-Clause "New" or "Revised" License
1.03k stars 256 forks source link

Can SteamVR_Input_Sources.Any refresh other sources in same action? #1082

Open REshyx opened 1 year ago

REshyx commented 1 year ago

I don't know if it is a bug, I called an action whose source is SteamVR_Input_Sources.Any, it returns true when I press down the key. When I call the same action in next frame with source: SteamVR_Input_Sources.RightHand. it also returns true. My aim is to using the key to realize a two-level menu. but when pressing the key once,it directly enters the secondary menu. I am sure the two two calls of action with SteamVR_Input_Sources.Any and SteamVR_Input_Sources.RightHand are both true. "Any" does not refresh "RightHand". But when I write a script like this:

using UnityEngine;
using Valve.VR;

public class  Script1 : MonoBehaviour
{
    public static SteamVR_Action_Boolean Function = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("Function");
    // Update is called once per frame
    void Update()
    {
        if (Function.GetStateDown(SteamVR_Input_Sources.Any))
        {
            Debug.LogError("Any stateDown. frame:" + Time.frameCount);
        }
        else {
            Debug.Log("Not any stateDown. frame:" + Time.frameCount);
            if (Function.GetStateDown(SteamVR_Input_Sources.RightHand))
            {
                Debug.LogError("Left stateDown. frame:" + Time.frameCount);
            } 
        }
    }
}

The “Any” seems refresh the "RightHand", the log "Right stateDown. frame: XXX" is never logged;

REshyx commented 1 year ago

In this case, two calls in different frame is both true:

using UnityEngine;
using Valve.VR;

public class  Script1 : MonoBehaviour
{
    bool alter=false;
    public static SteamVR_Action_Boolean Function = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("Function");
    // Update is called once per frame
    void Update()
    {
        if (!alter)
        {
            if (Function.GetStateDown(SteamVR_Input_Sources.Any))
            {
                Debug.LogError("Any stateDown. frame:" + Time.frameCount);
                alter = true;
            }

        }
        else {
            if (Function.GetStateDown(SteamVR_Input_Sources.RightHand))
            {
                Debug.LogError("Right stateDown. frame:" + Time.frameCount);
            }
            else {
                Debug.Log("None");
            }
        }
    }
}

image

but in this, it is true and false:

using UnityEngine;
using Valve.VR;

public class  Script1 : MonoBehaviour
{
    bool alter=false;
    public static SteamVR_Action_Boolean Function = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("Function");
    // Update is called once per frame
    void Update()
    {
        if (Function.GetStateDown(SteamVR_Input_Sources.Any))
        {
            Debug.LogError("Any stateDown. frame:" + Time.frameCount);
        }
        else
        {           
            if (Function.GetStateDown(SteamVR_Input_Sources.RightHand))
            {
                Debug.LogError("Right stateDown. frame:" + Time.frameCount);
            }
            else { 
                Debug.LogError("Right not stateDown. frame:" + Time.frameCount);
            }
        }
    }
}

image