Skip to content

키 리바인딩 완성#137

Open
wkdrudgnsdla wants to merge 2 commits intodevelopfrom
feature/InputSystem
Open

키 리바인딩 완성#137
wkdrudgnsdla wants to merge 2 commits intodevelopfrom
feature/InputSystem

Conversation

@wkdrudgnsdla
Copy link
Collaborator

사용방법: 인풋 UI에 버튼 입력 추가,
조작방식이 키보드일 경우
StartRebinding(인풋액션, 조작법)에서
조작법에 해당하는 위치에 "Keyboard, Mouse"
게임패드일 경우에는 "Gamepad" 입력, 바인딩 잘됩니당

제작한 내용
리바인딩, 세이브, 리셋, 로딩

사용방법: 인풋 UI에 버튼 입력 추가,
조작방식이 키보드일 경우
StartRebinding(인풋액션, 조작법)에서
조작법에 해당하는 위치에 "Keyboard, Mouse"
게임패드일 경우에는 "Gamepad" 입력, 바인딩 잘됩니당

제작한 내용
리바인딩, 세이브, 리셋, 로딩
@wkdrudgnsdla wkdrudgnsdla requested a review from leesiuuuu March 23, 2026 12:16
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 풀 리퀘스트는 게임 내에서 키보드/마우스 및 게임패드 입력에 대한 키 리바인딩 기능을 완벽하게 구현합니다. 사용자는 이제 원하는 대로 키 바인딩을 변경하고, 이를 저장 및 불러올 수 있으며, 필요에 따라 초기화할 수도 있습니다.

Highlights

  • 키 리바인딩 시스템 추가: 사용자가 게임 내에서 키보드/마우스 및 게임패드 입력을 자유롭게 재설정할 수 있는 새로운 키 리바인딩 시스템이 구현되었습니다.
  • UI 통합: 새로운 InputUI.cs 스크립트와 RebindingUI 게임 오브젝트를 통해 리바인딩 기능을 위한 사용자 인터페이스가 추가되었습니다.
  • 바인딩 관리 기능: RebindingManager.cs 스크립트는 대화형 리바인딩 작업, PlayerPrefs를 이용한 바인딩 저장 및 불러오기, 그리고 바인딩 초기화 기능을 제공합니다.
  • UI 제어 입력 확장: PlayerAction.inputactions 파일에 UI 제어를 위한 키보드 방향키 바인딩이 추가되었습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

키 리바인딩 기능 구현을 위한 PR 잘 보았습니다. 전반적으로 기능 구현은 잘 된 것으로 보이지만, 몇 가지 수정이 필요한 부분이 있습니다. 주로 문자열 인코딩 문제, 하드코딩된 문자열, 그리고 잘못된 기본값 사용으로 인한 버그 가능성입니다. 또한, 디버깅용 코드가 남아있어 정리할 필요가 있어 보입니다. 자세한 내용은 각 파일의 주석을 참고해주세요.

Comment on lines +16 to +19
public void OnClickRebindJump() => rebindingManager.StartRebinding(jumpAction);
public void OnClickRebindUISelect() => rebindingManager.StartRebinding(uiSelectAction);
public void OnClickRebindGrab() => rebindingManager.StartRebinding(grabAction, "Keyboard, Mouse");
public void OnClickRebindPush() => rebindingManager.StartRebinding(pushAction);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

RebindingManager.StartRebinding 메소드의 기본 controlScheme 값이 "Keyboard&Mouse"로 잘못 설정되어 있어, controlScheme을 명시하지 않은 호출들은 리바인딩에 실패할 수 있습니다. 모든 호출에 "Keyboard, Mouse"를 명시적으로 전달하도록 수정하는 것을 권장합니다.

    public void OnClickRebindJump() => rebindingManager.StartRebinding(jumpAction, "Keyboard, Mouse");
    public void OnClickRebindUISelect() => rebindingManager.StartRebinding(uiSelectAction, "Keyboard, Mouse");
    public void OnClickRebindGrab() => rebindingManager.StartRebinding(grabAction, "Keyboard, Mouse");
    public void OnClickRebindPush() => rebindingManager.StartRebinding(pushAction, "Keyboard, Mouse");

"UIControll"
};

public void StartRebinding(InputActionReference actionReference, string controlScheme = "Keyboard&Mouse")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

controlScheme의 기본값이 "Keyboard&Mouse"로 되어있습니다. .inputactions 파일에 정의된 컨트롤 스킴 이름은 "Keyboard, Mouse"이므로, &, 로 수정해야 합니다. 그렇지 않으면 기본값을 사용하는 리바인딩 호출이 모두 실패하게 됩니다.

    public void StartRebinding(InputActionReference actionReference, string controlScheme = "Keyboard, Mouse")

