SteamVR:获取由动作触发的输入设备然后获取其对应的 Hand class 的正确方法?

SteamVR: Correct way to get the input device triggered by an action and then get it's corresponding Hand class?

我有一个动作映射到我的 VR 控制器上的左右手触发器。我想访问这些实例...

Player.instance.rightHand 
Player.instance.leftHand

...取决于使用的触发器,但我无法从 SteamVR API 中找到正确的方法。到目前为止,我得到的最接近的是这个...

public SteamVR_Action_Boolean CubeNavigation_Position;

private void Update()
{
    if (CubeNavigation_Position[SteamVR_Input_Sources.Any].state) {

        // this returns an enum which can be converted to string for LeftHand or RightHand
        SteamVR_Input_Sources inputSource = CubeNavigation_Position[SteamVR_Input_Sources.Any].activeDevice; 
    } 
}

...我应该为 SteamVR_Input_Sources.LeftHand 和 SteamVR_Input_Sources.RightHand 做多个 if 语句吗?这似乎不正确。

我只想获取触发操作的输入设备,然后使用 Player.instance 访问它。

我也在寻找这个问题的答案。我现在已经完成了我认为是 if 语句的意思。它有效,但绝对不理想。您想直接引用触发动作的手,对吗?

通过这里的 'inputHand' 变量,我得到手的 transform.position,我将从中进行光线投射并显示一条可见线。当然,我本可以像这样在每只手上放置一个单独的 raycastScript 实例,但我想制作一个 'global' 脚本,如果这有意义的话。

private SteamVR_Input_Sources inputSource = SteamVR_Input_Sources.Any; //which controller
public SteamVR_Action_Boolean raycastTrigger; // action-button
private Hand inputHand;

private void Update()
{
    if (raycastTrigger.stateDown && !isRaycasting) // If holding down trigger
    {
        isRaycasting = true;
        inputHand = inputChecker();
    }
    if (raycastTrigger.stateUp && isRaycasting)
    {
        isRaycasting = false;
    }
}

private Hand inputChecker()
{
    if (raycastTrigger.activeDevice == SteamVR_Input_Sources.RightHand)
    {
        inputHand = Player.instance.rightHand;
    }
    else if (raycastTrigger.activeDevice == SteamVR_Input_Sources.LeftHand)
    {
        inputHand = Player.instance.leftHand;
    }
    return inputHand;
}