Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

unity-inputUnity input 搜索

Agent Skill

unity-input 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

312

周安装

13

GitHub Stars

14

下载量

104
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:unity-input(Unity input 搜索)
来源仓库:https://github.com/nice-wolf-studio/unity-claude-skills
仓库路径:skills/unity-input
安装命令:
npx skills add https://github.com/nice-wolf-studio/unity-claude-skills --skill unity-input
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/nice-wolf-studio/unity-claude-skills --skill unity-input

简介

用于 Unity Input 相关信息的查找、检索和筛选,适合在 Codex、Claude、Cursor、Gemini CLI 中快速定位输入处理资料。

  • 适用于需要根据关键词或任务场景定位候选结果时使用。
  • 通过 npx skills add 命令从 GitHub 仓库安装并使用。
  • 安装前建议确认权限范围和维护状态,避免触发不必要的联网或文件操作。
  • unity-input 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Unity Input System

Input System Overview: New vs Legacy

Unity provides two input systems:

FeatureNew Input System (Recommended)Legacy Input Manager
Packagecom.unity.inputsystem (v1.19.0 for Unity 6.3)Built-in (UnityEngine.Input)
ArchitectureAction-based, event-drivenPolling-based
Device SupportGamepad, keyboard, mouse, touch, XR, customKeyboard, mouse, joystick
MultiplayerBuilt-in local multiplayer via PlayerInputManual implementation
RebindingRuntime rebinding supportNot supported
Cross-platformControl Schemes per device typeManual per-platform code

The new Input System is a package installed via Package Manager. It replaces the legacy Input.GetKey/Input.GetAxis API with an action-based model that separates input purpose from device controls.

Namespace: UnityEngine.InputSystem

Quick Start Setup

1. Install the Package

Install via Window > Package Manager > Unity Registry > Input System.

2. Create Default Project-Wide Actions

Go to Edit > Project Settings > Input System Package > Input Actions and click "Create and assign a default project-wide Action Asset".

This creates default Action Maps:

  • Player: Move, Look, Jump, Attack
  • UI: Navigate, Submit, Cancel

Each action includes bindings for keyboard, gamepad, XR controllers, and touchscreen.

3. Read Input in a Script

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    InputAction moveAction;
    InputAction jumpAction;

    void Start()
    {
        moveAction = InputSystem.actions.FindAction("Move");
        jumpAction = InputSystem.actions.FindAction("Jump");
    }

    void Update()
    {
        Vector2 moveValue = moveAction.ReadValue<Vector2>();
        transform.Translate(new Vector3(moveValue.x, 0, moveValue.y) * Time.deltaTime * 5f);

        if (jumpAction.IsPressed())
        {
            // Jump logic
        }
    }
}

When multiple actions share names across maps, specify both: "Player/Move".

Input Actions and Action Maps

Core Concepts

  • InputAction: A named action that returns control values or triggers callbacks
  • InputActionMap: A named collection of related actions (e.g., "Player", "UI", "Vehicle")
  • InputBinding: Relationship between an action and a device control
  • InputSystem.actions: Reference to project-wide actions

Creating Actions

Method 1 — Input Actions Editor (Recommended): Configure via Project Settings > Input System Package.

Method 2 — MonoBehaviour fields: Declare InputAction fields directly in scripts (configurable in Inspector).

Method 3 — Code:

var moveAction = new InputAction("Move", InputActionType.Value);
moveAction.AddCompositeBinding("Dpad")
    .With("Up", "<Keyboard>/w").With("Down", "<Keyboard>/s")
    .With("Left", "<Keyboard>/a").With("Right", "<Keyboard>/d");
moveAction.Enable();

Method 4 — JSON: var map = InputActionMap.FromJson(jsonString);

Action Lifecycle

Actions begin disabled. You must call .Enable() before they respond to input. You cannot modify bindings while enabled; call .Disable() first.

Input Action Assets (.inputactions)

These are JSON files storing actions, bindings, and control schemes. Create via Assets > Create > Input Actions.

Auto-generated C# class: Enable "Generate C# Class" in the asset's importer to get type-safe access:

public class MyPlayerScript : MonoBehaviour, IGameplayActions
{
    MyPlayerControls controls;

    public void OnEnable()
    {
        controls = new MyPlayerControls();
        controls.gameplay.SetCallbacks(this);
        controls.gameplay.Enable();
    }

    public void OnDisable()
    {
        controls.gameplay.Disable();
    }

    public void OnMove(InputAction.CallbackContext context)
    {
        Vector2 move = context.ReadValue<Vector2>();
        // Handle movement
    }
}

PlayerInput Component

The PlayerInput component maps Input Actions to script methods and handles local multiplayer with device filtering and screen-splitting.

Setup

  1. Add PlayerInput component to your player GameObject
  2. Assign your Action Asset to the Actions field
  3. Select a Default Action Map
  4. Choose a Behavior notification type

Behavior Options

