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.

Xbox One Wireless Controller

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手柄输入问题的更多相关文章

  1. Unity 为NGUI增加体感输入方式

    背景 NGUI在处理UI和输入方面确实做的不错,但是现在的问题是公司引入体感之后,是通过手的位置来实现按钮的点击操作,前提我不想改变原先设计好的NGUI界面和机制,怎么破? NGUI的输入底层机制 N ...

  2. 【Unity】7.4 游戏外设输入

    分类:Unity.C#.VS2015 创建日期:2016-04-21 一.简介 Unity可以处理摇杆.游戏手柄.方向盘等标准游戏外设的输入,使用的方法如下图所示: 虚拟按键需要在输入管理器中配置,把 ...

  3. 【Unity】7.5 移动设备输入

    分类:Unity.C#.VS2015 创建日期:2016-04-21 一.简介 在iOS和Android系统中,操作都是通过触摸来完成的.Input类中对触摸操作的方法或变量如下图所示: 通过GetT ...

  4. 转:Oculus Unity Development Guide开发指南(2015-7-21更新)

    http://forum.exceedu.com/forum/forum.php?mod=viewthread&tid=34175 Oculus Unity Development Guide ...

  5. unity零基础开始学习做游戏(三)鼠标输入,来个虚拟摇杆怎么样?

    -------小基原创,转载请给我一个面子 现在移动游戏越来越火,大家都拿手机平板玩游戏,没有键盘和手柄输入,所以就不得不看看虚拟摇杆怎么搞?(小基对于没有实体反馈不是很喜欢呢) 首先要清楚,鼠标操作 ...

  6. 在Unity中接入Xbox360手柄

    提要 本文主要介绍了怎样在Unity中接入Xbox360的手柄. 当我们调Input.GetAxis("Horizontal"),我们调了什么 Unity中全部关于输入的设置都在E ...

  7. Unity的HTC VIVE SDK研究(手柄按键功能的研究,比较详细)

    http://blog.csdn.net/ystistheking/article/details/51553237 想交流的朋友我们可以微博互粉,我的微博黑石铸造厂厂长 ,缺粉丝啊 .....求粉求 ...

  8. 在 Unity 中基于 Oculus DK1 的开发

    开发环境: Windows 10 专业版 64位(GeForce GTX 970M,驱动版本:378.72) 大朋助手 1.3.2.10,大朋E2(http://www.deepoon.com/dap ...

  9. 介绍用C#和VS2015开发基于Unity架构的2D、3D游戏的技术

    [Unity]13.3 Realtime GI示例 摘要: 分类:Unity.C#.VS2015 创建日期:2016-04-19 一.简介 使用简单示例而不是使用实际示例的好处是能让你快速理解光照贴图 ...

随机推荐

  1. jQuery学习(一)——jQuery入门

    1.jQuery基础 Jquery它是一个库(框架),要想使用它,必须先引入! jquery-1.8.3.js:一般用于学习阶段. jquery-1.8.3.min.js:用于项目使用阶段 官网下载后 ...

  2. Windows上快速编译caffe CPU版本

    windows上快速安装配置Caffe的 cpu_only环境. 一:安装环境: 1.windows10: 2.Visual Studio2013: 3.Caffe版本:http://github.c ...

  3. Html表单提交到Servlet输出到页面乱码

    Html使用的编码是UTF-8编码显示页面,之后使用form表单提交字段到Servlet中,Servlet将利用getParamer方法获得form提交的字段,之后通过Respone中的writer将 ...

  4. HDU 3342 Legal or Not【拓扑排序】

    题意:给出n,m,人的编号为 0到n-1,再给出m个关系,问能不能够进行拓扑排序 #include<iostream> #include<cstdio> #include< ...

  5. tigergao

    互联网从业 6 年.前码农&DBA,现运维&电商创业者,也在做自媒体.终生学习者. 运营微信公众号:高哥咋么看 感兴趣的朋友们可以订阅.

  6. NOIp2018模拟赛三十八

    爆〇啦~ A题C题不会写,B题头铁写正解: 随手过拍很自信,出分一看挂成零. 若要问我为什么?gtmdsubtask! 神tm就一个subtask要么0分要么100,结果我预处理少了一点当场去世 难受 ...

  7. 获取mapper

    static UpdateLogMapper updateLogMapper = (UpdateLogMapper)SpringContextUtil.getBean(UpdateLogMapper. ...

  8. Linux用户与用户组

    Linux用户与用户组 Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统. 用户的账号一方面可以帮助系统管 ...

  9. OpenStack-API开发

    介绍两种OpenStack-API(Java版)--jcoulds && openstack4j Jclouds 1.介绍 jclouds -该API提供云计算环境的可移植抽象层以及云 ...

  10. Android 取得 ListView中每个Item项目的值

    首先我们须要创建 ListView .这里假定我们已经创建好了而且使用SimpleAdapter设置好了adapter数据,看一下我们的adapter ArrayList<HashMap< ...