如何配置一个自定义的按钮
点击+号创建 然后点击Save and generate保存 在点击 Open binding UI 打开编辑面板绑定按键
最后点击替换默认按键设置保存自己的修改
方法一
private void Update()
{
if (SteamVR_Input.GetAction<SteamVR_Action_Boolean>("Fire").GetState(SteamVR_Input_Sources.Any))
{
Debug.Log("Firing");
}
if (SteamVR_Input.GetAction<SteamVR_Action_Boolean>("Fire").GetStateUp(SteamVR_Input_Sources.Any))
{
Debug.Log("Fire Up");
}
if (SteamVR_Input.GetAction<SteamVR_Action_Boolean>("Fire").GetStateDown(SteamVR_Input_Sources.Any))
{
Debug.Log("Firing Down");
}
}
方法二
void Start()
{
SteamVR_Actions.default_Fire.onStateUp += FireUp;
SteamVR_Actions.default_Fire.onState += Firing;
SteamVR_Actions.default_Fire.onStateDown += FireDown;
}
void End()
{
SteamVR_Actions.default_Fire.onStateUp -= FireUp;
SteamVR_Actions.default_Fire.onState -= Firing;
SteamVR_Actions.default_Fire.onStateDown -= FireDown;
}
private void FireDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
{
Debug.Log("Fire Down");
}
private void Firing(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
{
Debug.Log("Firing");
}
private void FireUp(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
{
Debug.Log("Fire up");
}
方法三
void Start()
{
SteamVR_Actions.default_Fire.AddOnStateUpListener(FireUp,SteamVR_Input_Sources.Any);
SteamVR_Actions.default_Fire.AddOnStateDownListener(FireDown,SteamVR_Input_Sources.Any);
}
void End()
{
SteamVR_Actions.default_Fire.RemoveAllListeners(SteamVR_Input_Sources.Any);
}
private void FireDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
{
Debug.Log("Fire Down");
SteamVR_Actions.default_Fire.AddOnUpdateListener(Firing, SteamVR_Input_Sources.Any);
}
private void Firing(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource, bool newState)
{
Debug.Log("Firing");
}
private void FireUp(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
{
Debug.Log("Fire up");
SteamVR_Actions.default_Fire.RemoveOnUpdateListener(Firing, SteamVR_Input_Sources.Any);
}
|