I_Jemin

Support both VRTrigger and VRTriggerDown

......@@ -12,12 +12,12 @@ public class GunController : MonoBehaviour {
void Update()
{
if(VRInput.GetTriggerButton(VRInput.Hand.Right))
if(VRInput.GetVRButtonDown(VRInput.Button.RightIndex))
{
gun.Fire();
}
if(VRInput.GetGripButton(VRInput.Hand.Right))
if(VRInput.GetVRButtonDown(VRInput.Button.RightGrip))
{
gun.Reload();
}
......
......@@ -21,11 +21,9 @@ public class VREyeRaycaster : MonoBehaviour
{
EyeRaycast();
if(VRInput.GetTriggerButton(VRInput.Hand.Right))
if(VRInput.GetVRButtonDown(VRInput.Button.LeftIndex))
{
// Xbox 나 VR 컨트롤러의 'A' 키를 누르면 인터렉터블 오브젝트의 OnClick 이벤트를 발동시킴
// TODO: VR 컨트롤러의 트리거 버튼 클릭으로 대체
if(m_CurrentInteractible && Input.GetButtonDown("Fire1"))
if(m_CurrentInteractible)
{
m_CurrentInteractible.OnClick();
}
......
......@@ -3,11 +3,35 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
// VR 컨트롤러의 입력을 GetVRTriggerButton 과 GetVRGripButton 로 제공하는 클래스
public static class VRInput {
// VR 컨트롤러의 입력 감지를 GetButton 함수로 제공하는 클래스
public class VRInput: MonoBehaviour {
public enum Hand {Left,Right};
private static VRInput m_instance;
public static VRInput instance
{
get
{
if (!m_instance)
{
m_instance = new GameObject("VRInput").AddComponent<VRInput>();
}
return m_instance;
}
}
private void Start()
{
if (m_instance != null && m_instance != this)
{
Debug.LogError("There are more than one VRInput instance");
DestroyImmediate(this);
}
}
public enum Button {LeftIndex,RightIndex,LeftGrip,RightGrip};
/*
유니티는 OpenVR API 를 내장하고 있다.
......@@ -41,60 +65,185 @@ public static class VRInput {
//왼손
// 검지 손가락 트리거에 대응되는 입력 세팅 이름
static string leftIndexTriggerName = "LeftIndexTrigger";
public static string leftIndexTriggerName = "LeftIndexTrigger";
// 쥐는 트리거에 대응되는 입력 세팅 이름
static string leftGripTriggerName = "LeftGripTrigger";
public static string leftGripTriggerName = "LeftGripTrigger";
// 오른손
// 검지 손가락 트리거에 대응되는 입력 세팅 이름
static string rightIndexTriggerName = "RightIndexTrigger";
public string rightIndexTriggerName = "RightIndexTrigger";
// 쥐는 트리거에 대응되는 입력 세팅 이름
static string rightGripTriggerName = "RightGripTrigger";
public string rightGripTriggerName = "RightGripTrigger";
private bool m_isLeftIndexTriggerDown;
private bool m_isLeftIndexTriggerStay;
private bool m_isRightIndexTriggerDown;
private bool m_isRightIndexTriggerStay;
private bool m_isLeftGripTriggerDown;
private bool m_isLeftGripTriggerStay;
private bool m_isRightGripTriggerDown;
private bool m_isRightGripTriggerStay;
// 편의를 위해 정적 함수로 입력을 제공
public static bool GetTriggerButton(Hand hand)
void Awake()
{
if(hand == Hand.Right)
m_isRightIndexTriggerDown = false;
m_isRightIndexTriggerStay = false;
m_isRightGripTriggerDown = false;
m_isRightGripTriggerStay = false;
m_isLeftIndexTriggerDown = false;
m_isLeftIndexTriggerStay = false;
m_isLeftGripTriggerDown = false;
m_isLeftGripTriggerStay = false;
}
public static bool GetVRButtonDown(Button button)
{
switch (button)
{
case Button.LeftIndex:
return instance.m_isLeftIndexTriggerDown;
case Button.LeftGrip:
return instance.m_isLeftGripTriggerDown;
case Button.RightIndex:
return instance.m_isRightIndexTriggerDown;
case Button.RightGrip:
return instance.m_isRightGripTriggerDown;
}
return false;
}
public static bool GetVRButton(Button button)
{
switch (button)
{
case Button.LeftIndex:
return instance.m_isLeftIndexTriggerStay;
case Button.LeftGrip:
return instance.m_isLeftGripTriggerStay;
case Button.RightIndex:
return instance.m_isRightIndexTriggerStay;
case Button.RightGrip:
return instance.m_isRightGripTriggerStay;
}
return false;
}
void Update()
{
UpdateIndexState();
UpdateGripState();
}
void UpdateIndexState()
{
if(Input.GetAxisRaw(rightIndexTriggerName) >= 0.1f)
{
return true;
if(m_isRightIndexTriggerDown || m_isRightIndexTriggerStay)
{
m_isRightIndexTriggerDown = false;
}
else
{
m_isRightIndexTriggerDown = true;
}
m_isRightIndexTriggerStay = true;
}
else if(hand == Hand.Left)
else
{
m_isRightIndexTriggerDown = false;
m_isRightIndexTriggerStay = false;
}
if(Input.GetAxisRaw(leftIndexTriggerName) >= 0.1f)
{
return true;
if(m_isLeftIndexTriggerDown || m_isLeftIndexTriggerStay)
{
m_isLeftIndexTriggerDown = false;
}
else
{
m_isLeftIndexTriggerDown = true;
}
return false;
m_isLeftIndexTriggerStay = true;
}
else
{
m_isLeftIndexTriggerDown = false;
m_isLeftIndexTriggerStay = false;
}
}
void UpdateGripState()
{
public static bool GetGripButton(Hand hand)
if(Input.GetAxisRaw(rightGripTriggerName) >= 0.1f)
{
if(hand == Hand.Right)
if(m_isRightGripTriggerDown || m_isRightGripTriggerStay)
{
if(Input.GetAxisRaw(rightGripTriggerName) >= 0.1f)
m_isRightGripTriggerDown = false;
}
else
{
return true;
m_isRightGripTriggerDown = true;
}
m_isRightGripTriggerStay = true;
}
else if(hand == Hand.Left)
else
{
m_isRightGripTriggerDown = false;
m_isRightGripTriggerStay = false;
}
if(Input.GetAxisRaw(leftGripTriggerName) >= 0.1f)
{
return true;
if(m_isLeftGripTriggerDown || m_isLeftGripTriggerStay)
{
m_isLeftGripTriggerDown = false;
}
else
{
m_isLeftGripTriggerDown = true;
}
return false;
m_isLeftGripTriggerStay = true;
}
else
{
m_isLeftGripTriggerDown = false;
m_isLeftGripTriggerStay = false;
}
}
//TODO GetTriggerDown 과 GetTriggerUp 만들기
}
......