๋ฌธ์ œ๊ฐ€ ๋˜์—ˆ๋˜ ์ฝ”๋“œ

//----------------------์ฝ”๋“œ๋ถ€-----------------------------------

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; public class KeyBindingSetting : MonoBehaviour { public List<InputActionReference> Actions; private InputActionRebindingExtensions.RebindingOperation rebindOperation; void RebindCompleted(KeySettingSection section) { rebindOperation.Dispose(); rebindOperation = null; section.UpdateText(); } public void StartInteractiveRebind(KeySettingSection section) { rebindOperation = Actions[section.RebindActionIndex].action .PerformInteractiveRebinding() .WithControlsExcluding("<Mouse>/position") .WithControlsExcluding("<Mouse>/delta") .WithControlsExcluding("<Gamepad>/Start") .WithControlsExcluding("<Keyboard>/escape") .OnMatchWaitForAnother(0.1f) .OnComplete(operation => RebindCompleted(section)); rebindOperation.Start(); } }
//------------------------------์ฝ”๋“œ๋ถ€----------------------------------------


๋ณธ์ธ์€ ์ธํ’‹ ์‹œ์Šคํ…œ์—์„œ ์ถ”๊ฐ€์ ์œผ๋กœ ๊ฑด๋“ค ์ผ์ด ์ƒ๊ธธ ๊ฒฝ์šฐ, ๊ทธ ๋‚ด์šฉ์ด ๋ฐ”๋กœ ๋ฐ˜์˜๋  ์ˆ˜ ์žˆ๋„๋ก ์—์…‹์—์„œ ์ง์ ‘ ์•ก์…˜ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ๋Œ์–ด๋‹ค๊ฐ€ ๋ฐ›์•„์˜ค๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ฆฌ๋ฐ”์ธ๋”ฉ ๊ตฌ์กฐ๋ฅผ ๊ตฌํ˜„ํ•˜๊ณ ์ž ํ–ˆ์Œ


๊ทธ๋Ÿฐ๋ฐ ์ด ๋ฐฉ์‹์œผ๋กœ ํ•˜๋‹ˆ, ๋ถ„๋ช…ํžˆ ํ‚ค ๋ฆฌ๋ฐ”์ธ๋“œ๊ฐ€ ๋กœ๊ทธ์—์„œ๋„ ๋“œ๋Ÿฌ๋‚˜๊ณ , section.UpdateText(); ํ•จ์ˆ˜ ๊ตฌ๋™ ์‹œ์—๋„ ๋ณ€๊ฒฝ๋œ ๋ฐ”์ธ๋”ฉ ์„ธํŒ…์œผ๋กœ ๋“œ๋Ÿฌ๋‚˜๋Š”๋ฐ๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ๋ฐ”์ธ๋”ฉ์ด ์ž˜ ์•ˆ๋˜๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒํ•˜์˜€์Œ


์ด๊ฑธ ๊ณ ์น˜๊ธฐ ์œ„ํ•ด ์–ด๋””๊ฐ€ ๋ฌธ์ œ์ง€ ํ•˜๊ณ  ์ฐพ์•„๋ดค์—ˆ๋Š”๋ฐ, ์–ผ๋–จ๊ฒฐ์— ๋‹ค๋ฅธ ํ”„๋กœ์ ํŠธ ์ฝ”๋“œ์™€ ๋Œ€์กฐํ•˜๋‹ค๋ณด๋‹ˆ ์–ด๋””๊ฐ€ ๋ฌธ์ œ์˜€๋Š”์ง€ ์•Œ๊ฒŒ ๋˜์—ˆ์Œ


//์ดํ•˜ ๋‚ด์šฉ์€ ์ถ”๋ก ์ƒ ๋‚ด๋ฆฐ ๊ฒฐ๋ก ์ž„

์ด ๋ฐฉ์‹๋Œ€๋กœ ํ•  ๊ฒฝ์šฐ ์—์…‹์ด ๋‹ด๊ณ  ์žˆ๋Š” ๋ ˆํผ๋Ÿฐ์Šค์˜ ์ •๋ณด๋Š” ๊ฐฑ์‹ ์ด ๋˜๋Š”๋ฐ, ํ”Œ๋ ˆ์ด์–ด ์›€์ง์ž„์„ ์ œ์–ดํ•˜๋Š” ๋ถ€๋ถ„์—์„œ๋Š” ๊ฐฑ์‹ ์ด ์•ˆ ๋˜์–ด์„œ ๋ณ„๋„๋กœ ๊ฐฑ์‹ ์„ ์ง์ ‘ ํ•ด ์ค˜์•ผ ํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฑฐ์˜€์Œ


์ด ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•˜๊ณ ์ž ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•˜๊ฒŒ ๋˜์—ˆ์Œ


