Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 設備連接 Unity Profiler 性能分析器

編輯:關於 Android 程式設計

Unity 提供了兩種方式,讓開發者的 Android 設備連接到 Profiler 進行性能分析:

1. 通過 WiFi,讓 Android 設備和計算機處於同一個 WLAN 中;

2. 通過 USB 連接 ADB。

一般情況下我們的計算機都是用網線上網,所以這裡採用 ADB 的方式。相比 WiFi,ADB 也能更即時地反映設備的性能數據。

官方的英文文檔要點如下:

For ADB profiling, follow these steps: Attach your device to your Mac/PC via cable and make sure ADB recognizes the device (i.e. it shows in adb devices list). Check the "Development Build" checkbox in Unity's build settings dialog, and hit "Build & Run". When the app launches on the device, open the profiler window in Unity Editor (Window->Profiler). Select the AndroidProfiler(ADB@127.0.0.1:54999) from the Profiler Window Active Profiler drop down menu. Note: The Unity editor will automatically create an adb tunnel for your application when you press "Build & Run". If you want to profile another application or you restart the adb server you have to setup this tunnel manually. To do this, enter: adb forward tcp:54999 localabstract:Unity-[bundle identifier]. Note: If you are using a firewall, make sure that ports 54998 to 55511 are open in the firewall's outbound rules.

按照文檔的步驟,這裡翻譯並梳理一下操作流程:

第一步,設置 ADB。打開 CMD 命令行窗口,輸入以下命令(把後面的包名換成你自己應用的包名):

adb forward tcp:54999 localabstract:Unity-com.thisisgame.gamedemo

第二步,從 Unity 中 Export Android 工程的時候,一定要勾選 Development Build。

第三步,在手機上打開遊戲。

第四步,打開 Unity 的 Profiler 窗口,在 Active Profiler 下拉菜單中選擇 ADB@127.0.0.1:54999。

然後就能在 Profiler 中實時查看性能分析數據了。


小提示:如果重啟了 adb server 或想分析其他應用,需要手動重新執行 adb forward 命令建立隧道;另外如果使用了防火牆,記得放行 54998 到 55511 這段端口。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved