一、效果展示
B站地址:传送门
Unity远程调试功能
二、介绍
MxDebug 是一个跨平台日记管理工具,是 MXFramework框架 的一个子模块。可以不需链接USB线,输出Unity所有级别的Log信息,整个模块解耦合,低入侵,简单易用,对已经开发好的项目只需要一句API就可以集成进去。不需要时候可以随时移除。 整个UI界面和Unity “Console”UI界面基本一样。工具分为接收端和输入端。接收端已经开发好了提供源码,输入端是集成到你现有项目中去的,只需要一句代码就会输出你原有项目中的(Debug和Print和异常信息)。还可以关闭所有日记输出以节省性能。
(MxDebug的UI界面)
三、API
1.打开调试功能(默认是开启的,正式上线的时候建议关闭)
public static void OpenDebug(){}
功能默认是打开,会输入Unity所有级别的Log信息
2.关闭调试功能(建议项目正式上线的时候关闭所有日记输出)
public static void CloseDebug(){}
该工能是关闭Unity的所有日记输出,关闭所有级别的log信息,建议项目正式上线的时候关闭所有日记输出以便节省性能。
3.远程调试
public static void RemoteDebug(){}
该功能是用于项目远程调试时候使用,将所有log信息会通过UDP协议发送给电脑Debug工具(接收端),这个就可以不需要连接USB线,和不通过ADB命令和Xcode软件也能查看全部log。当应用发生异常或者错误的时候会根据时间保存一份txt格式的错误信息到本地,会详细的记录发生异常的原因,时间,和是由哪些类,引发的异常或错误。
三、如何集成
1.前往GitHub下载 MxDebug 工具,将 MxDebug/Tool/Debug.unitypackage(输入端) 导入到您的工程中
2.打开或者关闭全部日记输出功能(代码如下)
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.远程调试功能 (代码如下)
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.MxDebug/Assets 目录下的是接收端,全部都是C#代码,你可以发布成exe文件或者其他平台。也可以二次开发
源码地址:https://github.com/yongliangchen/MxDebug
视频教程:https://www.bilibili.com/video/BV1sK411A7Bd
QQ交流群:1079467433