Using custom input instead of basic Unity keycodes and InputManager

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Ders
Posts: 18
Joined: Thu Mar 10, 2016 3:53 am

Using custom input instead of basic Unity keycodes and InputManager

Post 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?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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);
        }
    }
}
Ders
Posts: 18
Joined: Thu Mar 10, 2016 3:53 am

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

Post by Ders »

Thanks a lot :) This is much easier then expected
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

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

Post by Tony Li »

Happy to help!
Post Reply