//--------------------์ฝ”๋“œ๋ถ€------------------------------

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; public class KeyBindingSetting : MonoBehaviour { public InputActionAsset IAA; public List<InputActionReference> Actions; private InputActionRebindingExtensions.RebindingOperation rebindOperation; void RebindCompleted(KeySettingSection section) { rebindOperation.Dispose(); rebindOperation = null; GameController.GetPlayer.GetComponent<PlayerInput>().actions = IAA; section.UpdateText(); } public void StartInteractiveRebind(KeySettingSection section) { rebindOperation = Actions[section.RebindActionIndex].action .PerformInteractiveRebinding() .WithControlsExcluding("<Mouse>/position") .WithControlsExcluding("<Mouse>/delta") .WithControlsExcluding("<Gamepad>/Start") .WithControlsExcluding("<Keyboard>/escape") .OnMatchWaitForAnother(0.1f) .OnComplete(operation => RebindCompleted(section)); rebindOperation.Start(); } }
//----------------------์ฝ”๋“œ๋ถ€--------------------------


๋ณ€๊ฒฝ๋œ ์•ก์…˜ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ์ธํ’‹ ์•ก์…˜ ์—์…‹์„ ๋Œ๊ณ ์˜ค๊ณ , ๊ทธ๊ฒƒ์„ ์‹ฑ๊ธ€ํ†ค์œผ๋กœ ์ถ”์ ์ค‘์ธ ํ”Œ๋ ˆ์ด์–ด์˜ ํ”Œ๋ ˆ์ด์–ด ์•ก์…˜ ์ปดํฌ๋„ŒํŠธ์— ๋„ฃ์–ด์„œ ์ง์ ‘ ๊ฐฑ์‹ ๋œ ๊ฐ’์„ ๋„ฃ์–ด์ฃผ๋Š” ๋ฐฉ์‹์œผ๋กœ ๋Œ๋ ธ์Œ


์š”์ฝ”๋กœ๋กฌ ๋ฐ”๊พธ๋‹ˆ ์ด์ œ์•ผ ๋ฆฌ๋ฐ”์ธ๋”ฉ ๋œ ํ‚ค ์ž…๋ ฅ์„ ๋ฐ›์•„๋“ค์ด๊ฒŒ ๋˜๋”๋ผ


์ž„์‹œ ๋•œ๋ฐฉ์œผ๋กœ ๋ฐฉ์‹๋งŒ ์•Œ์•„๋‚ธ๊ฑฐ๋ผ ๋น„ํšจ์œจ์ ์ธ ๋ถ€๋ถ„์ด ๋‚จ์•„ ์žˆ๊ธด ํ•œ๋ฐ, ์ด ๋ถ€๋ถ„์€ ๊ฐœ์„  ์ž‘์—… ๋“ค์–ด๊ฐ€๋ฉด ๋˜๋Š” ๋ฌธ์ œ์ด๊ธฐ๋„ ํ•˜๊ณ , ์šฐ์„  ์ ์–ด๋„ ๋ฌธ์ œ์ ์ด ์–ด๋””์ธ์ง€๋Š” ์ฐพ์•„๋‚ด์„œ ๋‚˜๋ฆ„ ๋ณด๋žŒ์„ ๋А๊ผˆ์Œ


๊ตฌํ˜„ ์ž์ฒด๊ฐ€ ์ข€ ๊นŒ๋‹ค๋กญ๊ธฐ๋Š” ํ–ˆ์–ด๋„, ๋•๋ถ„์— ์ข‹์€ ๊ณต๋ถ€๊ฐ€ ๋˜์—ˆ์Œ


์ตœ๊ณ 


ํ˜น์‹œ๋ผ๋„ ๋น„์Šทํ•˜๊ฒŒ ํ•ด๋งค๋Š” ์ธ๋ถ•์ด๋“ค ์žˆ์„๊นŒ๋ด ํ•˜์ฐฎ์€ ๊ธ€ ๋‚จ๊ธฐ๊ณ ๊ฐ...



//ps. ํ˜น์‹œ ์ข€ ๋” ๊ฐœ์ฉŒ๋Š” ๋ฐฉ์‹๊ฐ™์€๊ฑฐ ์•Œ๊ณ ๊ณ„์‹œ๋ฉด ๋Œ“๊ธ€๋กœ ๋‚จ๊ฒจ์ฃผ์‹œ๋ฉด ๋งค์šฐ ๊ฐ์‚ฌํ•˜๊ฒŸ์Šด๋‹ˆ๋‹ค...




//์ˆ˜์ •(2022.08.27.15.05)

๋ฆฌ๋ฐ”์ธ๋“œ ๊ณผ์ • ์ง„ํ–‰์ค‘์— ํ•ด๋‹น ์•ก์…˜์„ ์ผ๋‹จ Disable()๋กœ ๋ฐ”๊พธ๊ณ ์„œ, ์ „ํ™˜ ํ›„ Enable() ๋กœ ํ•ด์ฃผ์…”์•ผ ๋ฌธ์ œ๊ฐ€ ์•ˆ์ƒ๊น๋‹ˆ๋‹ค...


public void StartInteractiveRebind(KeySettingSection section) { InputAction IA = Actions[section.RebindActionIndex].action; IA.Disable(); rebindOperation = IA.PerformInteractiveRebinding() .WithControlsExcluding("<Mouse>/position") .WithControlsExcluding("<Mouse>/delta") .WithControlsExcluding("<Gamepad>/Start") .WithControlsExcluding("<Keyboard>/escape") .OnMatchWaitForAnother(0.1f) .OnComplete(operation => RebindCompleted(section)); rebindOperation.Start(); IA.Enable(); }


์•ฝ๊ฐ„ ์ด๋Ÿฐ ๋А๋‚Œ์œผ๋กœ