unity 5.6.1 Oculus手柄输入问题
unity文档中提到 轴的 ID 是5和6,但是测试后发现,ID是6和7,很坑
void Update () {
if (Input.GetKeyDown(KeyCode.JoystickButton0)) {
Debug.Log ("确定");
}
if (Input.GetKeyDown(KeyCode.JoystickButton1)) {
Debug.Log ("返回");
}
Debug.Log (Input.GetAxis("OculusRL"));
Debug.Log (Input.GetAxis("OculusUD"));
}
附:https://ritchielozada.com/2016/01/16/part-11-using-an-xbox-one-controller-with-unity-on-windows-10/
Part 11: Using an Xbox One Controller with Unity on Windows 10
This post follows: Part 10: Creating the CameraRig Control Script
Unity supports several of input devices that simplify into mouse, joystick or keyboard behavior, it gets a bit challenging as the same input device will have varying input configurations across devices (PC, Mobile) and platforms (Windows 10, previous Windows, Linux, Mac, iOS, Android etc.)
There are several dual-stick/controllers available across platforms — unfortunately we are still not at the stage of having a single controller solution. I use the Xbox One Controller for PC and Xbox One, the NVidia Shield, Nexus and Fire Controllers over Bluetooth for Android Apps and when I get the time to test it out the SteelSeries Nimbus for iOS. The programming concept is very similar across the controllers, the key differences are with button and axis id assignments. I’ll be using the Xbox One controller as the development reference – might as well use the same controller platform that is included with the Oculus Rift package.
The Xbox One controller has slight changes in the button naming convention compared to the Xbox 360 version (which shares setup and usage conventions with other controllers since it has been out for quite some time.) The controller layout is the same but the Xbox 360 Back and Start buttons are now referred to as View and Menu buttons respectively.
There are several guides, blogs and sites that cover the Xbox 360 controller setup for Unity. The setup and programming concept remains the same, we have to be aware that the axis setup actually vary across platforms and in the case of Windows 10 vs. previous versions of Windows — we need to make sure that the axis assignments are updated as there is a difference in the configuration.
http://wiki.unity3d.com/index.php?title=Xbox360Controller
The Xbox One Controller is automatically recognized by Windows on a wired connection over USB or through a wireless connection using the Xbox Wireless Adapter for Windows
This is the setup I have for the Xbox One Controller on Windows 10:
(Updated November 25, 2016 to include return values and DPAD Axis Correction)

