Version: 2017.2
iOS 开发入门
iOS 帐户设置

Unity iOS 基础知识

本部分介绍在开始使用 iOS 时出现的最常见和最重要的问题。

先决条件

我刚收到 Apple 的 iPhone 开发者审批,但我以前从未进行过 iOS 的开发。我首先需要做什么?

:下载 SDK,在 Apple 开发者网站上设置并运行,建立开发团队,准备好设备,并调配资源。我们提供了一份基本步骤列表供您入门之用。

Unity 构建的游戏可以在 iPhone 模拟器中运行吗?

A: No, but Unity iOS can build to iPad Simulator if you’re using the latest SDK. However the simulator itself is not very useful for Unity because it does not simulate all inputs from iOS or properly emulate the performance you get on the iPhone/iPad. You should test out gameplay directly inside Unity using the iPhone/iPad as a remote control while it is running the Unity Remote application. Then, when you are ready to test performance and optimize the game, you publish to iOS devices.

Unity 功能

如何使用触摸屏和加速度计?

A: In the scripting reference inside your Unity iOS installation, you will find classes that provide the hooks into the device’s functionality that you will need to build your apps. Consult the Input page for more information.

我现有的粒子系统似乎在 iOS 上运行得非常慢。我该怎么办?

A: iOS has relatively low fillrate. If your particles cover a rather large portion of the screen with multiple layers, it will kill iOS performance even with the simplest shader. We suggest baking your particle effects into a series of textures off-line. Then, at run-time, you can use 1–2 particles to display them via animated textures. You can get fairly decent looking effects with a minimum amount of overdraw this way.

我可以制作大量使用物理系统的游戏吗?

A: Physics can be expensive on iOS as it requires a lot of floating point number crunching. You should completely avoid MeshColliders if at all possible, but they can be used if they are really necessary. To improve performance, use a low fixed framerate using Edit->Time->Fixed Delta Time. A framerate of 10–30 is recommended. Enable rigidbody interpolation to achieve smooth motion while using low physics frame rates. In order to achieve completely fluid framerate without oscillations, it is best to pick fixed deltaTime value based on the average framerate your game is getting on iOS. Either 1:1 or half the frame rate is recommended. For example, if you get 30 fps, you should use 15 or 30 fps for fixed frame rate (0.033 or 0.066)

我可以在 Unity iOS 中访问图库、音乐库或原生 iPod 播放器吗?

A: Yes - if you implement it. Unity iPhone supports the native plugin system, where you can add any feature you need – including access to Gallery, Music library, iPod Player and any other feature that the iOS SDK exposes. Unity iOS does not provide an API for accessing the listed features through Unity scripts.

UnityGUI 注意事项

UnityGUI 会对我的游戏产生什么样的性能影响?

A: UnityGUI is fairly expensive when many controls are used. It is ideal to limit your use of UnityGUI to game menus or very minimal GUI Controls while your game is running. It is important to note that every object with a script containing an OnGUI() call will require additional processor time – even if it is an empty OnGUI() block. It is best to disable any scripts that have an OnGUI() call if the GUI Controls are not being used. You can do this by marking the script as enabled = false.

是否有任何其他关于使用 UnityGUI 的技巧?

:尽可能减少 GUILayout 的使用。如果在一个 OnGUI() 调用中未使用任何 GUILayout,可以使用 MonoBehaviour.useGUILayout = false; 禁用所有 GUILayout 渲染。这样可以使 GUI 渲染性能提高一倍。最后,在渲染 3D 场景时使用尽可能少的 GUI 元素。

iOS 开发入门
iOS 帐户设置