Page 1 of 1

Using custom input instead of basic Unity keycodes and InputManager

Posted: Mon Mar 28, 2016 10:44 am
by Ders
I'm trying to figure out if there's a way to override the way that the Dialogue System Controller checks if the cancel button has been pressed. I'm using Rewired for the input in my game and I would like to be able to connect it to the Dialogue System.
I've found that I can setup a regular KeyCode or a Button Name that references one of the buttons from the regular InputManager but I'm not using both since I'm setting those things up in the Rewired plugin.

So, is there a way to override this cancel button functionality?

Re: Using custom input instead of basic Unity keycodes and InputManager

Posted: Mon Mar 28, 2016 12:18 pm
by Tony Li
Hi,

Set the Dialogue Manager's Cancel keys to KeyCode.None and button names to a blank string. This disables the default input manager check.

An explicit delegate for third party input managers like Rewired is on the roadmap, but the following has worked well for other developers so the delegate hasn't been implemented yet.

Add a script to the Dialogue Manager that implements the OnConversationLine and OnConversationResponseMenu script messages. In them, send "OnCancelSubtitle" or "OnCancelResponseMenu". The script below uses the same cancel button for both types of cancel:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
using Rewired;

public class RewiredToDialogueSystem : MonoBehaviour {

    public string cancelButton = "Cancel"; // Define this button in Rewired.
    public int playerId = 0; // The Rewired player id.
    
    private Player player;
    private string cancelMessage = null;

    void Awake() {
        player = ReInput.players.GetPlayer(playerId);
    }
    
    void OnConversationLine(Subtitle subtitle) {
        cancelMessage = "OnCancelSubtitle";
    }
    
    void OnConversationResponseMenu(Response[] responses) {
        cancelMessage = "OnCancelResponseMenu";
    }
    
    void Update () {
        if (DialogueManager.IsConversationActive && player.GetButtonDown(cancelButton)) {
            SendMessage(cancelMessage);
        }
    }
}

Re: Using custom input instead of basic Unity keycodes and InputManager

Posted: Tue Mar 29, 2016 4:58 am
by Ders
Thanks a lot :) This is much easier then expected

Re: Using custom input instead of basic Unity keycodes and InputManager

Posted: Tue Mar 29, 2016 8:30 am
by Tony Li
Happy to help!