网上演练贵港万达广场(人员密集)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.6 KiB

4 years ago
using System;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
public class XLogPresenter
{
public List<XLog> LogsAll = new List<XLog>();
// 筛选日志集合
public ReactiveCollection<XLog> ShowLogs = new ReactiveCollection<XLog>();
//
public IntReactiveProperty LogsCount = new IntReactiveProperty(0);
public IntReactiveProperty WarningsCount = new IntReactiveProperty(0);
public IntReactiveProperty ErrorsCount = new IntReactiveProperty(0);
// 是否筛选Log
public bool IsShowLog = true;
// 是否筛选警告Log
public bool IsShowWarning = true;
// 是否筛选错误Log
public bool IsShowError = true;
public XLogPresenter()
{
LogHelper.LogCallbackAsObservable().Subscribe(x =>
{
switch (x.Type)
{
case LogType.Error:
case LogType.Exception:
if (IsShowError)
{
ShowLogs.Add(x);
}
ErrorsCount.Value++;
break;
case LogType.Warning:
if (IsShowWarning)
{
ShowLogs.Add(x);
}
WarningsCount.Value++;
break;
case LogType.Log:
if (IsShowLog)
{
ShowLogs.Add(x);
}
LogsCount.Value++;
break;
}
// 添加到集合
LogsAll.Add(x);
});
}
// 筛选所有指定类型的LOG
public void ShowLog(bool isShow)
{
IsShowLog = isShow;
GetData();
}
public void ShowWarning(bool isShow)
{
IsShowWarning = isShow;
GetData();
}
public void ShowError(bool isShow)
{
IsShowError = isShow;
GetData();
}
public void GetData()
{
ShowLogs.Clear();
foreach (var item in LogsAll)
{
switch (item.Type)
{
case LogType.Log:
if (IsShowLog)
{
ShowLogs.Add(item);
}
break;
case LogType.Warning:
if (IsShowWarning)
{
ShowLogs.Add(item);
}
break;
case LogType.Exception:
case LogType.Error:
if (IsShowError)
{
ShowLogs.Add(item);
}
break;
}
}
}
// 清空所有LOG
public void ClearLogs()
{
LogsCount.Value = 0;
WarningsCount.Value = 0;
ErrorsCount.Value = 0;
LogsAll.Clear();
ShowLogs.Clear();
}
}
public class XLog
{
public string Condition;
public string StackTrace;
public LogType Type;
public bool IsSelected;
public DateTime SendTime;
public int Id;
}
public static class LogHelper
{
static int count = 0;
public static UniRx.IObservable<XLog> LogCallbackAsObservable()
{
return Observable.FromEvent<Application.LogCallback, XLog>
(
h => (condition, stackTrace, type) => h(new XLog { Condition = condition, StackTrace = stackTrace, Type = type, IsSelected = false, SendTime = DateTime.Now, Id = count++ }),
h => Application.logMessageReceived += h,
h => Application.logMessageReceived -= h
);
}
}