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

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

内容简介:手机上可以把一段时间的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块钱请我喝一杯咖啡的话,请用手机扫描二维码即可通过支付宝直接向我捐款哦。


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

查看所有标签

猜你喜欢:

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

Spring Into HTML and CSS

Spring Into HTML and CSS

Molly E. Holzschlag / Addison-Wesley Professional / 2005-5-2 / USD 34.99

The fastest route to true HTML/CSS mastery! Need to build a web site? Or update one? Or just create some effective new web content? Maybe you just need to update your skills, do the job better. Welco......一起来看看 《Spring Into HTML and CSS》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

在线进制转换器
在线进制转换器

各进制数互转换器

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具