位置: 编程技术 - 正文

Unity3D值Input Manager

编辑:rootadmin

推荐整理分享Unity3D值Input Manager,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

转载自: supports keyboard, joystick and gamepad input.

Unity支持,键盘,操纵杆和游戏手柄输入。

Virtual axes and buttons can be created in the Input Manager, and end users can configure Keyboard input in a nice screen configuration dialog.

在输入管理器可以创建虚拟轴和按钮,并终端用户可以在屏幕配置对话框配置键盘输入。

You can setup joysticks, gamepads, keyboard, and mouse, then access them all through one simple scripting interface.

用户可以设置操纵杆,游戏手柄,键盘和鼠标,然后可以通过简单的脚本接口访问它们。

From scripts, all virtual axes are accessed by their name.

从脚本,所有虚拟轴通过它们的名字来访问。

Every project has the following default input axes when it's created:

当创建时,每个项目都具有下面的默认输入轴:

Horizontal and Vertical are mapped to w, a, s, d and the arrow keys. 水平和垂直被映射到w, a, s, d键和方向键Fire1, Fire2, Fire3 are mapped to Control, Option (Alt), and Command, respectively. Fire1, Fire2, Fire3被分别映射到Ctrl,Option(Alt)和Command键Mouse X and Mouse Y are mapped to the delta of mouse movement. Mouse X 和 Mouse Y被映射到鼠标移动增量Window Shake X and Window Shake Y is mapped to the movement of the window. Window Shake X 和 Window Shake Y 被映射到窗口的移动Adding new Input Axes 添加新的输入轴

If you want to add new virtual axes go to the Edit->Project Settings->Input menu. Here you can also change the settings of each axis.

如果想添加新的虚拟轴,选择菜单Edit->Project Settings->Input menu。这里可以改变每个轴的设置。

You map each axis to two buttons on a joystick, mouse, or keyboard keys.

映射每个轴到操纵杆、鼠标或键盘键的两个按钮。

Name 名称The name of the string used to check this axis from a script.名称用于从脚本使用这个轴Descriptive Name 描述名称Positive value name displayed in the input tab of the configuration dialog for standalone builds.正&#;名称显示于配置对话框的输入标签,用于独立版。Descriptive Negative Name 描述负名称Negative value name displayed in the Input tab of the Configuration dialog for standalone builds.负&#;名称显示于配置对话框的Input标签,用于独立版。Negative Button 负按钮The button used to push the axis in the negative direction.该按钮用于在负方向移动轴Positive Button 正按钮The button used to push the axis in the positive direction.该按钮用于在正方向移动轴Alt Negative Button 备选负按钮Alternative button used to push the axis in the negative direction.备选按钮用于在负方向移动轴Alt Positive Button 备选正按钮Alternative button used to push the axis in the positive direction.备选按钮用于在正方向移动轴Gravity 重力Speed in units per second that the axis falls toward neutral when no buttons are pressed.当没有按钮被按下,在单位每秒速度,轴下降到0。Dead 死亡Size of the analog dead zone. All analog device values within this range result map to neutral.模拟的死区大小。 设定范围内所有模拟设备的&#;为0。Sensitivity 灵敏度Speed in units per second that the the axis will move toward the target value. This is for digital devices only.在单位每秒速度,轴将移向目标&#;。这近用于数码设备。Snap 捕捉If enabled, the axis value will reset to zero when pressing a button of the opposite direction.如果启用,当按下相反方向的按钮,该轴&#;将重设为0。Invert 反向If enabled, the Negative Buttons provide a positive value, and vice-versa.如果启用,负按钮将提供一个正&#;,反之亦然。Type 类型The type of inputs that will control this axis. 控制轴的输入设备类型Axis 轴The axis of a connected device that will control this axis. 连接设备的轴将控制这个轴Joy Num 操作杆The connected Joystick that will control this axis. 连接操纵杆将控制这个轴

Use these settings to fine tune the look and feel of input. They are all documented with tooltips in the Editor as well.

使用这些设置来进行效果和输入的感觉微调。它们在编辑器中都带有提示。

Using Input Axes from Scripts 从脚本使用输入轴

You can query the current state from a script like this:

从像这样的脚本,可以查询当前状态:

value = Input.GetAxis ("Horizontal");

An axis has a value between -1 and 1. The neutral position is 0. This is the case for joystick input and keyboard input.

一个轴具有-1和1之间的&#;。中间位置为0。这种情况用于操纵杆输入和键盘输入。

However, Mouse Delta and Window Shake Delta are how much the mouse or window moved during the last frame. This means it can be larger than 1 or smaller than -1 when the user moves the mouse quickly.

