The Unity Profiler helps you to optimize your game. It reports for you how much time is spent in the various areas of your game. For example, it can report the percentage of time spent rendering, animating or in your game logic.
Unity分析器可以帮助你优化你的游戏。它为您报告在你的游戏的各个领域所花费的时间。例如,它可以报告渲染、动画或在你的游戏逻辑花费时间的百分比。
You can play your game in the Editor with Profiling on, and it will record performance data. The Profiler window then displays the data in a timeline, so you can see the frames or areas that spike (take more time) than others. By clicking anywhere in the timeline, the bottom section of the Profiler window will display detailed information for the selected frame.
在编辑器中,你可以将你的游戏在分析器运行着的状态下运行,它会记录性能数据。 分析器窗口,在时间轴上显示数据,所以你可以看到帧或区域峰值(比其他需要更多的时间)。在时间轴中的任何地方按一下,分析器窗口的底部区域会显示选定的帧的详细信息。
Note that profiling has to instrument your code. This instrumentation has a small impact on the performance of your game. Typically this overhead is small enough to not affect the game framerate. When using profiling it is typical to consider only the ratio (or percentage) of time spent in certain areas. Also, to improve performance focus on those parts of the game that consume the most time. Compare profiling results before and after code changes and determine the improvements you measure. Sometimes changes you make to improve performance might have a negative effect on frame rate; unexpected consequences of code optimization should be expected.
请注意,分析时必须检测你的代码。这检测会对你的游戏性能有小小影响。通常情况下,这种开销是足够小,不会影响游戏的帧率。当使用分析时,它是典型的考虑时间花费在某些领域的比例(或百分比)。此外,为了提高性能,重点在游戏消耗的时间最多的那些部分。代码更改前后比较分析结果,并确定您测量的改进。有时,您所做的更改来提高性能,可能对帧速率有负面影响;应预计代码优化的意外的后果。
Remote profiling can be enabled on iOS devices by following these steps:
iOS设备上启用远程分析可以通过以下步骤:
If you are using a firewall, you need to make sure that ports 54998 to 55511 are open in the firewall's outbound rules - these are the ports used by Unity for remote profiling.
如果使用了防火墙,你必须确保端口54998 到 55511在防火墙的出站规则被打开。这些端口都是Unity远程分析要使用的端口。
Note: Sometimes Unity Editor might not autoconnect to the device. In such cases profiler connection might be initiated from Profiler Window Active Profiler drop down menu by select appropriate device.
注:有时,在Unity的编辑器可能不会自动连接到该设备。在这种情况下,在分析器窗口的Active Profiler下拉菜单选择相应的设备,分析器连接可以主动发起。
Remote profiling can be enabled on Android devices through two different paths : WiFi or ADB.
远程分析可以在Android设备通过两种不同的途径启用:WiFi或ADB。
For WiFi profiling, follow these steps:
对于WiFi分析,用下列的这些步骤:
Note: The Android device and host computer (running the Unity Editor) must both be on the same subnet for the device detection to work.
注意:Android设备和主机计算机(正运行Unity)必须两者在同一子网,才能正常运行设备检测工作。
For ADB profiling, follow these steps:
对于ADB分析,用下列的这些步骤:
adb forward tcp:54999 localabstract:Unity-<insert bundle identifier here>
Note: The entry in the drop down menu is only visible when the selected target is Android.
注意:进入下拉菜单,当选择目标是Android唯一可见时选择。
If you are using a firewall, you need to make sure that ports 54998 to 55511 are open in the firewall's outbound rules - these are the ports used by Unity for remote profiling.
如果使用了防火墙,你必须确保端口54998 到 55511在防火墙的出站规则被打开。这些端口都是Unity远程分析要使用的端口。