Importing the CrossPlatformInput package adds a menu item to Unity, "CrossPlatformInput", which allows you to enable or disable the CrossPlatformInput in the editor. You must enable the CrossPlatformInput in order to see the control rigs in the editor, and to start using Unity Remote to control your game.
导入CrossPlatformInput包将在Unity中添加要给菜单项“CrossPlatformInput”,从而在编辑器中启用或禁用CrossPlatformInput。必须启用CrossPlatformInput才能在编辑器中看到控件,以及用Unity Remote控制游戏。
The CrossPlatformInput sample assets contains two main sections.
CrossPlatformInput示例资源含有两个主要部分。
- The folder of prefabs provide a variety of ready-to-use "MobileControlRigs". Each control rig is suitable for a different purpose, and each implements the touch or tilt-based equivalent of some of the default standalone axes or buttons. These are ready to drop into your scene, and to use them you simply need to read the axes via the CrossPlatformInput class, rather than Unity's regular Input class.
prefabs文件夹中提供了一些做好的“移动端控件”。每个控件都适合不同的用途,都各自实现了触摸或摇摆处理以对应标准的输入轴和按钮。这些控件直接放到场景里就能使用,简单通过CrossPlatformInput类就能读取输入,注意不是Unity常规的Input类。
- The set of scripts provided are the scripts we used to put together the control rigs prefabs. They provide a simplified way of reading basic mobile input, such as tilt, taps and swipe gestures. They are designed so that various mobile controls can be read in the same way as regular Unity axes and buttons. You can use these scripts to build your own MobileControlRigs.
提供的脚本用于将控件预制体结合在一起,用于读取基本的移动端输入,比如摇摆倾斜,点击,还有滑动手势,就像读取常规Unity轴或者按钮一样。用这些脚本也可以构建自己的移动端控件。
For example the Car control rig feeds the tilt input of the mobile device to the "Horizontal" axis, and has an accelerator and brake touch button which are fed as a pair into the "Vertical" axis. These are virtual equivalents of the real "Horizontal" and "Vertical" axes defined in Unity's Input Manager.
比如,车的控件将移动设备的倾斜输入传送到“Horizontal”轴,并且将加速和刹车触摸按钮的动作传送给“Vertical”轴。这些都是定义在Unity的Input Manager中的真正的“Horizontal”以及“Vertical”轴的相应虚拟输入。
Therefore when you read CrossPlatformInput.GetAxis("Horizontal"), you will either get the "real" input value - if your build target is non-mobile, or the value from the mobile control rig - if your build target is set to a mobile platform.
这样,在使用CrossPlatformInput.GetAxis("Horizontal")时,将在非移动平台下获得“真正”的输入值,而在移动平台下获得移动端控件的值。
The CrossPlatformInput scripts and prefabs are provided together as an example of how you can implement a cross-platform control solution in Unity. They also allow us to provide our other sample scenes in a form that can be published as standalone or to mobile targets with no modification.
CrossPlatformInput的脚本和预制体演示了如何在Unity中实现跨平台控制方案。这使得在不同平台发布游戏时不需要做任何更改。
To use the CrossPlatformInput, you need to drop a "Mobile Control Rig" into your scene (or create your own), and then make calls to CrossPlatformInput functions, referring to the axes and buttons that the Rig implements.
要使用CrossPlatformInput,需要将“移动端控件”放入场景(或者自己创建控件),然后调用CrossPlatformInput的方法来获取控件实现的轴和按钮的输入值。
When reading input from the CrossPlatformInput class, the values returned will be taken either from Unity's Input Manager settings, or from the mobile-specific controls set up, depending on which build target you have selected.
通过CrossPlatformInput类获取输入时,根据运行的目标平台,值可能来自Unity的Input Manager,也可能来自移动端控件。
The CrossPlatformInput class is designed to be called instead of Unity's own Input class, and so mirrors certain parts of the Input API - specifically the functions relating to Axes and Buttons:
GetAxis, GetAxisRaw
GetButton, GetButtonDown, GetButtonUp
CrossPlatformInput类的设计可以取代Unity自己的Input类,仿照Input API做了类似实现-特别是与轴和按钮相关的功能: GetAxis, GetAxisRaw,GetButton, GetButtonDown, GetButtonUp
Notes for coders:
This package sets two compiler define symbols. One is always set automatically, the other is optionally set from a menu item.
程序员要注意:
这个包设置了两个编译器定义符。一个总是设置为自动,另一个是从菜单项中设置。
Importing the "CrossPlatformInput" package will automatically add a compiler define symbol, "CROSS_PLATFORM_INPUT". This enables the CrossPlatformInput functions defined in some of the other Sample Asset packages (such as the Characters, Planes, etc). Without this symbol defined, those packages use Unity's regular Input class, which means they can be imported alone and still work without the CrossPlatformInput package.
导入“CrossPlatformInput”包会自动添加一个编译器定义符“CROSS_PLATFORM_INPUT”,用于开启定义在一些示例资源包中CrossPlatformInput相关功能(比如角色控制,飞机等)。移除这个定义符,那些包将使用Unity常规Input类,就是说,没有CrossPlatformInput包导入,那些包也能单独导入并工作,只是不支持CrossPlatformInput的功能了。
The optional define (which is set by default, but can be disabled using the "Mobile Input" menu), is "MOBILE_INPUT". This causes the MobileControlRigs to become active when a mobile build target is selected. It also enables certain mobile-specific control nuances in some of the packages, which make more sense when the character or vehicle is being controlled using mobile input (such as auto-leveling the character's look direction). This define is optional because some developers prefer to use standalone input methods instead of the Unity Remote app, when testing mobile apps in the editor's play mode.
另一个可选的定义(默认是开启的,但可以通过“Mobile Input”菜单禁用)是“MOBILE_INPUT”。这使得移动端作为目标平台时MobileControlRigs会成为启用状态。也同样会开启某些包中移动端相关的细微控制,使得在移动端控制角色或载具时更加自在(比如自动找平角色的观察方向)。这个选项是可选的,因为在编辑器模式下,有些开发者更喜欢常规的Input方法而不是Unity Remote App(一种编辑开发模式下,将手机用于输入操作的方法)。