1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- namespace GFGGame
- {
- public class LogController : SingletonBase<LogController>
- {
- public const string _all = "All";
- public const string _error = "Error";
- public const string _log = "Log";
- public const int _maxCount = 100;
- public Dictionary<string, List<string>> msgDic = new Dictionary<string, List<string>>();
- public void Init()
- {
- msgDic.Add(_all, new List<string>());
- msgDic.Add(_error, new List<string>());
- msgDic.Add(_log, new List<string>());
- this.AddMsgListener();
- }
- public void AddMsgListener()
- {
- Application.logMessageReceived += (condition, stackTrace, type) =>
- {
- if (LauncherConfig.onDebug < 2)
- {
- return;
- }
- if (type == LogType.Error || type == LogType.Exception || type == LogType.Log)
- {
- this.AddMsgToDic(condition, stackTrace, type);
- }
- };
- }
- private void AddMsgToDic(string condition, string stackTrace, LogType type)
- {
- string msg = "";
- DateTime now = DateTime.Now;
- string time = string.Format("[{0}.{1} {2}:{3}:{4}]", now.Month, now.Day, now.Hour, now.Minute, now.Second);
- switch (type)
- {
- case LogType.Error:
- case LogType.Exception:
- if (msgDic[_all].Count == _maxCount)
- {
- msgDic[_all].RemoveAt(0);
- }
- if (msgDic[_error].Count == _maxCount)
- {
- msgDic[_error].RemoveAt(0);
- }
- msg = string.Format("error@{2}\n{0}\n{1}", condition, stackTrace, time);
- msgDic[_all].Add(msg);
- msgDic[_error].Add(msg);
- #if !UNITY_EDITOR
- ViewManager.Show<LogView>();
- #endif
- break;
- default:
- if (msgDic[_all].Count == _maxCount)
- {
- msgDic[_all].RemoveAt(0);
- }
- if (msgDic[_log].Count == _maxCount)
- {
- msgDic[_log].RemoveAt(0);
- }
- msg = string.Format("log@{2}\n{0}\n{1}", condition, stackTrace, time);
- msgDic[_all].Add(msg);
- msgDic[_log].Add(msg);
- break;
- }
- }
- }
- }
|