然而,鼠标增量和Window Shake增量是鼠标或窗口从上一帧到现在的移动。这意思是当用户快速移动鼠标时,它可能大于1或小于-1。

It is possible to create multiple axes with the same name. When getting the input axis, the axis with the largest absolute value will be returned. This makes it possible to assign more than one input device to one axis name. For example, create one axis for keyboard input and one axis for joystick input with the same name. If the user is using the joystick, input will come from the joystick, otherwise input will come from the keyboard. This way you don't have to consider where the input comes from when writing scripts.

它可以创建具有相同名称的多个轴。当获取输入轴,该轴带有最大绝对&#;将被返回。这可以使得分配多个输入设备为一个轴名。例如,创建一个轴为键盘输入,一个轴为操纵杆输入,具有相同的名称。如果用户使用操纵杆,输入将来自操纵杆,否则输入将来自键盘。这样,当写脚本时就不必考虑输入来自什么设备了。

Button Names 按钮名称

To map a key to an axis, you have to enter the key's name in the Positive Button or Negative Button property in the Inspector.

要映射一个键到一个轴,在检视面板的正按钮或负按钮的属性中,必须输入键的名称。

The names of keys follow this convention:

输入键的名称如下:

Normal keys: "a", "b", "c" ... 标准键:Number keys: "1", "2", "3", ... 数字键:Arrow keys: "up", "down", "left", "right" 方向键:Keypad keys: "[1]", "[2]", "[3]", "[&#;]", "[equals]" 小键盘键:Modifier keys: "right shift", "left shift", "right ctrl", "left ctrl", "right alt", "left alt", "right cmd", "left cmd" 修改键:Mouse Buttons: "mouse 0", "mouse 1", "mouse 2", ... 鼠标按钮:Joystick Buttons (from any joystick): "joystick button 0", "joystick button 1", "joystick button 2", ... 操纵杆按钮(从任意操纵杆):Joystick Buttons (from a specific joystick): "joystick button 0", "joystick button 1", "joystick 1 button 0", ... 操纵杆按钮(从指定操纵杆):Special keys: "backspace", "tab", "return", "escape", "space", "delete", "enter", "insert", "home", "end", "page up", "page down" 特殊键:Function keys: "f1", "f2", "f3", ... 功能键:

The names used to identify the keys are the same in the scripting interface and the Inspector.

在脚本和检视面板,用来识别键的名称是一样的。

value = Input.GetKey ("a");

Mobile Input 移动设备输入

On iOS and Android, the Input class offers access to touchscreen, accelerometer and geographical/location input.

在 iOS/Android Input类提供触摸屏、加速度计和地理/位置输入。

Unity3D值Input Manager

Access to keyboard on mobile devices is provided via the iOS keyboard.

访问键盘是通过iOS keyboard。

Multi-Touch Screen 多点触控屏幕

The iPhone and iPod Touch devices are capable of tracking up to five fingers touching the screen simultaneously. You can retrieve the status of each finger touching the screen during the last frame by accessing the Input.touches property array.

iPhone和iPod触控设备是具有五个手指触控屏幕同时跟踪能力。通过访问Input.touches属性数&#;,可以取回每个手指触摸屏幕在最后一帧的状态。

Android

Android devices don't have a unified limit on how many fingers they track. Instead, it varies from device to device and can be anything from two-touch on older devices to five fingers on some newer devices.

Android设备,能跟踪多少个手指没有统一的限制。相反,在不同的设备上可能是不同的,从老设备的两指触控,到新设备的五指触控。

Each finger touch is represented by an Input.Touch data structure:

每个手指触控是通过Input.touches数据结构描述的:

fingerId 手指索引The unique index for a touch. 触摸的唯一索引。position 位置The screen position of the touch. 触摸屏幕的位置。deltaPosition 增量位置The screen position change since the last frame.自最后一帧改变的屏幕位置。deltaTime 增量时间Amount of time that has passed since the last state change.从最后状态改变到现在经过的时间tapCount 点击数The iPhone/iPad screen is able to distinguish quick finger taps by the user. This counter will let you know how many times the user has tapped the screen without moving a finger to the sides. Android devices do not count number of taps, this field is always 1.iPhone/iPad屏幕能够识别用过的快速点击, 这个计数器让你知道用户点击屏幕多少次,而不是移动手指。android设备不对点击计数,这个方法总是返回1phase 相位(状态)Describes so called "phase" or the state of the touch. It can help you determine if the touch just began, if user moved the finger or if he just lifted the finger.描述触摸的状态,可以帮助开发者确定用户是否刚开始触摸,是否用户移动手指,是否用户刚刚抬起手指。

Phase can be one of the following:

相位(状态)可能是下列之一:

