01_Unity remote debugging tool (MxDebug)

1. Effect display 

Station B address: Portal

Unity remote debugging function

2. Introduction

MxDebug  is a cross-platform diary management tool and   a sub-module of the MXFramework framework . It is not necessary to connect the USB cable, output all levels of Unity Log information, the entire module is decoupled, low intrusion, simple and easy to use, and can be integrated into the developed project with only one API. It can be removed at any time when it is not needed. The entire UI interface is basically the same as the Unity "Console" UI interface. The tool is divided into receiving end and input end. The receiving end has been developed to provide source code, and the input end is integrated into your existing project. Only one sentence of code will output your original project (Debug and Print and exception information). You can also turn off all journal output to save performance.

                                                                                          (UI interface of MxDebug) 

 

、 、 API

1. Turn on the debugging function (it is turned on by default, and it is recommended to turn it off when it is officially launched)

public static void OpenDebug(){}

The function is turned on by default, and log information of all levels of Unity will be entered

2. Turn off the debugging function (it is recommended to turn off all diary output when the project is officially launched)

public static void CloseDebug(){}

The function is to turn off all log output of Unity and all levels of log information. It is recommended to turn off all log output when the project is officially launched to save performance.

3. Remote debugging

public static void RemoteDebug(){} 

This function is used for remote debugging of the project. All log information will be sent to the computer Debug tool (receiving end) through the UDP protocol. This does not need to be connected to the USB cable, and can be viewed without ADB commands and Xcode software. log. When an exception or error occurs in the application, it will save a txt format error message to the local according to the time, and will record in detail the reason for the exception, the time, and the type of exception or error that occurred.

 

Three, how to integrate 

1. Go to GitHub to download the  MxDebug  tool, and import MxDebug/Tool/Debug.unitypackage (input terminal) into your project

2. Turn on or off all diary output functions (code is as follows)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mx.Log;
using UnityEngine.UI;

namespace Mx.Example
{
    /// <summary>测试打开或者关闭全部日记输出功能</summary>
    public class TestCloseLog : MonoBehaviour
    {
        private Text m_ButtonText;
        private bool m_IsOpenDebug = true;

        private void Awake()
        {
            m_ButtonText = GameObject.Find("Button/Text").GetComponent<Text>();

            InvokeRepeating("PrintLog", 0.2f, 0.2f);
        }

        public void OpenOrCloseLog()
        {
            m_IsOpenDebug = !m_IsOpenDebug;

            if(m_IsOpenDebug)
            {
                DebugManager.Instance.OpenDebug();
                m_ButtonText.text = "关闭日记输出";
            }
            else
            {
                DebugManager.Instance.CloseDebug();
                m_ButtonText.text = "打开日记输出";
            }
        }

        private void PrintLog()
        {
            int index1 = Random.Range(0, 3);
            int index2 = Random.Range(0, 10);

            if (index1 == 0)
            {
                Debug.Log(GetType() + "/PrintLog()/" + "请前往RemoteDebug工具查看Logo" + index2);
            }
            else if (index1 == 1)
            {
                Debug.LogWarning(GetType() + "/PrintLog()/" + "请前往RemoteDebug工具查看Logo" + index2);
            }
            else
            {
                Debug.LogError(GetType() + "/PrintLog()/" + "请前往RemoteDebug工具查看Logo" + index2);
            }
        }
    }
}

3. Remote debugging function (code is as follows)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mx.Log;

namespace Mx.Example
{
    /// <summary>测试远程调试功能</summary>
    public class TestRemoteDebug : MonoBehaviour
    {
        private void Awake()
        {
            DebugManager.Instance.RemoteDebug();
           

            InvokeRepeating("PrintLog", 0.2f, 0.2f);
        }

        private void PrintLog()
        {
            int index1 = Random.Range(0, 3);
            int index2 = Random.Range(0, 10);

            if (index1 == 0)
            {
                Debug.Log(GetType() + "/PrintLog()/" + "请前往RemoteDebug工具查看Logo" + index2);
            }
            else if (index1 == 1)
            {
                Debug.LogWarning(GetType() + "/PrintLog()/" + "请前往RemoteDebug工具查看Logo" + index2);
            }
            else
            {
                Debug.LogError(GetType() + "/PrintLog()/" + "请前往RemoteDebug工具查看Logo" + index2);
            }
        }
    }
}

4. The receiver under the MxDebug/Assets directory is all C# code, you can publish it as an exe file or other platforms. Can also be secondary development

 

Source address: https://github.com/yongliangchen/MxDebug  

Video tutorial: https://www.bilibili.com/video/BV1sK411A7Bd

QQ exchange group: 1079467433 

Guess you like

Origin blog.csdn.net/a451319296/article/details/108985330