BehaviorMechanismBest For
Send MessagesGameObject.SendMessage()Simple prototyping
Broadcast MessagesBroadcastMessage() down hierarchyComponent hierarchies
Invoke Unity EventsInspector-configured event routingDesigner-friendly wiring
Invoke C# EventsonActionTriggered, onDeviceLost, onDeviceRegainedProgrammer control

Send Messages Pattern

public class PlayerActions : MonoBehaviour
{
    public void OnJump()
    {
        // Called when Jump action triggers (no parameters)
    }

    public void OnMove(InputValue value)
    {
        Vector2 v = value.Get<Vector2>();
        // InputValue is only valid during this callback
    }
}

Unity Events Pattern

public void OnFire(InputAction.CallbackContext context)
{
    if (context.performed)
    {
        // Fire logic
    }
}

Managing PlayerInput

PlayerInput playerInput = GetComponent<PlayerInput>();
playerInput.DeactivateInput();                      // Disable all input
playerInput.ActivateInput();                         // Re-enable with default map
playerInput.SwitchCurrentActionMap("Vehicle");       // Switch action map

Reading Input in Code

Polling (in Update)

// 2D movement axis
Vector2 move = moveAction.ReadValue<Vector2>();

// Button state
if (jumpAction.IsPressed()) { /* held down */ }
if (jumpAction.WasPressedThisFrame()) { /* just pressed */ }
if (jumpAction.WasReleasedThisFrame()) { /* just released */ }

Callbacks (Event-Driven)

void OnEnable()
{
    fireAction.started += OnFireStarted;
    fireAction.performed += OnFirePerformed;
    fireAction.canceled += OnFireCanceled;
    fireAction.Enable();
}

void OnDisable()
{
    fireAction.started -= OnFireStarted;
    fireAction.performed -= OnFirePerformed;
    fireAction.canceled -= OnFireCanceled;
    fireAction.Disable();
}

void OnFireStarted(InputAction.CallbackContext ctx) { /* Input began */ }
void OnFirePerformed(InputAction.CallbackContext ctx) { /* Completed */ }
void OnFireCanceled(InputAction.CallbackContext ctx) { /* Interrupted */ }

Gamepad / Keyboard / Mouse / Touch

Gamepad

using UnityEngine.InputSystem;

// Current gamepad (null if none connected)
var gp = Gamepad.current;
if (gp == null) return;

Vector2 leftStick = gp.leftStick.ReadValue();
bool southPressed = gp.buttonSouth.isPressed;

// Access by enum
gp[GamepadButton.LeftShoulder].isPressed;
gp[GamepadButton.Y].isPressed;          // Xbox style
gp[GamepadButton.Triangle].isPressed;   // PlayStation style

// Rumble / Haptics
gp.SetMotorSpeeds(0.25f, 0.75f); // low-frequency, high-frequency
gp.ResetHaptics();

// Global haptics control
InputSystem.PauseHaptics();
InputSystem.ResumeHaptics();
InputSystem.ResetHaptics();

Supported gamepads: DualShock 3/4, DualSense, Xbox (XInput/Bluetooth), Switch Pro. Generic HID gamepads appear as generic joysticks, not Gamepad devices.

Keyboard and Mouse

var kb = Keyboard.current;
if (kb.spaceKey.wasPressedThisFrame) { /* space pressed */ }

var mouse = Mouse.current;
Vector2 mousePos = mouse.position.ReadValue();
float scroll = mouse.scroll.ReadValue().y;
bool leftClick = mouse.leftButton.isPressed;

Touch

Two API levels:

Low-level — Touchscreen device:

var ts = Touchscreen.current;
if (ts.primaryTouch.press.isPressed)
{
    Vector2 pos = ts.primaryTouch.position.ReadValue();
}

High-level — EnhancedTouch API:

using UnityEngine.InputSystem.EnhancedTouch;

void OnEnable() => EnhancedTouchSupport.Enable();
void OnDisable() => EnhancedTouchSupport.Disable();

void Update()
{
    foreach (var touch in Touch.activeTouches)
    {
        Debug.Log($"{touch.touchId}: {touch.screenPosition}, {touch.phase}");
    }
}

Touch phases: Began, Moved, Stationary, Ended, Cancelled.

Multi-touch with Actions: Bind <Touchscreen>/touch*/press and set action type to PassThrough to receive callbacks per touch.

Touch simulation: Enable via TouchSimulation.Enable() to simulate touch from mouse/pen during development.

Device Discovery

// Monitor device connections
InputSystem.onDeviceChange += (device, change) =>
{
    if (change == InputDeviceChange.Added)
        Debug.Log($"Device connected: {device.displayName}");
};

Interactions and Processors

Interactions define input patterns that drive action phases.

Interaction Phases

PhaseMeaning
WaitingAwaiting input
StartedInput received, not yet complete
PerformedInteraction complete — primary response trigger
CanceledInteraction interrupted

Built-in Interactions

InteractionDescriptionKey Parameters
DefaultAuto-applied; behavior varies by action type
PressExplicit button press behaviorpressPoint, behavior (PressOnly/ReleaseOnly/PressAndRelease)
HoldSustained press for minimum durationduration, pressPoint
TapQuick press-and-releaseduration, pressPoint
SlowTapHold then releaseduration, pressPoint
MultiTapRepeated tap sequencestapTime, tapDelay, tapCount, pressPoint

