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 一.简介 使用简单示例而不是使用实际示例的好处是能让你快速理解光照贴图 ...
随机推荐
- 【转载】犀利的 oracle 注入技术
介绍一个在web上通过oracle注入直接取得主机cmdshell的方法. 以下的演示都是在web上的sql plus执行的,在web注入时 把select SYS.DBMS_EXPORT_EXTEN ...
- SpringBoot学习笔记(15)----SpringBoot使用Druid
直接访问Druid官网wiki,有详细教程,地址如下: SpringBoot支持Druid地址:https://github.com/alibaba/druid/tree/master/druid-s ...
- Springboot设置跨域的三种方式
方式一(精细配置) 在需要跨域的整个Controller或者单个方法上添加@CrossOrigin注解 方式二(全局配置) @Configuration public class WebMvcConf ...
- Spark脚本调用
Spark提供了多个脚本来作为程序的入口,其中最常用的是交互脚本 spark-shell, pyspark,还有spark sql的客户端spark-sql. 这些脚本最后都会归结到对SparkSub ...
- [LOJ2422]【NOIP2015】斗地主
大名鼎鼎的NOIP2015D1T3 题意: 由于一些众所周知的原因,没有完整题面…… 给你一副斗地主的手牌(牌数<=23),问最少要几次能出完: 包含双王,没有癞子,连对要三连对以上,可以直接出 ...
- POJ-2752 Seek the Name, Seek the Fame 字符串问题 KMP算法 求前后缀串相同数木
题目链接:https://cn.vjudge.net/problem/POJ-2752 题意 给一个字符串,求前缀串跟后缀串相同的前缀串的个数 例:alala 输出:a, ala, alala 思路 ...
- 通过nodeSelector配置项实现pod部署至指定node
Node节点添加标签 [root@node1 work]# kubectl label nodes node1 node=master --overwrite node/node1 labeled [ ...
- 改造vue-quill-editor: 结合element-ui上传图片到服务器
前排提示:现在可以直接使用封装好的插件vue-quill-editor-upload 需求概述 vue-quill-editor是我们再使用vue框架的时候常用的一个富文本编辑器,在进行富文本编辑的时 ...
- [luogu] P4514 上帝造题的七分钟 (树状数组,二维差分)
P4514 上帝造题的七分钟 题目背景 裸体就意味着身体. 题目描述 "第一分钟,X说,要有矩阵,于是便有了一个里面写满了0的n×m矩阵. 第二分钟,L说,要能修改,于是便有了将左上角为(a ...
- MySQL 一台主机多实例root登录问题
假设在一台机子上起多个MySQL实例. 比方port号为 3306. 3307. 3308 登录时候要选择不同的 mysql.sock文件 mysql -uroot -p123456 这一句 登录的是 ...