胖仔

文章 分类 评论
10 6 7

站点介绍

胖仔的个人技术学习、心得、日常的分享站

学习笔记之新输入系统

胖仔配猪 2025-12-27 796 0条评论 Unity学习心得 Unity输入系统

首页 / 正文

// ==============================
// Unity 新输入系统 Input System 完整笔记 + 代码
// 结构:ActionMaps → Actions → ActionProperties
// 包含:Button事件绑定 / Value值获取
// ==============================

/*
一、核心概念

  1. ActionMaps:行为映射图集(分组:Player/UI等)
  2. Actions:行为分类(Jump/Move/Fire等)
  3. ActionProperties:按键类型(Button/Value)

二、使用步骤

  1. 右键 → Input Actions → 创建 PlayerInputActions
  2. 配置:

    • ActionMap: Player
    • Jump → Button → 绑定 Space
    • Move → Value → Vector2 → 绑定 WASD/摇杆
  3. 勾选 Generate C# Class → Apply 自动生成脚本
    */

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerInputController : MonoBehaviour
{

// 自动生成的输入系统类
private PlayerInputActions _inputActions;

private void Awake()
{
    // 生成新输入系统类实例
    _inputActions = new PlayerInputActions();
}

private void OnEnable()
{
    // 启用 ActionMap
    _inputActions.Player.Enable();

    // ==============================
    // Button 类型:事件绑定方式
    // ==============================
    _inputActions.Player.Jump.started += OnJumpStarted;
    _inputActions.Player.Jump.performed += OnJumpPerformed;
    _inputActions.Player.Jump.canceled += OnJumpCanceled;
}

private void OnDisable()
{
    // 注销事件
    _inputActions.Player.Jump.started -= OnJumpStarted;
    _inputActions.Player.Jump.performed -= OnJumpPerformed;
    _inputActions.Player.Jump.canceled -= OnJumpCanceled;

    // 禁用 ActionMap
    _inputActions.Player.Disable();
}

private void Update()
{
    // ==============================
    // Value 类型:值获取方式
    // ==============================
    Vector2 moveInput = _inputActions.Player.Move.ReadValue<Vector2>();
}

// Button 回调
private void OnJumpStarted(InputAction.CallbackContext ctx) => Debug.Log("跳跃按住中");
private void OnJumpPerformed(InputAction.CallbackContext ctx) => Debug.Log("跳跃按下");
private void OnJumpCanceled(InputAction.CallbackContext ctx) => Debug.Log("跳跃松开");

}

// ==============================
// 核心语法总结
// 1. 生成输入类:new PlayerInputActions()
// 2. Button绑定:动作.started/performed/canceled += 方法
// 3. Value获取:ReadValue()
// ==============================

评论(0)

最新评论

  • homepage

    Solid perspective. Modern adult platforms feel very distinct from old-school ones

  • https://masturbationporntubehd.com

    Good perspective. Some 18+ video websites clearly focus on user comfort now

  • https://handjob-teens.com

    Nice read. I’ve seen the same improvements on several 18+ video platforms

  • https://hentai0day.com/videos/33863/otaku-eating-his-school-friend-to-read-manga/

    Good insights here. Presentation definitely impacts how long users stay on adult platforms

  • homepage

    Good article — it actually lines up with what I’ve seen on some newer 18+ video platforms lately

  • webpage

    Thanks for the post. Clean design really separates quality adult platforms from the rest

  • https://gay0day.com

    This article makes sense. Simple layouts really enhance the experience on 18+ platforms

日历

2026年05月

     12
3456789
10111213141516
17181920212223
24252627282930
31      

文章目录