提要

本文主要介绍了怎样在Unity中接入Xbox360的手柄。

当我们调Input.GetAxis("Horizontal"),我们调了什么

Unity中全部关于输入的设置都在Edit -> Project Setting -> Input里面,点开之后,Inspector面板中就会显示当前的输入设置。

几个重要选项的含义有:

Gravity How fast will the input recenter. Only used when the Type is key / mouse button.
Dead Any positive or negative values that are less than this number will register as zero. Useful for joysticks.
Sensitivity For keyboard input, a larger value will result in faster response time. A lower value will be more smooth. For Mouse delta the value will scale the actual mouse delta.
Snap If enabled, the axis value will be immediately reset to zero after it receives opposite inputs. Only used when the Type is key / mouse button.
Invert If enabled, the positive buttons will send negative values to the axis, and vice versa.
Type Use Key / Mouse Button for any kind of buttons, Mouse Movement for mouse delta and scrollwheels, Joystick Axis for analog joystick axes and Window Movement for when the user shakes the window.

上图中,定义了键盘上的a键,d键。小键盘上的左和右控制了 "Horizontal" 的输入。并且实际情况中直接插上360的手柄,通过左边的摇杆, Input.GetAxis("Horizontal")也能够获得输入值,原因是后面还定义了一个 "Horizontal" 的输入。

这里定义了一个 Joystick Axis类型的输入,输入的轴是X。 从全部手柄获取输入。

由于有了这个,Input.GetAxis("Horizontal")就能够直接获取手柄的值了。

接下来看怎么扩展到手柄的按键和其它的摇杆。

扩展到手柄的按键和其它的摇杆

首先看一下手柄按键 的分布图。

有了这个就能够自己定义手柄的输入了。

比方要 通过 Input.GetButtonDown("Action"); 来判定是否攻击,关联的是手柄上的A键, 我们仅仅须要例如以下图设置

再比方右边的摇杆,横向是这样

纵向是这种

取值的话是这样

Input.GetAxis("RightHorizontal"))
Input.GetAxis("RightVertical"))

其它的按键或者摇杆用相同的方式设置就能够了。

參考

Input Manager - http://docs.unity3d.com/Manual/class-InputManager.html

Xbox 360 Joystick Controller +  - Unity http://bobstudios-en.blogspot.com/2012/09/xbox-360-joystick-controller-unity.html

附录:sony ps4 joystick map

Buttons
Square = joystick button 0
X = joystick button 1
Circle = joystick button 2
Triangle= joystick button 3
L1 = joystick button 4
R1 = joystick button 5
L2 = joystick button 6
R2 = joystick button 7
Share = joystick button 8
Options = joystick button 9
L3 = joystick button 10
R3 = joystick button 11
PS = joystick button 12
PadPress= joystick button 13

Axes:
LeftStickX = X-Axis
LeftStickY = Y-Axis (Inverted?)
RightStickX = 3rd Axis
RightStickY = 4th Axis (Inverted?

)
L2 = 5th Axis (-1.0f to 1.0f range, unpressed is -1.0f)
R2 = 6th Axis (-1.0f to 1.0f range, unpressed is -1.0f)
DPadX = 7th Axis
DPadY = 8th Axis (Inverted?)

最新文章

  1. jquery的offset().top 和position().top 详解 和如何用js实现
  2. JDom2的Xpath使用
  3. c语言warning总结
  4. test dword ptr [eax],eax ; probe page. visual studio
  5. (九)串行口方式0 拓展并行输入端口 74LS165 芯片
  6. nginx的Location的总结以及rewrite规则的总结
  7. 一个App的界面设计流程是怎么产生的
  8. polya计数定理在ACM-icpc中的应用
  9. React Native 弹性布局FlexBox
  10. oracle 常用语句
  11. [iOS 开发]UITableView第一行显示不完全
  12. static \ const \ volatile 的含义
  13. EffectiveC#5--始终提供ToString()
  14. ASF (0) - ASF Java 项目总览
  15. python黑魔法之metaclass
  16. Django入门实战【3步曲】
  17. .net Core+Dapper MySQL增删改查
  18. 利用反射编写私有 Private 方法的单元测试
  19. myeclise 安装
  20. doc窗口 输入命令net start mysql 服务名无效

热门文章

  1. 20面向对象三特征 之继承 方法重写 super
  2. window10换系统为windows7
  3. JAVA基础——对象流
  4. PyTorch: 序列到序列模型(Seq2Seq)实现机器翻译实战
  5. Oracle 数据库实例启动关闭过程
  6. MySQL 快速入门教程
  7. 77-CCI,Commodity Channel Index,商品通道指标.(2015.7.1)
  8. 杭电 5363 求集合的非空子集中key的数量
  9. sort cmp函数的写法 (特判排序 二级排序)
  10. Critical Links-UVa796(无向图求桥)