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. AndroidStudio EventBus报错解决方法its super classes have no public methods with the @Subscribe

    首先说明,以前我用eventBus的jar包写得项目demo,前几天就写了一个EventBus的实例,这次我没用jar包,直接用gradle引用的,可是demo写完了,报错: its super cl ...

  2. 分库分表中间件Sharding-JDBC

    数据库分库分表从互联网时代开启至今,一直是热门话题.在NoSQL横行的今天,关系型数据库凭借其稳定.查询灵活.兼容等特性,仍被大多数公司作为首选数据库.因此,合理采用分库分表技术应对海量数据和高并发对 ...

  3. 配置 centos apache 的日志文件为每天保存,在home分区

    /usr/local/apache/bin/rotatelogs 这个执行程序会根据安装方式不同的位置也不同,yum安装的话,路径为:/usr/sbin/rotatelogs 改为: ErrorLog ...

  4. Linux重新命名文件夹

    linux 重命名文件和文件夹   linux下重命名文件或文件夹的命令mv既可以重命名,又可以移动文件或文件夹. 例子:将目录A重命名为B mv A B 例子:将/a目录移动到/b下,并重命名为c ...

  5. 题解 UVA12206 【Stammering Aliens】

    终于A了这道题啊(坑啊) 教练说:这道题不能用map吧,复杂度不一个O(nlogn)吗 于是我就一直想不出来,然后看题解代码,一看就是map... 所以我就在想,那复杂度是不是也不是O(nlogn)呢 ...

  6. C语言编译和链接

    编译链接是使用高级语言编程所必须的操作,一个源程序只有经过编译.链接操作以后才可以变成计算机可以理解并执行的二进制可执行文件. 编译是指根据用户写的源程序代码,经过词法和语法分析,将高级语言编写的代码 ...

  7. 成都磨子桥技工学校 / 2016届练习区 0003:jubeeeeeat

    0003:jubeeeeeat 总时间限制:  1000ms 内存限制:  256000kB 描述 众所周知,LZF很喜欢打一个叫Jubeat的游戏.这是个音乐游戏,游戏界面是4×4的方阵,会根据音乐 ...

  8. 生成apk文件遇到的编译问题error: format not a string literal and no format arguments

    编译错误时使用的android-ndk为r9的版本号.报下面错误: "Compile++ thumb : cocosdenshion_static <= SimpleAudioEngi ...

  9. Android-Universal-Image-Loader 的使用说明

    这个图片异步载入并缓存的类已经被非常多开发人员所使用,是最经常使用的几个开源库之中的一个,主流的应用,随便反编译几个火的项目,都能够见到它的身影. 但是有的人并不知道怎样去使用这库怎样进行配置,网上查 ...

  10. RabbitMQ inequivalent arg 'durable' for exchange 'csExchange' in vhost '/': received

    错误:inequivalent arg 'durable' for exchange 'csExchange' in vhost '/': received 使用不同的MQ客户端时,常常会出现以上错误 ...