Adding Interactions via Code

var action = new InputAction("fire");
action.AddBinding("<Gamepad>/buttonSouth")
    .WithInteractions("tap(duration=0.8)");

Tap vs Hold Example (Fire vs Charge)

var fireAction = new InputAction("fire");
fireAction.AddBinding("<Gamepad>/buttonSouth").WithInteractions("tap,slowTap");
fireAction.started += ctx => { if (ctx.interaction is SlowTapInteraction) ShowChargingUI(); };
fireAction.performed += ctx => {
    if (ctx.interaction is SlowTapInteraction) ChargedFire(); else Fire();
};
fireAction.canceled += _ => HideChargingUI();
fireAction.Enable();

Custom Interaction

Implement IInputInteraction, then register: InputSystem.RegisterInteraction<T>(). See references/input-system-api.md for full example.

Common Patterns

Action Map Switching (e.g., Gameplay vs UI)

public class GameStateManager : MonoBehaviour
{
    PlayerInput playerInput;

    void Start() => playerInput = GetComponent<PlayerInput>();

    public void EnterMenu() => playerInput.SwitchCurrentActionMap("UI");
    public void ExitMenu() => playerInput.SwitchCurrentActionMap("Player");
}

Runtime Rebinding

var rebindOp = action.PerformInteractiveRebinding()
    .WithControlsExcluding("Mouse")
    .OnMatchWaitForAnother(0.1f)
    .OnComplete(op =>
    {
        Debug.Log($"Rebound to: {op.action.bindings[0].effectivePath}");
        op.Dispose();
    })
    .Start();

Multiple Bindings for Same Action (WASD + Arrows)

var moveAction = new InputAction("Move", InputActionType.Value);
moveAction.AddCompositeBinding("2DVector")
    .With("Up", "<Keyboard>/w").With("Down", "<Keyboard>/s")
    .With("Left", "<Keyboard>/a").With("Right", "<Keyboard>/d");
moveAction.AddCompositeBinding("2DVector")
    .With("Up", "<Keyboard>/upArrow").With("Down", "<Keyboard>/downArrow")
    .With("Left", "<Keyboard>/leftArrow").With("Right", "<Keyboard>/rightArrow");

Anti-Patterns

Anti-PatternProblemCorrect Approach
Using Input.GetKey() (legacy)Not compatible with new Input System; no rebinding, no multi-deviceUse InputAction with bindings
Reading actions without .Enable()Actions start disabled and return no valuesAlways call action.Enable() in OnEnable()
Forgetting .Disable() on cleanupMemory leaks and ghost callbacksCall action.Disable() in OnDisable()
Modifying bindings while action is enabledThrows exceptionCall .Disable() before modifying, then .Enable()
Hardcoding device paths in gameplay codeBreaks cross-platform supportUse Actions + Control Schemes instead
Using InputValue outside its callbackValue is only valid during the callback frameCopy the value to a field immediately
Accessing Gamepad.current without null checkCrashes if no gamepad connectedAlways check if (Gamepad.current == null) return;
Not unsubscribing from action callbacksCauses errors on scene reloadUnsubscribe in OnDisable()
Using SendMessages behavior in productionPerformance overhead from reflectionUse Invoke Unity Events or Invoke C# Events
Polling EnhancedTouch without enabling itReturns empty collectionsCall EnhancedTouchSupport.Enable() first

Key API Quick Reference

APIPurpose
InputSystem.actionsProject-wide actions
InputSystem.actions.FindAction("name")Find action by name
action.ReadValue<T>()Read current value
action.IsPressed()Button held check
action.WasPressedThisFrame()Button just pressed
action.WasReleasedThisFrame()Button just released
action.Enable() / action.Disable()Activate/deactivate
action.started / performed / canceledCallback events
action.AddBinding("path")Add binding in code
action.AddCompositeBinding("type")Add composite (Dpad, 2DVector)
.WithInteractions("tap(duration=0.5)")Add interaction to binding
Gamepad.currentCurrent gamepad reference
Keyboard.current / Mouse.currentCurrent keyboard/mouse
Touchscreen.currentCurrent touchscreen
EnhancedTouchSupport.Enable()Enable enhanced touch API
Touch.activeTouchesAll active touches (enhanced)
InputSystem.onDeviceChangeDevice connection events
PlayerInput.SwitchCurrentActionMap()Change active action map
action.PerformInteractiveRebinding()Start runtime rebinding

Related Skills

  • unity-scripting — MonoBehaviour lifecycle, C# patterns
  • unity-ui — UI Toolkit input integration, InputSystemUIInputModule
  • unity-xr — XR controller input, tracked devices

Additional Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.05%
按下载量换算36

Claude

31.86%
按下载量换算33

Cursor

18.21%
按下载量换算19

Gemini CLI

10.09%
按下载量换算10

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills