Unity打包后控制台信息Debugger

using UnityEngine;
using System.Collections.Generic;
using System;
using UnityEngine.Profiling;

public class Debugger : MonoBehaviour
{
    /// <summary>
    /// 是否允许调试
    /// </summary>

    public bool AllowDebugging = true;

    private DebugType _debugType = DebugType.Console;

    private List<LogData> _logInformations = new List<LogData>();

    private int _currentLogIndex = -1;

    private int _infoLogCount = 0;

    private int _warningLogCount = 0;

    private int _errorLogCount = 0;

    private int _fatalLogCount = 0;

    private bool _showInfoLog = true;

    private bool _showWarningLog = true;

    private bool _showErrorLog = true;

    private bool _showFatalLog = true;

    private Vector2 _scrollLogView = Vector2.zero;

    private Vector2 _scrollCurrentLogView = Vector2.zero;

    private Vector2 _scrollSystemView = Vector2.zero;

    private bool _expansion = false;

    private Rect _windowRect = new Rect(0, 0, 100, 60);

    private int _fps = 0;

    private Color _fpsColor = Color.white;

    private int _frameNumber = 0;

    private float _lastShowFPSTime = 0f;

    private void Start()

    {

        if (AllowDebugging)

        {

            Application.logMessageReceived += LogHandler;

        }

    }

    private void Update()

    {

        if (AllowDebugging)

        {

            _frameNumber += 1;

            float time = Time.realtimeSinceStartup - _lastShowFPSTime;

            if (time >= 1)

            {

                _fps = (int)(_frameNumber / time);

                _frameNumber = 0;

                _lastShowFPSTime = Time.realtimeSinceStartup;

            }

        }

    }

    private void OnDestory()

    {

        if (AllowDebugging)

        {

            Application.logMessageReceived -= LogHandler;

        }

    }

    private void LogHandler(string condition, string stackTrace, LogType type)

    {

        LogData log = new LogData();

        log.time = DateTime.Now.ToString("HH:mm:ss");

        log.message = condition;

        log.stackTrace = stackTrace;

        if (type == LogType.Assert)

        {

            log.type = "Fatal";

            _fatalLogCount += 1;

        }

        else if (type == LogType.Exception || type == LogType.Error)

        {

            log.type = "Error";

            _errorLogCount += 1;

        }

        else if (type == LogType.Warning)

        {

            log.type = "Warning";

            _warningLogCount += 1;

        }

        else if (type == LogType.Log)

        {

            log.type = "Info";

            _infoLogCount += 1;

        }

        _logInformations.Add(log);

        if (_warningLogCount > 0)

        {

            _fpsColor = Color.yellow;

        }

        if (_errorLogCount > 0)

        {

            _fpsColor = Color.red;

        }

    }

    private void OnGUI()

    {

        if (AllowDebugging)

        {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值