Archived
分散文件结构,添加了枚举类型的一个辅助类
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
using log4net.Util;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using static Codice.CM.WorkspaceServer.WorkspaceTreeDataStore;
|
||||
|
||||
namespace XericLibrary.Runtime.MacroLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// Merged debug messages
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 合并调试消息,
|
||||
/// 如果需要输出连续的一串消息,但又因为太长或太细碎导致调试信息破碎,
|
||||
/// 就适合使用合并消息。
|
||||
/// </remarks>
|
||||
public class MergeDebug
|
||||
{
|
||||
#region 字段属性
|
||||
|
||||
/// <summary>
|
||||
/// 单次发送消息的限制长度
|
||||
/// </summary>
|
||||
private const int debugInfomationLengthLimit = 4000;
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
private StringBuilder messageContext;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 构造函数
|
||||
|
||||
public MergeDebug()
|
||||
{
|
||||
messageContext = new StringBuilder();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 输入消息
|
||||
|
||||
/// <summary>
|
||||
/// Push the message content
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 压入消息内容
|
||||
/// </remarks>
|
||||
public void PushLog(string message)
|
||||
{
|
||||
messageContext.Append(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Push the message content, with a line feed
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 压入消息内容,并在末尾追加一个换行符
|
||||
/// </remarks>
|
||||
public void PushLogLine(string message)
|
||||
{
|
||||
messageContext.AppendLine(message);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 输出消息
|
||||
|
||||
private static bool IsNewLine(char c)
|
||||
{
|
||||
return c == '\n' || c == '\r';
|
||||
}
|
||||
|
||||
private static void PopLog(StringBuilder sb, Action<string> debugFunc)
|
||||
{
|
||||
//debugInfomationLengthLimit
|
||||
var context = sb.ToString();
|
||||
|
||||
int startIndex = 0;
|
||||
int endIndex = 0;
|
||||
|
||||
while(startIndex < context.Length)
|
||||
{
|
||||
endIndex = Math.Min(startIndex + debugInfomationLengthLimit, context.Length);
|
||||
|
||||
while(endIndex > startIndex && !IsNewLine(context[endIndex - 1]))
|
||||
{
|
||||
endIndex--;
|
||||
}
|
||||
|
||||
string line = context.Substring(startIndex, endIndex - startIndex);
|
||||
debugFunc(line);
|
||||
|
||||
startIndex = endIndex;
|
||||
while(startIndex < context.Length && IsNewLine(context[startIndex]))
|
||||
{
|
||||
startIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send information in a message type
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 以消息类型发送信息
|
||||
/// </remarks>
|
||||
public void Log()
|
||||
{
|
||||
PopLog(messageContext, a => Debug.Log(a));
|
||||
messageContext.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send information in a Warning type
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 以警告类型发送信息
|
||||
/// </remarks>
|
||||
public void LogWarning()
|
||||
{
|
||||
PopLog(messageContext, a => Debug.LogWarning(a));
|
||||
messageContext.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send information in a Error type
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 以错误消息类型发送信息
|
||||
/// </remarks>
|
||||
public void LogError()
|
||||
{
|
||||
PopLog(messageContext, a => Debug.LogError(a));
|
||||
messageContext.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12ca18e1b72f65247a03c7f98672eb00
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user