目次
開発環境
- Quest1
- Oculus Link + SteamVR
- Unity 2021.2.0b16.3733
- Unity 2020.3.17f1
- SteamVR Plugin 2.7.3
実装
Inspectorから設定する
public class QuestButtonHandler : MonoBehaviour
{
public SteamVR_Input_Sources hand;
public SteamVR_Action_Boolean aAction;
void Update()
{
if (aAction.GetStateDown(hand))
{
Debug.Log("状態(Click)がオンになった");
}
if (aAction.GetState(hand))
{
Debug.Log("現在状態(Click)がオン中");
}
if (aAction.GetStateUp(hand))
{
Debug.Log("状態(Click)がオフになった");
}
}
}
public class QuestButtonHandler : MonoBehaviour
{
void Update()
{
if (SteamVR_Actions.default_A.GetStateDown(SteamVR_Input_Sources.RightHand))
{
Debug.Log("A touch down.");
}
if (SteamVR_Actions.default_A.GetState(SteamVR_Input_Sources.RightHand))
{
Debug.Log("A touching.");
}
if (SteamVR_Actions.default_A.GetStateUp(SteamVR_Input_Sources.RightHand))
{
Debug.Log("A touch up.");
}
}
}
SteamVR_Behaviour系のコンポーネントを使う
public class QuestButtonHandler : MonoBehaviour
{
public void OnPressDown()
{
Debug.Log("press down.");
}
public void OnPress()
{
Debug.Log("press.");
}
public void OnPressUp()
{
Debug.Log("press up.");
}
}