๐ฆ Input System
- Action-based์ Device-based. 2๊ฐ์ง ํ์ ์ ์ธํ ์์คํ ์ด ์๋ค.
๐ง Document
๐ฆ Device-based
๐ง ํน์ง
- XR ๊ธฐ๊ธฐ๋ง์ ํ๊ฒํ ํ๋ค.
- ์ค์ ํด๋์ ํ๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก๋ง ์ธํ์ด ๊ฐ๋ฅํ๋ค.
- ์ค์ ์ ๊ฐ๋จํ๊ฒ ์ฒ๋ฆฌํ ์ ์๋ค.
๐ง ์ค์ ๋ฐฉ๋ฒ
- XR Rig ์ถ๊ฐ(Device-based)
- XR Controller(Device-based) ์ปดํฌ๋ํธ ์ํ๋ ๊ฐ์ผ๋ก ์ค์
๐ฆ Action-based
๐ง ํน์ง
- ์ฌ๋ฌ ๊ธฐ๊ธฐ์ ๋์ํ ์ ์๋ค.
- ์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก ์ธํ์ด ๊ฐ๋ฅํ๋ค.
- ํ๋์ฉ ๋งตํ์ ํด์ค์ผํ๋ค.
๐ง ์ค์ ๋ฐฉ๋ฒ
- XR Rig (Action-based) ์ถ๊ฐ
- controller ์ค๋ธ์ ํธ๋ฅผ ์ดํด๋ณด๋ฉด reference๋ค์ด ์ฐ๊ฒฐ๋์ด ์๋ค.
- ์ฐ๊ฒฐ๋ reference๋ฅผ ์ด์ด๋ณด๋ฉด ํค๊ฐ ๋งตํ๋์ด์๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
(XR Toolkit์ sample์ ๋ค์ด๋ฐ์์ ๊ทธ๋ด ์๋ ์์)
- ๊ฐ๋ น Select ์ก์
์ ํค๋ณด๋ Space ํค๋ก๋ ๊ฐ๋ฅํ๊ฒ ํ๊ณ ์ถ๋ค๋ฉด
- Select ํ์์ Space ํค๋ฅผ ์ถ๊ฐํด์ฃผ๋ฉด ๋๋ค.
- '+' ๋ฒํผ์ ๋๋ฅธ ํ Add Binding
- Path > Listen > Space๋ฅผ ๋๋ฅด๋ฉด ๋ฐ๋ก ๋ฌ๋ค.
- ํค๊ฐ ์ถ๊ฐ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
- Save Asset ๊ผญ ํด์ฃผ๊ธฐ
๐ฆ Input ๊ฐ ์ฒดํฌํ๊ธฐ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CommonUsages = UnityEngine.XR.CommonUsages;
using UnityEngine.XR.Interaction.Toolkit;
using UnityEngine.InputSystem;
public class XRInput : MonoBehaviour
{
#region Device-based
[SerializeField] private XRController m_LeftXRC;
private bool m_IsLeftGripButtonPressed;
private void Update()
{
m_LeftXRC.inputDevice.TryGetFeatureValue(CommonUsages.gripButton, out m_IsLeftGripButtonPressed);
if (m_IsLeftGripButtonPressed)
{
Debug.Log("Left GripButton is Pressed");
}
}
# endregion
#region Action-based
[SerializeField] private InputActionReference m_LeftSelectRef;
[SerializeField] private InputActionAsset m_ActionAsset;
private void OnEnable()
{
m_ActionAsset.Enable();
// ๋ฐฉ๋ฒ 1
// m_ActionAsset.FindActionMap("XRI LeftHand").FindAction("Select").performed += SelectLeft;
// m_ActionAsset.FindActionMap("XRI LeftHand").FindAction("Select").canceled += CancelSelectLeft;
// ๋ฐฉ๋ฒ2
m_LeftSelectRef.action.performed += SelectLeft;
m_LeftSelectRef.action.canceled += CancelSelectLeft;
}
private void OnDisable()
{
m_ActionAsset.Disable();
m_LeftSelectRef.action.performed -= SelectLeft;
m_LeftSelectRef.action.canceled -= CancelSelectLeft;
}
private void SelectLeft(InputAction.CallbackContext obj)
{
Debug.Log("Select Left");
}
private void CancelSelectLeft(InputAction.CallbackContext obj)
{
Debug.Log("Cancel Select Left");
}
#endregion
}
- ์คํฌ๋ฆฝํธ ์์ฑ ํ ์ฝ๋ ์์ฑ
- ์ธ์คํํฐ ์ฐ๊ฒฐ
- Select์ Space ํค๋ฅผ ๋งตํํด๋์๊ธฐ ๋๋ฌธ์ Action-base๋ฅผ ํ ์คํธํด๋ณผ ์ ์๋ค.
๐ฆ ๋น๊ต
๐ง Device-based
- ํน์ ๋ฒํผ์ ์ ๋ ฅํ๋์ง ์ง์ ๊ฐ์ ธ์ฌ ์ ์๋ค.
๐ง Action-based
- ์ฌ๋ฌ ํค๋ฅผ ๋งตํํ ์ ์๋ค.
- ์ฌ๋ฌ ๊ธฐ๊ธฐ์ ๋ํด ๋์ํ ์ ์๋ค.
- ํน์ ๋ฒํผ์ด ์๋ ๋งตํํด๋์ action์ผ๋ก ๊ฐ์ ๊ฐ์ ธ์์ผํ๋ค.
'Unity > VR' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
XR Interaction Toolkit - Locomotion (0) | 2021.10.01 |
---|---|
XR Interaction Toolkit - Setting (2) | 2021.09.22 |