Toggle navigation
Toggle navigation
This project
Loading...
Sign in
I_Jemin
/
Unity-OpenVR-Shooter-Template
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
I_Jemin
2017-12-03 17:31:14 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5f7e1517b62b5932d040d41da9e73ebb598ebb14
5f7e1517
1 parent
7c1a3d0b
Support both VRTrigger and VRTriggerDown
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
182 additions
and
35 deletions
Assets/OpenVR-Shooter/Scripts/GunScript/GunController.cs
Assets/OpenVR-Shooter/Scripts/VRInteract/VREyeRaycaster.cs
Assets/OpenVR-Shooter/Scripts/VRInteract/VRInput.cs
Assets/OpenVR-Shooter/Scripts/GunScript/GunController.cs
View file @
5f7e151
...
...
@@ -12,12 +12,12 @@ public class GunController : MonoBehaviour {
void
Update
()
{
if
(
VRInput
.
Get
TriggerButton
(
VRInput
.
Hand
.
Right
))
if
(
VRInput
.
Get
VRButtonDown
(
VRInput
.
Button
.
RightIndex
))
{
gun
.
Fire
();
}
if
(
VRInput
.
Get
GripButton
(
VRInput
.
Hand
.
Right
))
if
(
VRInput
.
Get
VRButtonDown
(
VRInput
.
Button
.
RightGrip
))
{
gun
.
Reload
();
}
...
...
Assets/OpenVR-Shooter/Scripts/VRInteract/VREyeRaycaster.cs
View file @
5f7e151
...
...
@@ -21,11 +21,9 @@ public class VREyeRaycaster : MonoBehaviour
{
EyeRaycast
();
if
(
VRInput
.
Get
TriggerButton
(
VRInput
.
Hand
.
Right
))
if
(
VRInput
.
Get
VRButtonDown
(
VRInput
.
Button
.
LeftIndex
))
{
// Xbox 나 VR 컨트롤러의 'A' 키를 누르면 인터렉터블 오브젝트의 OnClick 이벤트를 발동시킴
// TODO: VR 컨트롤러의 트리거 버튼 클릭으로 대체
if
(
m_CurrentInteractible
&&
Input
.
GetButtonDown
(
"Fire1"
))
if
(
m_CurrentInteractible
)
{
m_CurrentInteractible
.
OnClick
();
}
...
...
Assets/OpenVR-Shooter/Scripts/VRInteract/VRInput.cs
View file @
5f7e151
...
...
@@ -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
{
p
ublic
enum
Hand
{
Left
,
Right
}
;
p
rivate
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"
;
// 오른손
// 검지 손가락 트리거에 대응되는 입력 세팅 이름
stat
ic
string
rightIndexTriggerName
=
"RightIndexTrigger"
;
publ
ic
string
rightIndexTriggerName
=
"RightIndexTrigger"
;
// 쥐는 트리거에 대응되는 입력 세팅 이름
stat
ic
string
rightGripTriggerName
=
"RightGripTrigger"
;
publ
ic
string
rightGripTriggerName
=
"RightGripTrigger"
;
// 편의를 위해 정적 함수로 입력을 제공
public
static
bool
GetTriggerButton
(
Hand
hand
)
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
;
void
Awake
()
{
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
(
hand
==
Hand
.
Right
)
if
(
Input
.
GetAxisRaw
(
rightIndexTriggerName
)
>=
0.1f
)
{
if
(
Input
.
GetAxisRaw
(
rightIndexTriggerName
)
>=
0.1f
)
if
(
m_isRightIndexTriggerDown
||
m_isRightIndexTriggerStay
)
{
m_isRightIndexTriggerDown
=
false
;
}
else
{
return
true
;
m_isRightIndexTriggerDown
=
true
;
}
m_isRightIndexTriggerStay
=
true
;
}
else
{
m_isRightIndexTriggerDown
=
false
;
m_isRightIndexTriggerStay
=
false
;
}
else
if
(
hand
==
Hand
.
Left
)
if
(
Input
.
GetAxisRaw
(
leftIndexTriggerName
)
>=
0.1f
)
{
if
(
Input
.
GetAxisRaw
(
leftIndexTriggerName
)
>=
0.1f
)
if
(
m_isLeftIndexTriggerDown
||
m_isLeftIndexTriggerStay
)
{
m_isLeftIndexTriggerDown
=
false
;
}
else
{
return
true
;
m_isLeftIndexTriggerDown
=
true
;
}
m_isLeftIndexTriggerStay
=
true
;
}
else
{
m_isLeftIndexTriggerDown
=
false
;
m_isLeftIndexTriggerStay
=
false
;
}
return
false
;
}
public
static
bool
GetGripButton
(
Hand
hand
)
void
UpdateGripState
()
{
if
(
hand
==
Hand
.
Right
)
if
(
Input
.
GetAxisRaw
(
rightGripTriggerName
)
>=
0.1f
)
{
if
(
Input
.
GetAxisRaw
(
rightGripTriggerName
)
>=
0.1f
)
if
(
m_isRightGripTriggerDown
||
m_isRightGripTriggerStay
)
{
m_isRightGripTriggerDown
=
false
;
}
else
{
return
true
;
m_isRightGripTriggerDown
=
true
;
}
m_isRightGripTriggerStay
=
true
;
}
else
if
(
hand
==
Hand
.
Left
)
else
{
if
(
Input
.
GetAxisRaw
(
leftGripTriggerName
)
>=
0.1f
)
m_isRightGripTriggerDown
=
false
;
m_isRightGripTriggerStay
=
false
;
}
if
(
Input
.
GetAxisRaw
(
leftGripTriggerName
)
>=
0.1f
)
{
if
(
m_isLeftGripTriggerDown
||
m_isLeftGripTriggerStay
)
{
m_isLeftGripTriggerDown
=
false
;
}
else
{
return
true
;
m_isLeftGripTriggerDown
=
true
;
}
m_isLeftGripTriggerStay
=
true
;
}
else
{
m_isLeftGripTriggerDown
=
false
;
m_isLeftGripTriggerStay
=
false
;
}
return
false
;
}
//TODO GetTriggerDown 과 GetTriggerUp 만들기
}
...
...
Please
register
or
login
to post a comment