Unity3D研究院之手机上保存Profiler与提取查看(一百零二)

栏目: 后端 · 发布时间: 7年前

内容简介:手机上可以把一段时间的profiler日志保存在本地,接着在手机里把文件取出来就可以在电脑上查看了,很方便,上代码,在需要保存手机Profiler日志的时候调用  ProfilerUtils.BeginRecord();并且我已经封装好了。

手机上可以把一段时间的profiler日志保存在本地,接着在手机里把文件取出来就可以在电脑上查看了,很方便,上代码,在需要保存手机Profiler日志的时候调用  ProfilerUtils.BeginRecord();并且我已经封装好了。

using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Profiling;
 
public class ProfilerUtils {
 
 
    static private GameObject profilerGameObject;
 
    static ProfilerUtils(){
        profilerGameObject = new GameObject("#Profiler#");
        UnityEngine.Object.DontDestroyOnLoad(profilerGameObject);
    }
 
 
    static public void BeginRecord()
    {
        if(!profilerGameObject.GetComponent<InternalBehaviour>()){
            profilerGameObject.AddComponent<InternalBehaviour>();
        }
    }
 
    class InternalBehaviour : MonoBehaviour
    {
        private string m_DebugInfo = String.Empty;
 
        private void OnGUI()
        {
            GUILayout.Label(String.Format("<size=50>{0}</size>", m_DebugInfo));
        }
 
        IEnumerator Start()
        {
 
            for (int i = 5; i > 0; i--)
            {
                m_DebugInfo = string.Format("<color=blue>{0}s后开始保存Profiler日志</color>", i);
                yield return new WaitForSeconds(1);
            }
            string file = Application.persistentDataPath + "/profiler_" + DateTime.Now.ToString("yyyyMMddhhmmss") +".log";
            Profiler.logFile = file;
            Profiler.enabled = true;
            Profiler.enableBinaryLog = true;
 
            for (int i = 5; i > 0; i--)
            {
                m_DebugInfo = string.Format("<color=red>{0}s后结束保存Profiler日志</color>", i);
                yield return new WaitForSeconds(1);
            }
 
            Profiler.enableBinaryLog = false;
            m_DebugInfo = string.Format("保存完毕:{0}", file);
            yield return new WaitForSeconds(10);
 
            Destroy(this);
        }
    }
 
}

Unity3D研究院之手机上保存Profiler与提取查看(一百零二)

Unity3D研究院之手机上保存Profiler与提取查看(一百零二)

最后在Profier窗口中点击load载入即可,如果你用的unity版本比较老,并没有load按钮,调用Proilfer.AddframesFromeFile也可以载入profiler信息。

Unity3D研究院之手机上保存Profiler与提取查看(一百零二)

雨松MOMO提醒您:亲,如果您觉得本文不错,快快将这篇文章分享出去吧 。另外请点击网站顶部彩色广告或者捐赠支持本站发展,谢谢!

最后编辑:

作者:雨松MOMO

专注移动互联网,Unity3D游戏开发

站内专栏 QQ交谈 腾讯微博 新浪微博

捐 赠 如果您愿意花20块钱请我喝一杯咖啡的话,请用手机扫描二维码即可通过支付宝直接向我捐款哦。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Everything Store

The Everything Store

Brad Stone / Little, Brown and Company / 2013-10-22 / USD 28.00

The definitive story of Amazon.com, one of the most successful companies in the world, and of its driven, brilliant founder, Jeff Bezos. Amazon.com started off delivering books through the mail. Bu......一起来看看 《The Everything Store》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具