Skip to main content

Module Intro

Important Attention Reminder

Coding Style wiki​


Basic Instructions​

Input control system that supports Unity New InputSystem. When using Unity New InputSystem, you create its Control Maps yourself, and the module also provides a Binding Composite script template for Unity New InputSystem. Finally, Input Actions dispatch input signals that are subscribed to by subscribers, so the in-game control logic does not need to know about platform or device differences — everything is integrated by Input Actions. Of course, Input Actions also support other input plugins, acting as pure input-signal dispatchers.

  • Version: v1.0.4 (com.michaelo.oxgkit.inputsystem)
  • Namespace: OxGKit.InputSystem

Attention This module depends on Unity New InputSystem and OxGKit.LoggingSystem (for log output); install the dependencies first.


Application Description​

Main Drive Layers​

  • For Unity New InputSystem
    • Control Maps (Input Action Asset)
    • Binding Composites
  • For Any Inputs
    • Input Actions (standalone universal signal dispatchers that do not depend on any input plugin — any input source can be implemented freely)

Script Templates (Right-Click)​

  • Use Right-Click Create/OxGKit/Input System/Template Input Action.cs (Input Interface For Any) to implement the InputAction interface (universal signal dispatcher); after creation, at game startup register Inputs.CM.RegisterControlMap and then Inputs.IA.RegisterInputAction to activate it (see "Simple Usage" below).
  • Use Right-Click Create/OxGKit/Input System/New Input System (Extension)/Template Input Binding Composite.cs (For Unity New Input System) to implement your own custom Binding Composite (combining multiple input parts into a single input value); the template ships with automatic registration at startup, so once created it becomes selectable in the Input Action Asset's binding list (see IInputAction - Script Templates).

Reminder The Editor part of this module only provides the script-template MenuItems above (InputSystemCreateScriptEditor) as a script-creation helper; there is no other Editor API.

Using the Inputs API​

  • Call the Inputs API (using OxGKit.InputSystem) and use Inputs.CM (Control Maps) and Inputs.IA (Input Actions) to register, get, toggle, and drive updates.

Module Logger​

  • This module logs through OxGKit.LoggingSystem with the logger name OxGKit.InputSystem.Logger; its toggle and level can be configured in LoggingLauncher.

Simple Usage​

Implement an Input Action (Signal Dispatcher)​

using System;
using OxGKit.InputSystem;
using UnityEngine.InputSystem;

public class PlayerAction : IInputAction
{
// Custom input event (subscribed to by subscribers)
public event Action<MoveInputComposite.MoveInput> onMoveAction;

public void OnCreate()
{
// On registration, get the registered Control Map and bind events
var ctrls = Inputs.CM.GetControlMap<PlayerControls>();
if (ctrls != null)
{
// add move input performed (player move)
ctrls.Player.Move.performed += this.OnMoveAction;
// add move input canceled to reset input data
ctrls.Player.Move.canceled += this.OnMoveAction;
}
}

public void OnUpdate(float dt)
{
// Optional polling-style input detection (driven by Inputs.IA.DriveUpdate)
}

public void RemoveAllListeners()
{
this.onMoveAction = null;
}

protected void OnMoveAction(InputAction.CallbackContext context)
{
// If there is a special input can make composite by yourself
// Read your composite values
var moveInput = context.ReadValue<MoveInputComposite.MoveInput>();
this.onMoveAction?.Invoke(moveInput);
}
}

Register and Drive Updates​

using OxGKit.InputSystem;
using UnityEngine;

public class InputDemo : MonoBehaviour
{
private void Awake()
{
// If use Unity New Input System must register control maps
Inputs.CM.RegisterControlMap<PlayerControls>();

// Register an input action (after control maps registered)
Inputs.IA.RegisterInputAction<PlayerAction>();
}

private void OnEnable()
{
// Add handle event
Inputs.IA.GetInputAction<PlayerAction>().onMoveAction += this._OnMoveAction;
}

private void OnDisable()
{
// Del handle event
Inputs.IA.GetInputAction<PlayerAction>().onMoveAction -= this._OnMoveAction;
}

private void Update()
{
// Call by Main MonoBehaviour (Main Program)
Inputs.IA.DriveUpdate(Time.unscaledDeltaTime);
}

private void _OnMoveAction(MoveInputComposite.MoveInput moveInput)
{
// Records move input signals and input data
}
}

Important Registration order: register Control Maps first, then Input Actions (an Input Action's OnCreate usually fetches a Control Map for binding).

Toggle Control Maps​

// Disable the whole control map (e.g., during UI modes or cutscenes)
Inputs.CM.SetActive<PlayerControls>(false);

// Check the control map's active state
bool isActive = Inputs.CM.IsActive<PlayerControls>();

[Refer to Example]


Installation​

Install via git URL
Add https://github.com/cout-m6o/OxGKit.git?path=Assets/OxGKit/InputSystem/Scripts to Package Manager

Third-party libraries (install manually)

Samples (Package Manager -> Samples)


Module API​


Demo​

InputSystem Demo