在Unity中接入Xbox360手柄
2015-12-19 23:15
726 查看
提要
本文主要介绍了如何在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. |
这里定义了一个 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.htmlXbox 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?)
相关文章推荐
- javascript制作游戏开发碰撞检测的封装代码
- Android游戏开发实践之人物移动地图的平滑滚动处理
- 游戏服务器端开发要点
- tvOS游戏开发系列(SpriteKit)之准备工作(一)
- tvOS游戏开发系列(SpriteKit)之新建tvOS游戏项目(二)
- 开源游戏 “打飞机”
- 开源游戏 “Elvish Bird”
- 开源游戏“2048”IOS移植版
- 游戏开发如何成功
- 【v2.x OGE教程 15】布局相关
- 【v2.x OGE-example 第二节】 实体参数
- 浅析LUA中游戏脚本语言之魔兽世界
- Grant Skinner称HTML5并非游戏的最佳选择
- 简单实用的网游服务器架构
- Android版哆啦A梦连连看游戏源码完整版
- 关于手机(智能机)游戏开发的43条小诀窍
- unity3d游戏开发的编辑应用
- 跟我从零基础学习Unity3D开发--初识U3D
- cocos2dx通过Jni调用Android的Java层代码(下)
- cocos2dx通过Jni调用Android的Java层代码(上)