| name | oxgkit-unity-skill |
| description | Use when developing or reviewing Unity projects that use OxGKit.InputSystem, including the Inputs.CM control-map registry (Unity New Input System IInputActionCollection), the Inputs.IA input-action registry (IInputAction signal dispatchers), Inputs.IA.DriveUpdate loops, custom Binding Composites, and decoupling gameplay/UI from device input via event subscription. |
OxGKit.InputSystem Unity Skill
Purpose
Make the agent behave like an experienced OxGKit.InputSystem user. The module (UPM package com.michaelo.oxgkit.inputsystem) is a thin input-dispatch layer: Control Maps wrap Unity New Input System generated classes, and Input Actions (IInputAction) re-dispatch input as C# events, so gameplay/UI code subscribes to game-level signals and never touches devices or platforms directly. Input Actions can also wrap any other input plugin — they are plain signal dispatchers.
First response rules
- Reply in the user's language; keep code and identifiers in English.
- Start with the conclusion, then implementation details.
- Verify APIs against the installed package (
Library/PackageCache/com.michaelo.oxgkit.inputsystem@* or Assets/OxGKit/InputSystem/Scripts when embedded) and inspect the project's generated control-map classes before writing code. Do not invent APIs or asset names.
- Check the project actually has Unity New Input System enabled (Player Settings > Active Input Handling) when Control Maps are involved.
Install
- UPM git URL:
https://github.com/michael811125/OxGKit.git?path=Assets/OxGKit/InputSystem/Scripts
- Auto dependencies:
com.unity.inputsystem, com.michaelo.oxgkit.loggingsystem.
- Samples (Package Manager > OxGKit.InputSystem > Samples):
InputSystem Demo, AI Agent Skills (this skill).
- Script templates: right-click
Assets/Create/OxGKit/Input System/Template Input Action.cs (Input Interface For Any) and .../New Input System (Extension)/Template Input Binding Composite.cs (For Unity New Input System).
Core API (verified)
using OxGKit.InputSystem;
Inputs.CM.RegisterControlMap<TIInputActionCollection>();
Inputs.CM.GetControlMap<TIInputActionCollection>();
Inputs.CM.SetActive<TIInputActionCollection>(bool active);
Inputs.CM.IsActive<TIInputActionCollection>();
Inputs.IA.RegisterInputAction<TInputAction>();
Inputs.IA.GetInputAction<TInputAction>();
Inputs.IA.DriveUpdate(float dt);
public interface IInputAction
{
void OnCreate();
void OnUpdate(float dt);
void RemoveAllListeners();
}
Usage pattern
Register order matters — Control Maps first, then Input Actions (their OnCreate usually fetches a control map):
using OxGKit.InputSystem;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerAction : IInputAction
{
public event System.Action<Vector2> onMove;
public event System.Action onAttack;
public void OnCreate()
{
var controls = Inputs.CM.GetControlMap<PlayerControls>();
if (controls == null) return;
controls.Player.Move.performed += this._OnMove;
controls.Player.Move.canceled += this._OnMove;
controls.Player.Attack.performed += _ => this.onAttack?.Invoke();
}
public void OnUpdate(float dt) { }
public void RemoveAllListeners()
{
this.onMove = null;
this.onAttack = null;
}
private void _OnMove(InputAction.CallbackContext ctx) => this.onMove?.Invoke(ctx.ReadValue<Vector2>());
}
Inputs.CM.RegisterControlMap<PlayerControls>();
Inputs.IA.RegisterInputAction<PlayerAction>();
private () => Inputs.IA.DriveUpdate(Time.deltaTime);
Inputs.IA.GetInputAction<PlayerAction>().onMove += .OnMove;
Inputs.IA.GetInputAction<PlayerAction>().onMove -= .OnMove;
Enable/disable input during UI modes or cutscenes:
Inputs.CM.SetActive<PlayerControls>(false);
Inputs.CM.GetControlMap<PlayerControls>()?.Player.Disable();
Inputs.CM.GetControlMap<PlayerControls>()?.Player.Enable();
Binding Composites (Unity New Input System)
For composite bindings (e.g., a 2D vector from four keys with custom processing), create one from the template menu; it produces an InputBindingComposite<Vector2>-style class registered via [RuntimeInitializeOnLoadMethod]/InputSystem.RegisterBindingComposite. The demo's MoveInput composite plus PlayerControls.inputactions shows the full setup — read them (Samples~/InputDemo) before authoring composites.
Rules & pitfalls
- Do not register an
IInputAction before the Control Map it reads is registered — GetControlMap returns null and bindings are silently skipped.
- Exactly one runtime owner should call
Inputs.IA.DriveUpdate(dt); forgetting it disables every OnUpdate-based action, calling it from several places double-ticks them.
- Gameplay/feature code subscribes to
IInputAction events only; do not scatter raw InputAction reads through the project.
- Unsubscribe events when a feature exits; call
RemoveAllListeners() (or re-register) on scene/domain transitions to avoid stale delegates.
- Registries are static: registering the same type twice is a no-op (first registration wins) — restart flows should account for that.
Verify
- Compile, enter Play mode, confirm subscribed events fire for keyboard/gamepad, and that
SetActive<T>(false) mutes input.
- If an
OnUpdate-based behavior is dead, first check DriveUpdate is being called each frame.