Input Action Assets | Package Manager UI website (unity3d.com)
Input Action Assets | Package Manager UI website
Input Action Assets An "input action asset" is an asset containing input actions as well as their associated bindings and control schemes. These assets are distinguished by the .inputactions file extension and are stored in a plain JSON format. Creating In
docs.unity3d.com
Action 대리자 (System) | Microsoft Learn
Action 대리자 (System)
매개 변수가 없으며 값을 반환하지 않는 메서드를 캡슐화합니다.
learn.microsoft.com
유니티의 키 입력을 C#의 Action과 같은 대리자 기능을 이용해서 함수를 바인딩 할 수 있게 해주는 기능입니다.
Input Manager에서 관리하는 것 보다 훨씬 편리하게 키를 추가할 수 있고
Update 함수에서 키 입력을 체크하여 동작하는 방식에서 벗어나게 해주어 코드의 가독성도 높여준다는 장점이 있습니다.
사용 방법
1. 설치
- window -> Package Manager에서 Input Action Assets을 검색하여 설치해줍니다.
2. 생성
- Resources 폴더에 우클릭 -> Create -> Input Action Assets 생성
3 Action Map 만들기
- Action Maps 오른쪽 + 버튼 클릭하여 추가
4. Action 추가
- Actions 오른쪽 + 버특 클릭하여 추가
5. Action 키 정의
- Action -> Binding -> Path로 키 설정
7. Script에서 사용
private InputAction _UIInputManager;
void Start()
{
var inputActionAsset = Resources.Load<InputActionAsset>("Inputs/Input_UI");
var actionMap = inputActionAsset.FindActionMap("UI");
_UIInputManager = actionMap.FindAction("Skill_Menu");
_UIInputManager.Enable();
// KKeyAction에 대한 콜백 등록
_UIInputManager.performed += OnSkillMenu;
}
void OnSkillMenu(InputAction.CallbackContext context)
{
_skillMenuManager.GetComponent<SkillMenuManager>().ActiveMenu(_skillMenuManager.activeSelf != true);
}
'Unity' 카테고리의 다른 글
Unity Instantiate (1) | 2024.06.11 |
---|---|
Unity JsonUtility (0) | 2024.05.31 |
Unity Google Admob (0) | 2024.04.22 |
Unity JAVA_TOOL_OPTIONS Error (Gradle Bild failed) (0) | 2024.04.22 |
Character Controller move가 안될때 (0) | 2022.08.03 |