DebugLogManager.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class DebugLogManager : MonoBehaviour {
  5. [SerializeField]
  6. private TextMesh mText;
  7. private List<DebugLog> mLogList = new List<DebugLog>();
  8. private DebugOutputManager mDebugOutputManagder;//专门做日志输出的
  9. void Start () {
  10. Application.logMessageReceived += MsgReceivedLog;
  11. mDebugOutputManagder = new DebugOutputManager();
  12. if(CDebug.IsDebug == false)
  13. {
  14. mText.gameObject.SetActive(false);
  15. }
  16. if(mText != null)
  17. mText.text = "";
  18. }
  19. void OnDestroy()
  20. {
  21. Application.logMessageReceived -= MsgReceivedLog;
  22. }
  23. private const int MAX_COUNT = 20;
  24. private void MsgReceivedLog( string logStr, string sTrace, LogType lType )
  25. {
  26. if(mText == null)
  27. {
  28. //不存在 或者应用已经关闭了
  29. return;
  30. }
  31. if (GamePlayerData.Instance.isDebugAccount)
  32. mLogList.Add (new DebugLog(logStr, sTrace, lType));
  33. mText.text = "";
  34. for (int i = Mathf.Max(0, mLogList.Count - MAX_COUNT); i < mLogList.Count; i++) {
  35. mText.text = mText.text + "\n" + mLogList[i].ToString();
  36. }
  37. }
  38. }