Provide static Input Getter
Remove VRInputController VRInput provide VR input check No more support: Overriding method for input
Showing
11 changed files
with
60 additions
and
46 deletions
| ... | @@ -3,20 +3,23 @@ using System.Collections.Generic; | ... | @@ -3,20 +3,23 @@ using System.Collections.Generic; |
| 3 | using UnityEngine; | 3 | using UnityEngine; |
| 4 | 4 | ||
| 5 | // VR 컨트롤러의 인풋을 받아 Gun 을 제어하는 스크립트 | 5 | // VR 컨트롤러의 인풋을 받아 Gun 을 제어하는 스크립트 |
| 6 | -public class GunController : VRInputController { | 6 | +public class GunController : MonoBehaviour { |
| 7 | 7 | ||
| 8 | - /* VR 입력을 받아 처리해야 하는 클래스는 VRInputController 만 상속받아서 두 함수만 오버라이드 하면 된다! */ | 8 | + /* VR 입력을 받아 처리해야 하는 클래스는 VRInputController 싱긑톤의 두 함수만 체크 하면 된다 */ |
| 9 | - // 단 두개의 함수 OnGripTriggerButtonDown 와 OnIndexTriggerButtonDown | 9 | + // 단 두개의 함수 GetGripButton 와 GetTriggerButton |
| 10 | 10 | ||
| 11 | public Gun gun; | 11 | public Gun gun; |
| 12 | 12 | ||
| 13 | - protected override void OnIndexTriggerButtonDown() | 13 | + void Update() |
| 14 | + { | ||
| 15 | + if(VRInput.GetTriggerButton(VRInput.Hand.Right)) | ||
| 14 | { | 16 | { |
| 15 | gun.Fire(); | 17 | gun.Fire(); |
| 16 | } | 18 | } |
| 17 | 19 | ||
| 18 | - protected override void OnGripTriggerButtonDown() | 20 | + if(VRInput.GetGripButton(VRInput.Hand.Right)) |
| 19 | { | 21 | { |
| 20 | gun.Reload(); | 22 | gun.Reload(); |
| 21 | } | 23 | } |
| 24 | + } | ||
| 22 | } | 25 | } | ... | ... |
File moved
| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | using UnityEngine; | 2 | using UnityEngine; |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | -public class VREyeRaycaster : VRInputController | 5 | +public class VREyeRaycaster : MonoBehaviour |
| 6 | { | 6 | { |
| 7 | public event Action<RaycastHit> OnRaycasthit; // This event is called every frame that the user's gaze is over a collider. | 7 | public event Action<RaycastHit> OnRaycasthit; // This event is called every frame that the user's gaze is over a collider. |
| 8 | 8 | ||
| ... | @@ -18,16 +18,12 @@ public class VREyeRaycaster : VRInputController | ... | @@ -18,16 +18,12 @@ public class VREyeRaycaster : VRInputController |
| 18 | private VRInteratable m_LastInteractible; //The last interactive item | 18 | private VRInteratable m_LastInteractible; //The last interactive item |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | - override protected void Update() | 21 | + void Update() |
| 22 | { | 22 | { |
| 23 | - base.Update(); | ||
| 24 | EyeRaycast(); | 23 | EyeRaycast(); |
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | - override protected void OnIndexTriggerButtonDown() | 26 | + |
| 28 | - { | ||
| 29 | - m_CurrentInteractible.OnTriggerClick(); | ||
| 30 | - } | ||
| 31 | 27 | ||
| 32 | private void EyeRaycast() | 28 | private void EyeRaycast() |
| 33 | { | 29 | { | ... | ... |
| 1 | using System.Collections; | 1 | using System.Collections; |
| 2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
| 3 | using UnityEngine; | 3 | using UnityEngine; |
| 4 | +using UnityEngine.XR; | ||
| 5 | + | ||
| 6 | +// VR 컨트롤러의 입력을 GetVRTriggerButton 과 GetVRGripButton 로 제공하는 클래스 | ||
| 7 | +public static class VRInput { | ||
| 8 | + | ||
| 9 | + public enum Hand {Left,Right}; | ||
| 4 | 10 | ||
| 5 | -// VR 컨트롤러의 인풋을 받아, 해당 함수를 발동하는 스크립트 | ||
| 6 | -// VR 컨트롤러에 대응해야 하는 클래스는, 이 스크립트를 상속받아서 | ||
| 7 | -// 단 두개의 함수 OnGripTriggerButtonDown 와 OnIndexTriggerButtonDown 만 오버라이드 하면 된다. | ||
| 8 | -public class VRInputController : MonoBehaviour { | ||
| 9 | 11 | ||
| 10 | /* | 12 | /* |
| 11 | 유니티는 OpenVR API 를 내장하고 있다. | 13 | 유니티는 OpenVR API 를 내장하고 있다. |
| ... | @@ -37,47 +39,60 @@ public class VRInputController : MonoBehaviour { | ... | @@ -37,47 +39,60 @@ public class VRInputController : MonoBehaviour { |
| 37 | */ | 39 | */ |
| 38 | 40 | ||
| 39 | 41 | ||
| 42 | + //왼손 | ||
| 40 | // 검지 손가락 트리거에 대응되는 입력 세팅 이름 | 43 | // 검지 손가락 트리거에 대응되는 입력 세팅 이름 |
| 41 | - public string indexTriggerName; | 44 | + static string leftIndexTriggerName = "LeftIndexTrigger"; |
| 42 | // 쥐는 트리거에 대응되는 입력 세팅 이름 | 45 | // 쥐는 트리거에 대응되는 입력 세팅 이름 |
| 43 | - public string gripTriggerName; | 46 | + static string leftGripTriggerName = "LeftGripTrigger"; |
| 44 | 47 | ||
| 45 | 48 | ||
| 46 | - // 입력 체크.. | ||
| 47 | - protected virtual void Update() | ||
| 48 | - { | ||
| 49 | - // indexTriggerName - 검지용 트리거를 누른 순간 | ||
| 50 | - if(Input.GetAxisRaw(indexTriggerName) >= 0.1f) | ||
| 51 | - { | ||
| 52 | - // 여기 내용을 원하는 처리로 교체하면 다른 게임에 적용 가능 | ||
| 53 | 49 | ||
| 54 | - // 검지손가락 트리거용 함수 발동 | 50 | + // 오른손 |
| 55 | - OnIndexTriggerButtonDown(); | 51 | + // 검지 손가락 트리거에 대응되는 입력 세팅 이름 |
| 56 | - Debug.Log("방아쇠를 누름"); | 52 | + static string rightIndexTriggerName = "RightIndexTrigger"; |
| 57 | - } | 53 | + // 쥐는 트리거에 대응되는 입력 세팅 이름 |
| 54 | + static string rightGripTriggerName = "RightGripTrigger"; | ||
| 58 | 55 | ||
| 59 | - // gripTriggerName - 쥐는 트리거를 누른 순간 | ||
| 60 | - if(Input.GetAxisRaw(gripTriggerName) >= 0.1f) | ||
| 61 | - { | ||
| 62 | - // 여기 내용을 원하는 처리로 교체하면 다른 게임에 적용 가능 | ||
| 63 | 56 | ||
| 64 | - // 쥐는 트리거용 함수 발동 | 57 | + // 편의를 위해 정적 함수로 입력을 제공 |
| 65 | - OnGripTriggerButtonDown(); | 58 | + public static bool GetTriggerButton(Hand hand) |
| 66 | - Debug.Log("사이드 방아쇠를 누름"); | 59 | + { |
| 60 | + if(hand == Hand.Right) | ||
| 61 | + { | ||
| 62 | + if(Input.GetAxisRaw(rightIndexTriggerName) >= 0.1f) | ||
| 63 | + { | ||
| 64 | + return true; | ||
| 67 | } | 65 | } |
| 68 | } | 66 | } |
| 69 | - | 67 | + else if(hand == Hand.Left) |
| 70 | - // 검지 트리거 버튼을 눌렀을때 발동될 함수 입니다. | ||
| 71 | - // 이것을 상속받아 오버라이드 하세요. | ||
| 72 | - protected virtual void OnIndexTriggerButtonDown() | ||
| 73 | { | 68 | { |
| 69 | + if(Input.GetAxisRaw(leftIndexTriggerName) >= 0.1f) | ||
| 70 | + { | ||
| 71 | + return true; | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | 74 | ||
| 75 | + return false; | ||
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | - // 쥐는 트리거 버튼을 눌렀을때 발동될 함수 입니다. | 78 | + |
| 78 | - // 이것을 상속받아 오버라이드 하세요. | 79 | + public static bool GetGripButton(Hand hand) |
| 79 | - protected virtual void OnGripTriggerButtonDown() | 80 | + { |
| 81 | + if(hand == Hand.Right) | ||
| 82 | + { | ||
| 83 | + if(Input.GetAxisRaw(rightGripTriggerName) >= 0.1f) | ||
| 80 | { | 84 | { |
| 85 | + return true; | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + else if(hand == Hand.Left) | ||
| 89 | + { | ||
| 90 | + if(Input.GetAxisRaw(leftGripTriggerName) >= 0.1f) | ||
| 91 | + { | ||
| 92 | + return true; | ||
| 93 | + } | ||
| 94 | + } | ||
| 81 | 95 | ||
| 96 | + return false; | ||
| 82 | } | 97 | } |
| 83 | } | 98 | } | ... | ... |
| 1 | fileFormatVersion: 2 | 1 | fileFormatVersion: 2 |
| 2 | -guid: 715fd8d3512a648df89f6adeca0aa407 | 2 | +guid: b08a39cf4ab32447e88c77e8eff973cf |
| 3 | -timeCreated: 1512113025 | 3 | +timeCreated: 1512278720 |
| 4 | licenseType: Pro | 4 | licenseType: Pro |
| 5 | MonoImporter: | 5 | MonoImporter: |
| 6 | externalObjects: {} | 6 | externalObjects: {} | ... | ... |
| ... | @@ -6,7 +6,7 @@ using UnityEngine; | ... | @@ -6,7 +6,7 @@ using UnityEngine; |
| 6 | using UnityEngine.XR; | 6 | using UnityEngine.XR; |
| 7 | 7 | ||
| 8 | // 현실의 디바이스를 트래킹하는 스크립트 | 8 | // 현실의 디바이스를 트래킹하는 스크립트 |
| 9 | -public class VRControllerTracking : MonoBehaviour { | 9 | +public class VRTrackingObject : MonoBehaviour { |
| 10 | 10 | ||
| 11 | // 트래킹 부위 식별자 | 11 | // 트래킹 부위 식별자 |
| 12 | public XRNode trackingNode; | 12 | public XRNode trackingNode; | ... | ... |
-
Please register or login to post a comment