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. 新疆大学(新大)OJ xju 1006: 比赛排名 第二类斯特林数+阶乘

    题目链接:http://acm.xju.edu.cn/JudgeOnline/problem.php?id=1006 第二类斯特林数: 第二类Stirling数实际上是集合的一个拆分,表示将n个不同的 ...

  2. java中三个类别加载器的关系以及各自加载的类的范围

    Java在需要使用类别的时候,才会将类别加载,Java的类别载入是由类别载入器(Class loader)来达到的,预设上,在程序启动之后,主要会有三个类别加载器:Bootstrap Loader.E ...

  3. sublime text3前端常用插件

    安装Package Control 在安装插件之前,需要让sublime安装Package Control.打开Sublime Text的控制台,快捷键ctrl + ~,在控制台中输入以下代码. im ...

  4. swift语言点评五-Function

    一.函数类型 Every function in Swift has a type, consisting of the function’s parameter types and return t ...

  5. canvas图片滚动

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  6. NOIp2018模拟赛三十二

    继续挂成傻逼 成绩:100+0+10(90)=110 A全场一眼题,C没取模挂八十分,然后没特判特殊情况又挂十分 A:[agc009b]tournament(太简单,咕了) B:[ATC2142]Bu ...

  7. apache源码编译安装

    源码安装apche 下载apache的源码包文件 访问http://mirror.bit.edu.cn/apache/httpd/,复制如下gz文件的链接地址,并使用wget下载到本地 wget -P ...

  8. [HAOI2015]树上染色(树形dp)

    [HAOI2015]树上染色 题目描述 有一棵点数为 N 的树,树边有边权.给你一个在 0~ N 之内的正整数 K ,你要在这棵树中选择 K个点,将其染成黑色,并将其他 的N-K个点染成白色 . 将所 ...

  9. 错误解决:error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token

    今天看到一个比较有趣的题目,如下代码,分析输出结果 #include <stdio.h> void num(int &b) { b = 222; return; } int mai ...

  10. VS2008 集成Lua解释器

    1. 登陆官网下载源代码 -> www.lua.org -> get started ->  installing  选择系统类型(这里是Windows的,所下面载 luaDist) ...