目录
Unity 基础 之 连接 Android 手机 使用 Profiler 基于 2019.3.x
一、简单介绍
二、效果预览
三、注意事项
四、实现步骤
附录:
防火墙开启端口:54998-55511 的简单步骤
Unity中的一些基础知识点。
本节简单介绍如何连接Android手机,Profiler 调试 ,可能有疏漏,如果您有更好的方法,欢迎留言指正。
官方文档:https://docs.unity3d.com/Manual/Profiler.html
Profiler 窗口的上半部分显示随时间推移的性能数据。运行游戏时,每帧都会记录数据,并显示最近几百帧的历史记录。单击特定帧将在窗口的下半部分显示其详细信息。根据当前选择的时间轴区域会显示不同的详细信息。
时间轴的垂直刻度是自动管理的,并会尝试填充窗口的垂直空间。请注意,要显示更多详细信息,比如 CPU Usage 区域中的信息,可删除 Memory 和 Rendering 区域。此外,可选择时间轴和统计信息区域之间的分割线并向下拖动,从而增加用于时间轴图表的屏幕区域。
时间轴包含几个区域:CPU Usage、Rendering 和 Memory。单击面板中的关闭按钮可删除这些区域,而使用性能分析器控件栏中的 Add Area 下拉选单可重新添加这些区域。
请注意,标签区域中的彩色方块可以控制是否显示关联的时间轴。要从显示中删除样本,请单击颜色键。该键将变暗,且数据将从图表中删除。此功能很有用,例如,可用于找出 CPU 图中产生尖峰的原因。
The Unity Profiler is a tool you can use to get performance information about your application. You can connect it to devices on your network or devices connected to your machine to test how your application runs on your intended release platform. You can also run it in the Editor to get an overview of resource allocation while you’re developing your application.
The Profiler gathers and displays data on the performance of your application in areas such as the CPU, memory, renderer, and audio. It’s a useful tool to identify areas for performance improvement in your application, and iterate on those areas. You can pinpoint things like how your code, assets, scene
settings, camera
rendering
, and build settings affect your application’s performance. It displays the results in a series of charts, so you can visualize where spikes in your application’s performance happen.In addition to using the built-in Unity Profiler, you can use the low level native plug-in Profiler API to export profiling data to third-party profiling tools, and the Profiling Core package to customize your profiling analysis. You can also add powerful profiling tools such as the Memory Profiler, and the Profile Analyzer to your project to analyze performance data in further detail.
To access the Profiler window go to menu: Window > Analysis > Profiler. For a detailed overview of the window, see the Profiler window documentation.
1、这里要注意防火墙不能屏蔽端口:54998-55511
2、确保 adb 连接要测试的 Android 设备
3、如果端口有占用情况,还请解除占用
4、有时候 Unity Profiler 没有反应,可以试着重启 Unity,或者 App
1、打开 Unity ,新建一个工程
2、简单在场景中,添加一些资源,这里作为简单测试使用
3、File - Build Settings ,切换成 Android 平台,并勾选 Development Build ,Autoconnect Profiler,Deep Profiling support (根据需要)
4、打包Apk ,然后连接手机,可以使用 adb 把应用安装到手机上
5、查看包名,后面可能使用到
6、adb forward 指定端口到具体应用上
adb forward tcp:34999 localabstract:Unity-包名
adb forward tcp:34999 localabstract:Unity-com.DefaultCompany.TestAndroidProfile
7、如果上面不能出现报错,无法连接
1)输入:adb nodaemon server,发现端口5037已被占用(可能是其他端口)
2)输入:netstat –ano | findstr “5037”,查看5037被哪些进程占用
3)输入:taskkill /f /pid 5900(这里是上面查出的进程pid),终止占用5037的进程
4)重新输入 adb forward tcp:34999 localabstract:Unity-包名 在测试
8、adb forward 还是不能连接成功,可以 adb kill-server,在 adb start-server ,接着adb forward tcp:34999 localabstract:Unity-包名 在测试
9、运行之前手机安装的 Profiler 调试的 App ,然后 Unity 上 Window - Analysis - Profiler
10、Profiler 选择 AndroidPlayer(ADB@127.0.0.1:34999),然后就会看到数据运行
基于 windows 10
1、打开 控制面板
2、控制面板,查看类型-大图标,找到 Windows Defender 防火墙,点击打开
3、找到 高级设置,点击打开
4、找到 入站规则,然后点击 新建规则
5、选择端口,点击下一步
6、TCP 特定本地端口,54998-55511,下一步
7、允许连接,点击下一步
8、如图,点击下一步
9、填写必要的名称和描述,点击 完成