Began 开始A finger just touched the screen. 手指刚刚触摸屏幕Moved 移动A finger moved on the screen. 手指在屏幕上移动Stationary 静止A finger is touching the screen but hasn't moved since the last frame.手指触摸屏幕,但是自最后一帧没有移动Ended 结束A finger was lifted from the screen. This is the final phase of a touch.手指从屏幕上抬起,这是触控的最后状态。Canceled 取消The system cancelled tracking for the touch, as when (for example) the user puts the device to her face or more than five touches happened simultaneously. This is the final phase of a touch.系统取消了触控跟踪,如,用户将设备放在了脸上或超过同时超过5个触摸点。这是触控的最后状态。

Following is an example script which will shoot a ray whenever the user taps on the screen:

下面的例子,只要用户在屏幕上点击,将射出一条光线:

Mouse Simulation 鼠标模拟

On top of native touch support Unity iOS/Android provides a mouse simulation. You can use mouse functionality from the standard Input class.

除了原有的触控之外,Unity iOS/Android还提供了鼠标模拟。从标准的Input类中,可以使用鼠标功能。

Accelerometer 加速度传感器

As the mobile device moves, a built-in accelerometer reports linear acceleration changes along the three primary axes in three-dimensional space. Acceleration along each axis is reported directly by the hardware as G-force values. A value of 1.0 represents a load of about &#;1g along a given axis while a value of -1.0 represents -1g. If you hold the device upright (with the home button at the bottom) in front of you, the X axis is positive along the right, the Y axis is positive directly up, and the Z axis is positive pointing toward you.

在手机设备移动时,内置加速度传感器报告在三维空间,沿着三个主要轴上的线性加速度改变。沿着每个轴的加速度由硬件作为G-force&#;直接报告。&#;为1表示沿给定轴增加1g负载,&#;为-1.0表示减少1g。如果用户在面前竖直拿着设备(home按钮在底部),X轴指向右,Y轴指向上,Z轴指向前。

You can retrieve the accelerometer value by accessing the Input.acceleration property.

可以通过访问Input.acceleration属性,取回加速度传感器的&#;。

The following is an example script which will move an object using the accelerometer:

下面的例子,将使用加速度传感器移动一个物体:

Low-Pass Filter 低通过滤器

Accelerometer readings can be jerky and noisy. Applying low-pass filtering on the signal allows you to smooth it and get rid of high frequency noise.

加速度传感器数&#;可能被颠簸和噪音影响。应用低通过滤器在信号上可以是它平滑,并摆脱高频噪音的干扰。

The following script shows you how to apply low-pass filtering to accelerometer readings:

下面的例子显示,怎样应用低通到加速度传感器数&#;:

The greater the value of LowPassKernelWidthInSeconds, the slower the filtered value will converge towards the current input sample (and vice versa). You should be able to use the LowPassFilter() function instead of avgSamples().

LowPassKernelWidthInSeconds的&#;越大, 被过滤&#;将汇集当前输入采样越慢,反之亦然。应该使用LowPassFilter()函数,而不是avgSamples()。

I'd like as much precision as possible when reading the accelerometer. What should I do?我想尽可能的读取加速度传感器的更高精度,应该怎样做呢?

Reading the Input.acceleration variable does not equal sampling the hardware. Put simply, Unity samples the hardware at a frequency of Hz and stores the result into the variable. In reality, things are a little bit more complicated -- accelerometer sampling doesn't occur at consistent time intervals, if under significant CPU loads. As a result, the system might report 2 samples during one frame, then 1 sample during the next frame.

读取 Input.acceleration变量,不等于从硬件采样。简而言之,Unity硬件样品频率为Hz并储存结果到变量。在现实中,是一个有点复杂的东西--加速度传感器采样不会发生在一致的时间间隔,如果大量的CPU负荷的情况下,因此,系统可能会报告一帧中的2个采样,那么1个采样在下一帧。

You can access all measurements executed by accelerometer during the frame. The following code will illustrate a simple average of all the accelerometer events that were collected within the last frame:

通过加速度传感器在帧间可以访问所有测量。

Further Reading 深入阅读

The Unity mobile input API is originally based on Apple's API. It may help to learn more about the native API to better understand Unity's Input API. You can find the Apple input API documentation here:

Unity移动Input API本来是基于Apple's API。这可以帮助你学习更多关于原生API,更好的理解Untiy的Input API。在这里找到Apple的 Input API文档:

Programming Guide: Event Handling (Apple iPhone SDK documentation)UITouch Class Reference (Apple iOS SDK documentation)

Note: The above links reference your locally installed iPhone SDK Reference Documentation and will contain native ObjectiveC code. It is not necessary to understand these documents for using Unity on mobile devices, but may be helpful to some!

注意:上面的链接参考你本地安装的iPHone SDK参考文档,也将包含ObjectiveC代码。对于在移动设备使用Unity开发,没有必要理解这些文档,但是可能或许有些一下帮助。

iOSDevice geographical location 设备地理位置

Device geographical location can be obtained via the iPhoneInput.lastLocation property. Before calling this property you should start location service updates using iPhoneSettings.StartLocationServiceUpdates() and check the service status via iPhoneSettings.locationServiceStatus. See the scripting reference for details.

设备地理位置可以通过iPhoneInput.lastLocation属性获得。在调用此属性之前,应该使用iPhoneSettings.StartLocationServiceUpdates()先开始位置服务的更新并通过iPhoneSettings.locationServiceStatus检查服务器状态。

参见脚本更多细节。

NGUI的Input输入框限制中文字节数问题 转载自:一般来说,昵称等用户输入的自定义数据都需要限制一下显示的长度。NGUI的INPUT输入框限制的是最大的char字符数,char字符数其实就是string的长

Unity3D跑酷游戏开发-游戏结束分数排名当前高能显示 (原创教程) 一般游戏结束后都会有个分数排名板。接下来让分析这功能。1.游戏结束后显示高分排列,当前玩家分数高能显示。(如果能进入排名板)2.数据必须持

Unity下Profiler的使用 转载自:

标签: Unity3D值Input Manager

本文链接地址:https://www.jiuchutong.com/biancheng/378728.html 转载请保留说明!

上一篇:unity3d 在线更新资源(3)(unity更新需要重新下载吗)

下一篇:NGUI的Input输入框限制中文字节数问题(input输入@弹出框)

  • 房产公司预缴土地增值税怎么做账
  • 土地增值税常见问题及解答
  • 注销公司详细步骤
  • 公司注销后持股要交税吗
  • 申报作废了还能修改吗
  • 批量转账和代发工资
  • 电子发票红字发票怎么开
  • 小规模自开专票怎么交税
  • 房屋置换以房换房政策2019
  • 无偿赠送他人货物交增值税吗
  • 临时工工资为什么那么低?
  • 无形资产加计扣除最新政策
  • 周转材料租赁费怎么结转成本
  • 餐饮行业液化气使用标准
  • 一张报关单上最多不能超过
  • 补交以前年度工会经费所得税如何申报
  • 异地取款还有手续费吗
  • 盘盈对应的入账科目
  • 母公司开票给子公司有什么税务风险吗
  • 增值税抄税报税流程2021
  • 涉税票据如何避免税务风险?
  • 内部权益性投资是指
  • 什么情况转账会延迟2天
  • linux运行后出现乱码
  • 可转债发行费用税前扣除
  • 怎么看iPhone电池温度
  • 苹果官网
  • 营改增后的增值税税目税率表
  • 非营利组织所得税申报
  • 安徽4岁男孩户口已解决
  • 有关预收账款的会计科目
  • 长期应收款属于流动资产吗
  • 工程物资已到发票怎么开
  • 员工保险个人部分交多少
  • thinkphpgui
  • ci框架视频教程
  • 专项应付款能转出来吗
  • 地方水利建设基金的会计分录
  • 应交税金会计编码
  • 金蝶软件利润表公式怎么设置
  • 支付股息如何做账
  • MySQL 数据库中,用于事务授权控制的关键词是下面哪个?
  • mongodb从入门到商业实战
  • 领取营业执照后超过30天
  • 企业注销后还会查账吗
  • 税盘清卡清不了怎么办
  • db2使用教程
  • 未开发票如何确认收入并进行申报?
  • 先收票后收货
  • 集团公司股份
  • 主营业务收入核算项目组合表
  • 房地产企业抵押借款
  • 获得赔偿收入什么科目
  • 天猫佣金是什么意思
  • 什么是现金流量表
  • 会计凭证用什么纸打印
  • sql批量导出数据
  • linux系统设置ntp同步
  • solaris删除文件命令
  • mac地图怎么标记多个位置
  • msng.exe是什么
  • 电脑超频以后变得很卡
  • qdcsfs.exe - qdcsfs是什么进程 有何作用
  • regloadr.exe - regloadr是什么进程 有什么用
  • win8平板玩lol
  • android 音频焦点丢失 媒体按键
  • 判断输入的日期是一年中第几天
  • 使用jquery
  • js 根据时间排序
  • jquery one()
  • nodejs递归创建目录
  • linux中crontab
  • unity 断点
  • arm兼容库安卓x86
  • 圣诞树代码html
  • javascrip
  • 如何查询纳税信用等级证明
  • 季度企业所得税分录
  • 严守纪律守规矩
  • 地税审计税务稽查局职责
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设