Custom New Input System control map
Posted: Fri Jun 30, 2023 1:09 pm
I am having trouble with the new input system. My game already has an inputactions file I would like to also use for dialogue system, but I must be missing a step because my script is throwing errors.
My file has an action map called UI with UI inputs. (It's messy right now.)
My event system is pointing at this file. Dialogue Manager has InputDeviceManager attached. I have a script attached called RollerDSInputRegistration.cs, and this is the content:
Am I missing something? Thanks!
My file has an action map called UI with UI inputs. (It's messy right now.)
My event system is pointing at this file. Dialogue Manager has InputDeviceManager attached. I have a script attached called RollerDSInputRegistration.cs, and this is the content:
Code: Select all
using UnityEngine;
namespace PixelCrushers.DialogueSystem
{
/// <summary>
/// This class helps the Dialogue System's demo work with the New Input System. It
/// registers the inputs defined in DemoInputControls for use with the Dialogue
/// System's Input Device Manager.
/// </summary>
public class RollerDSInputRegistration : MonoBehaviour
{
#if USE_NEW_INPUT
private RollerDSInputRegistration controls;
// Track which instance of this script registered the inputs, to prevent
// another instance from accidentally unregistering them.
protected static bool isRegistered = false;
private bool didIRegister = false;
void Awake()
{
controls = new RollerDSInputRegistration();
}
void OnEnable()
{
if (!isRegistered)
{
isRegistered = true;
didIRegister = true;
controls.Enable();
InputDeviceManager.RegisterInputAction("Horizontal", controls.UI.Horizontal);
InputDeviceManager.RegisterInputAction("Vertical", controls.UI.Vertical);
InputDeviceManager.RegisterInputAction("Fire1", controls.UI.Fire1);
}
}
void OnDisable()
{
if (didIRegister)
{
isRegistered = false;
didIRegister = false;
controls.Disable();
InputDeviceManager.UnregisterInputAction("Horizontal");
InputDeviceManager.UnregisterInputAction("Vertical");
InputDeviceManager.UnregisterInputAction("Fire1");
}
}
#endif
}
}