{
[SerializeField] private RebindingManager rebindingManager;

[Header("�����ε� ������ �׼Ǹ� ���")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

헤더의 한글이 깨져서 보입니다. 파일 인코딩을 UTF-8로 저장하여 수정해주세요.

    [Header("리바인딩 대상인 액션들")]

Comment on lines +23 to +53
Debug.Log("1");

InputAction action = actionReference.action;

if (_lockedActions.Contains(action.name)) return;

Debug.Log("2");

int bindingIndex = action.GetBindingIndex(
InputBinding.MaskByGroup(controlScheme)
);

if (bindingIndex == -1)
{
Debug.LogWarning($"[{action.name}] {controlScheme} ���ε� ����");
return;
}

action.Disable();

_rebindOperation = action
.PerformInteractiveRebinding(bindingIndex)
.WithControlsExcluding("<Mouse>/position")
.WithControlsExcluding("<Mouse>/delta")
.WithControlsExcluding("<Mouse>/scroll")
.WithCancelingThrough("<Keyboard>/escape")
.WithoutGeneralizingPathOfSelectedControl()
.OnMatchWaitForAnother(0.2f)
.OnComplete(operation =>
{
Debug.Log(3);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

개발 중 사용하신 것으로 보이는 Debug.Log("1"), Debug.Log("2"), Debug.Log(3) 호출들이 남아있습니다. 불필요한 로그이므로 제거하는 것이 좋습니다.

Comment on lines +37 to +65
Debug.LogWarning($"[{action.name}] {controlScheme} ���ε� ����");
return;
}

action.Disable();

_rebindOperation = action
.PerformInteractiveRebinding(bindingIndex)
.WithControlsExcluding("<Mouse>/position")
.WithControlsExcluding("<Mouse>/delta")
.WithControlsExcluding("<Mouse>/scroll")
.WithCancelingThrough("<Keyboard>/escape")
.WithoutGeneralizingPathOfSelectedControl()
.OnMatchWaitForAnother(0.2f)
.OnComplete(operation =>
{
Debug.Log(3);
action.Enable();
_rebindOperation?.Dispose();
_rebindOperation = null;
SaveBindings();
Debug.Log($"[{action.name}] [{controlScheme}] �����ε� �Ϸ�: {action.bindings[bindingIndex].effectivePath}");
})
.OnCancel(operation =>
{
action.Enable();
_rebindOperation?.Dispose();
_rebindOperation = null;
Debug.Log($"[{action.name}] �����ε� ���");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

로그 메시지의 한글이 깨져서 보입니다. 파일 인코딩을 UTF-8로 저장하여 수정해주세요.

  • 37행: Debug.LogWarning($"[{action.name}] {controlScheme} 바인딩을 찾지 못했습니다");
  • 58행: Debug.Log($"[{action.name}] [{controlScheme}] 리바인딩 완료: {action.bindings[bindingIndex].effectivePath}");
  • 65행: Debug.Log($"[{action.name}] 리바인딩 취소");

Comment on lines +70 to +79
public void ResetBinding(InputActionReference actionReference, int bindingIndex = 0)
{
if (actionReference == null) return;

InputAction action = actionReference.action;

if (_lockedActions.Contains(action.name)) return;

action.RemoveBindingOverride(bindingIndex);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

ResetBinding 메소드가 bindingIndex를 인자로 받지만, 기본값 0을 사용하면 의도치 않은 바인딩을 초기화할 수 있습니다. StartRebinding처럼 controlScheme을 사용하여 초기화할 바인딩을 명확하게 찾는 것이 더 안전합니다.

    public void ResetBinding(InputActionReference actionReference, string controlScheme = "Keyboard, Mouse")
    {
        if (actionReference == null) return;

        InputAction action = actionReference.action;

        if (_lockedActions.Contains(action.name)) return;

        int bindingIndex = action.GetBindingIndex(InputBinding.MaskByGroup(controlScheme));
        if (bindingIndex != -1)
        {
            action.RemoveBindingOverride(bindingIndex);
        }
    }

Comment on lines +81 to +92
private void SaveBindings()
{
string json = inputActions.SaveBindingOverridesAsJson();
PlayerPrefs.SetString("InputBindings", json);
PlayerPrefs.Save();
}

public void LoadBindings()
{
if (PlayerPrefs.HasKey("InputBindings"))
inputActions.LoadBindingOverridesFromJson(PlayerPrefs.GetString("InputBindings"));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

PlayerPrefs에 사용되는 키 "InputBindings"가 하드코딩되어 있습니다. 오타를 방지하고 유지보수성을 높이기 위해 상수로 분리하는 것이 좋습니다.
클래스 상단에 다음과 같이 상수를 추가하고,

private const string InputBindingsKey = "InputBindings";

SaveBindingsLoadBindings 메소드에서 이 상수를 사용하도록 수정해주세요.

Comment on lines +88 to +92
public void LoadBindings()
{
if (PlayerPrefs.HasKey("InputBindings"))
inputActions.LoadBindingOverridesFromJson(PlayerPrefs.GetString("InputBindings"));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

저장된 바인딩 설정을 불러오는 LoadBindings 메소드가 있지만, 게임 시작 시 자동으로 호출되지 않는 것 같습니다. Awake() 메소드를 추가하여 그 안에서 LoadBindings()를 호출하면, 게임이 시작될 때 사용자의 키 설정을 자동으로 불러올 수 있습니다.

private void Awake()
{
    LoadBindings();
}

Copy link
Owner

@leesiuuuu leesiuuuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants