Developing for Android
Android 开发
Building games for a device running Android OS requires an approach similar to that for iOS development. However, the device's hardware is not completely standardized, which raises issues that don't occur in iOS development. There are some feature differences in the Android version of Unity just as there are with the iOS version.
为运行Android操作系统的设备制作游戏,需要一个类似IOS这样的开发环境,然而,运行Android设备的硬件并非完全标准的,这样会出现IOS开发上没有的问题。Unity上不同的Android版本,存在一些功能上的差异,就像unity上不同版本的IOS。
Setting up your Android Developer environment
安装Android开发环境
Before you can run Unity Android games on the actual device, you'll need to have your Android developer environment set up. This involves downloading and installing the Android SDK with the different Android plaforms and adding your physical device to your system (this is done a bit differently depending on whether you are developing on Windows or Mac). This setup process is explained on the Android developer website, and there may be additional information provided by the manufacturer of your device. Since this is a complex process, we've provided a basic outline of the tasks that must be completed before you can run code on your Android device or in the Android emulator. However, the best thing to do is follow the instructions step-by-step from the Android developer portal.
在能够将你的Android游戏运行在实际设备之前,你需要安装Android 开发环境.涉及到需要下载安装不同Android平台的SDK,并在你的系统中添加相应的物理设备(Windows or Mac 上的开发环境的设置有些不同)。SDK的安装过程,在Android 开发网站已有相应的说明,可能还需要参考设备制造商提供的一些附加信息。由于这个过程比较复杂,所以我们提供了基本大纲,为了能够在你的android设备或者Android模拟器上运行你的代码,你必须完成基本大纲上所描述的过程。然而,最好的做法是按照 Android 开发者门户网站上的指示一步一步的完成安装。
Access Android Functionality 访问Andorid功能
Unity Android provides a scripting APIs to access various input data and settings. You can find out more about the new scripting classes on the Android scripting page.
Unity Android提供了可以访问Android的各种输入和设置数据的脚本 APIs。你可以在Android脚本页 找到更多的新的脚本分类。
Exposing Native C, C++ or Java Code to Scripts
脚本访问本机C,C++ or Java 代码
Unity Android allows you to call custom functions written in C/C++ directly (and Java indirectly) from C# scripts. To find out how to bind native functions, visit the plugins page.
Unity Android允许通过C# 脚本,直接调用用C/C++ 写的自定义的功能函数。如何绑定本机代码,请访问插件页.
Occlusion Culling 遮挡剔除(剔除场景中被自己前面的物体所遮挡的物体)
Unity Android includes support for occlusion culling, which is perfect for squeezing high performance out of complex scenes with many objects. To learn how occlusion culling works, visit the occlusion culling page.
Unity Android 支持遮挡剔除,可以高效压缩具有大量对象实体的复杂场景。学习遮挡剔除的工作原理,请参考遮挡剔除 页.
Splash Screen Customization 定制开机画面
If you want to customize the splash screen that appears when launching your game on the device, you should visit the splash screen customization page.
如果想要在启动游戏时播放定制画面,可以访问定制开机画面.
Troubleshooting 排除故障
There are many reasons why your application may crash or fail to work as you expected. Look here to see how to troubleshoot on Android.
这里列举了很多你的应用程序为什么会宕机或者没有按照你预计的目标去运行的原因,详细请参考怎样排除Android故障页面。
Reporting Crash Bugs on Android
在Android上报告崩溃错误
Before submitting a bug report, please look through the Android troubleshooting page first. If this doesn't solve the problem, proceed to reporting an Android bug.
在提交BUG之前,请先在Android故障列表页查找改BUG,如果发现还没解决,请继续报告Android bug。
How Unity Android Differs from Desktop Unity
Unity Android 和 Desktop Unity有什么不同
Strongly Typed JavaScript 强类型的JavaScript脚本
Dynamic typing in JavaScript is always turned off in Unity Android. This is the same as adding #pragma strict to your scripts, but it is done by default instead. This greatly improves performance (which is especially important on the iPhone/iPad devices). When you launch an existing Unity Project, you will receive compiler errors if you are using dynamic typing. You can easily fix them by either using static typing for the variables that are causing errors or taking advantage of type interface.
在Unity Android中,动态类型转换总是被关闭的.类似于在脚本中添加#pragma strict 这样的语句,但总会被默认设置所替代。这样可以大大提高性能(尤其在iPhone/iPad设备上,更为重要).当你打开一个已存在的Unity,如果使用的是动态类型转换,你会得到编译错误提示。你可以很容易的采用静态类型转换去解决这个问题或者采用高级的类型接口。
Terrain Engine 地形引擎
The terrain engine is not supported on Android devices yet. The terrain engine is built to work with modern PC GPUs and can't be scaled down to anything currently suitable for Android. Using custom low poly meshes and occlusion culling is the best way to create terrains on Android devices.
Android设备不支持地形引擎。地形引擎是基于PC GPUs 模块的,无法缩小其功能使其适用于Android。在Android 设备上创建地形最好的办法就是使用自定义的低多边形网格和遮挡剔除.
ETC as Recommended Texture Compression
推荐最好使用ETC 作为纹理压缩格式
While Unity Android does support DXT/PVRTC/ATC textures, Unity will decompress the textures into RGB(A) format at runtime if those compression methods are not supported by the actual hardware. This could have an impact on the GPU rendering speed and it is recommended to use the ETC format instead. The ETC compression is regarded as the standard compression format on Android, and should be supported on all post 2.0 devices. ETC however does not support the alpha channel and, depending on the use case for such a texture, RGBA 16-bit might be the best trade-off between size, quality and rendering speed.
Unity Android 不支持DXT/PVRTC/ATC 格式的纹理, 如果实际硬件不支持这种压缩方法,Unity 将会在运行过程中将纹理解压为RGB(A)格式。但这样影响GPU的渲染速度,所以推荐使用ETC格式。ETC已作为Android 2.0之后所有版本的标准压缩格式。ETC不支持alpha通道,根据如何组织纹理数据,权衡质量和渲染速度,RGBA 16-bit 将是最好的选择。
It's also possible to create separate android distribution archives (.apk) for each of the DXT/PVRTC/ATC formats, and let the Android Market filtering select the correct archive for the different devices (see Publishing Builds for Android).
也可以为每种格式DXT/PVRTC/ATC单独创建apk,让Android Market为不同的设备选择正确的APK文档(Android 发布)。
Movie Playback 影片播放
Movie textures are not supported on Android, but a full-screen streaming playback is provided via scripting functions. To learn about supported file formats and scripting API, consult the movie page or the Android supported media formats page.
Android不支持电影纹理,但提供脚本函数支持全屏流播放。了解支持哪些文件格式和这些脚本API,咨询movie page 或 Android 支持的媒体格式.
Further Reading 深入阅读
- Android SDK Setup 安装Android SDK
- Android Remote Android远程工具
- Trouble Shooting 排除故障
- Reporting crash bugs under Android 报告Android下的崩溃错误
- Features currently not supported by Unity Android Unity Android目前不支持的功能
- Player Settings 播放器设置
- Android Scripting Android脚本
- Input 输入
- Mobile Keyboard 移动键盘
- Advanced Unity Mobile Scripting 高级Unity移动脚本
- Using .NET API 2.0 compatibility level 使用.NET API 2.0兼容级别
- Plugins - Pro/Mobile-Only Feature 插件 - 只用于专业版/移动版功能
- Customizing your Mobile target's Splash screen 定制自己的开机画面
- Devices That we Have Tested On 已测试通过的设备
- Integrating Unity with Eclipse Unity集成Eclipse
- Launching an Android application from within unity Unity中启动Android应用程序
页面最后更新: 2011-05-31