To use the controller, we go back to the InputManager — similar to the setup covered in Part 9: Configure Input Settings for Camera Controls
Make sure to use the configuration for Buttons and Joystick Axes for each corresponding entry. There are 10 buttons and 8 axes to configure.
Button Configuration
Joystick Axis Setup
We’ll be using “Horizontal”, “Vertical”, “HorizontalTurn”, “VerticalTurn” as the entry names to match the pre-existing keyboard setup for the Left and Right Sticks.
After completing the InputManager to include the Xbox One Controller setup, running the scene should automatically work with the controller since we are using the same input names for the dual sticks.
To aid in testing our setup, create another text object in the canvas to display the controller status.
Edit CameraRig.cs, add a public UnityEngine.UI.Text entry “DebugText” so we can access the new Text object on the Canvas, Uncheck the “Raycast Target” so it does not block the Gaze. Include the following method in the CameraRig.cs script and call it from the Update() method, this will display the status of the controller buttons and axes at runtime.
void ControllerCheck()
{
float ltaxis = Input.GetAxis("XboxLeftTrigger");
float rtaxis = Input.GetAxis("XboxRightTrigger");
float dhaxis = Input.GetAxis("XboxDpadHorizontal");
float dvaxis = Input.GetAxis("XboxDpadVertical"); bool xbox_a = Input.GetButton("XboxA");
bool xbox_b = Input.GetButton("XboxB");
bool xbox_x = Input.GetButton("XboxX");
bool xbox_y = Input.GetButton("XboxY");
bool xbox_lb = Input.GetButton("XboxLB");
bool xbox_rb = Input.GetButton("XboxRB");
bool xbox_ls = Input.GetButton("XboxLS");
bool xbox_rs = Input.GetButton("XboxRS");
bool xbox_view = Input.GetButton("XboxView");
bool xbox_menu = Input.GetButton("XboxMenu"); DebugText.text =
string.Format(
"Horizontal: {14:0.000} Vertical: {15:0.000}\n" +
"HorizontalTurn: {16:0.000} VerticalTurn: {17:0.000}\n" +
"LTrigger: {0:0.000} RTrigger: {1:0.000}\n" +
"A: {2} B: {3} X: {4} Y:{5}\n" +
"LB: {6} RB: {7} LS: {8} RS:{9}\n" +
"View: {10} Menu: {11}\n" +
"Dpad-H: {12:0.000} Dpad-V: {13:0.000}\n",
ltaxis, rtaxis,
xbox_a, xbox_b, xbox_x, xbox_y,
xbox_lb, xbox_rb, xbox_ls, xbox_rs,
xbox_view, xbox_menu,
dhaxis, dvaxis,
hAxis, vAxis,
htAxis, vtAxis);
} void Update()
{
// Camera Rig Movement Control
hAxis = Input.GetAxis("Horizontal");
vAxis = Input.GetAxis("Vertical");
aAxis = Input.GetAxis("Altitude");
htAxis = Input.GetAxis("HorizontalTurn");
vtAxis = Input.GetAxis("VerticalTurn"); ControllerCheck(); ...
...
}
unity 5.6.1 Oculus手柄输入问题的更多相关文章
- Unity 为NGUI增加体感输入方式
背景 NGUI在处理UI和输入方面确实做的不错,但是现在的问题是公司引入体感之后,是通过手的位置来实现按钮的点击操作,前提我不想改变原先设计好的NGUI界面和机制,怎么破? NGUI的输入底层机制 N ...
- 【Unity】7.4 游戏外设输入
分类:Unity.C#.VS2015 创建日期:2016-04-21 一.简介 Unity可以处理摇杆.游戏手柄.方向盘等标准游戏外设的输入,使用的方法如下图所示: 虚拟按键需要在输入管理器中配置,把 ...
- 【Unity】7.5 移动设备输入
分类:Unity.C#.VS2015 创建日期:2016-04-21 一.简介 在iOS和Android系统中,操作都是通过触摸来完成的.Input类中对触摸操作的方法或变量如下图所示: 通过GetT ...
- 转:Oculus Unity Development Guide开发指南(2015-7-21更新)
http://forum.exceedu.com/forum/forum.php?mod=viewthread&tid=34175 Oculus Unity Development Guide ...
- unity零基础开始学习做游戏(三)鼠标输入,来个虚拟摇杆怎么样?
-------小基原创,转载请给我一个面子 现在移动游戏越来越火,大家都拿手机平板玩游戏,没有键盘和手柄输入,所以就不得不看看虚拟摇杆怎么搞?(小基对于没有实体反馈不是很喜欢呢) 首先要清楚,鼠标操作 ...
- 在Unity中接入Xbox360手柄
提要 本文主要介绍了怎样在Unity中接入Xbox360的手柄. 当我们调Input.GetAxis("Horizontal"),我们调了什么 Unity中全部关于输入的设置都在E ...
- Unity的HTC VIVE SDK研究(手柄按键功能的研究,比较详细)
http://blog.csdn.net/ystistheking/article/details/51553237 想交流的朋友我们可以微博互粉,我的微博黑石铸造厂厂长 ,缺粉丝啊 .....求粉求 ...
- 在 Unity 中基于 Oculus DK1 的开发
开发环境: Windows 10 专业版 64位(GeForce GTX 970M,驱动版本:378.72) 大朋助手 1.3.2.10,大朋E2(http://www.deepoon.com/dap ...
- 介绍用C#和VS2015开发基于Unity架构的2D、3D游戏的技术
[Unity]13.3 Realtime GI示例 摘要: 分类:Unity.C#.VS2015 创建日期:2016-04-19 一.简介 使用简单示例而不是使用实际示例的好处是能让你快速理解光照贴图 ...
随机推荐
- Caffe 激励层(Activation)分析
Caffe_Activation 一般来说,激励层的输入输出尺寸一致,为非线性函数,完成非线性映射,从而能够拟合更为复杂的函数表达式激励层都派生于NeuronLayer: class XXXlayer ...
- 用Maven创建第一个web项目Struts2项目
一.创建一个web项目 参考前面文章,项目名:maven-struts-demo. 二.配置pom.xml文件添加struts2依赖 <project xmlns="http://ma ...
- 3dsMax插件开发环境配置
Windows 7 X64.3dsmax 2014 64位.3dsmax 2014 sdk.visual studio 2010: 软件下载:http://www.xy3dsmax.com/xiaza ...
- (转)Java 虚拟机体系结构
来源:http://hxraid.iteye.com/blog/676235 众所周知,Java源代码被编译器编译成class文件.而并不是底层操作系统可以直接执行的二进制指令(比如Windows O ...
- [CTSC2012]熟悉的文章(广义后缀自动机+二分答案+单调队列优化DP)
我们对作文库建出广义后缀自动机.考虑用\(SAM\)处理出来一个数组\(mx[i]\),表示从作文的第\(i\)个位置向左最远在作文库中出现的子串的长度.这个东西可以在\(SAM\)上跑\(trans ...
- BZOJ 4896 [Thusc2016]补退选 (Trie树维护vector)
题目大意:略 这竟然是$thusc$的题... 先把询问里加入的串全拎出来,建出$Trie$树,$Trie$里每个节点都开一个$vector$记录操作标号,再记录操作数量$sum$ 然后瞎**搞搞就行 ...
- LINUX 中 python 版本升级
首先下载源tar包 可利用linux自带下载工具wget下载,如下所示: 1 # wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tg ...
- [terry笔记]11gR2_dataguard_保护模式切换
保护模式切换 Maximum protection/availability/ performance 1. 首先查看当前的保护模式 SQL> select protection_mode,pr ...
- NYIST 1108 最低的惩罚
最低的惩罚 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 那么现在问题就来了... 给你N(1=<N<=15)个任务,每个任务有一个截止完成时间t(1= ...
- 低价购买 洛谷1108 codevs4748 dp
首先,,我相信第一问是可以做出来的,,,做不出来自行面壁思过,,, 第二问,我们可以发现,如果f[i]为1时应该将其g[i]初始化为1,当初就是因为这个wa了一个世纪,之后先考虑不需要判重时的情况,如 ...