Attaching submit/cancel input to button event of Doozy UI from Rewired
Tags: unity3d, rewired, doozyui, gamedev
Published: 2020-04-10 13:03:41

---
title: Attaching submit/cancel input to button event of Doozy UI from Rewired
published: true
description: "Solve the issue using Doozy UI with Rewired in Unity"
tags: unity, rewired, doozyui, gamedevelopment
---

日本語は下部に書いてあります

In a vanilla unity project, the uGUI button input from the joystick or keyboard are can be detected by the Standalone Input Module and Event System component.

It requires setting first on the Input section in the Unity project setting that witch key or joystick button means of submit/cancel input.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/01n5gzhxztxpglqmgk8l.png)

With Doozy UI asset, the joystick input detect must set in Input Mode section on UI Button component. Change the Input Mode to Virtual Button, and write the button name.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mw5djesz2pvzjpb7aus1.png)

But if using Rewired asset with, it doesn't work because Dozzy doesn't refer to the Rewired Setting. 
So in this case, it has to change the code in UIButton.cs of Doozy UI as below.

```csharp

private IList<Player> reInputPlayerList;

public override void Awake()
{
    (omitted)

    ReInput.ControllerPreDisconnectEvent += _ => { reInputPlayerList = ReInput.players.AllPlayers;};
    reInputPlayerList = ReInput.players.AllPlayers;
}

(omitted)

private void Update()
{
        (omitted)

        case InputMode.VirtualButton:
            var isButtonDown = false;
            for (var index = 0; index < reInputPlayerList.Count; index++)
            {
                var r = reInputPlayerList[index];
                isButtonDown =
                    r.GetButtonDown(InputData.VirtualButtonName) ||
                    (InputData.EnableAlternateInputs && r.GetButtonDown(InputData.VirtualButtonNameAlt));

                    if (isButtonDown == true)break;
            }

            if (isButtonDown) ExecuteClick();
            break;

        (omitted)
    }
}

```
and it will work :)!

BackButton.cs needs the same modification if you use Back button operation in Nody.


--- 日本語 ---

通常のUnityプロジェクトでは、ジョイスティックやキーボードからのuGUIボタン入力はStandalone Input ModuleとEvent Systemコンポーネントで検出することができます。

そのためには、Unity ProjectのInputセクションで、どのキーやジョイスティックボタン submit/cancelの入力を行うかを最初に設定しておく必要があります。

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/01n5gzhxztxpglqmgk8l.png)

Doozy UI アセットでは、UI Button コンポーネントの Input Mode セクションでジョイスティック入力検出を設定する必要があります。Input ModeをVirtual Buttonに変更し、ボタン名を記述します。

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mw5djesz2pvzjpb7aus1.png)

しかしRewiredを使っている場合、Dozzy は Rewired 設定を参照していないので動作しません。そのため、Doozy UIのUIButton.csのコードを以下のように変更する必要があります。


```csharp

private IList<Player> reInputPlayerList;

public override void Awake()
{
    (中略)

    ReInput.ControllerPreDisconnectEvent += _ => { reInputPlayerList = ReInput.players.AllPlayers;};
    reInputPlayerList = ReInput.players.AllPlayers;
}

(中略)

private void Update()
{
        (中略)

        case InputMode.VirtualButton:
            var isButtonDown = false;
            for (var index = 0; index < reInputPlayerList.Count; index++)
            {
                var r = reInputPlayerList[index];
                isButtonDown =
                    r.GetButtonDown(InputData.VirtualButtonName) ||
                    (InputData.EnableAlternateInputs && r.GetButtonDown(InputData.VirtualButtonNameAlt));
            }

            if (isButtonDown) ExecuteClick();
            break;

        (中略)
    }
}

```

これで動作します！

Backボタン操作をNodyで使用する場合は、BackButton.csにも同様の変更が必要です。