DebugManager.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Serialization;
  4. using System;
  5. using System.Text;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using Sfs2X.Core;
  9. using Random = UnityEngine.Random;
  10. public class DebugManager : MonoBehaviour
  11. {
  12. #region Config
  13. public static Text DebugBugText
  14. {
  15. get
  16. {
  17. if (debugBugText == null)
  18. {
  19. DebugBugText = ResourceManager.Get<Text>(ObjectLabel.E_ScrrLab, false);
  20. }
  21. return debugBugText;
  22. }
  23. set { debugBugText = value; }
  24. }
  25. private static Text debugBugText;
  26. public int TextCounter;
  27. public float FrameRateTimer;
  28. #endregion
  29. public void Update()
  30. {
  31. FrameRateTimer += Time.deltaTime;
  32. TextCounter++;
  33. if (FrameRateTimer >= 1)
  34. {
  35. //Log($"当前帧率 {Counter} 目标帧率 {Application.targetFrameRate}");
  36. FrameRateTimer = 0;
  37. TextCounter = 0;
  38. }
  39. }
  40. public static void Log(string message)
  41. {
  42. if (DebugBugText == null)
  43. {
  44. return;
  45. }
  46. DebugBugText.text += '\n' + message;
  47. }
  48. public static void TryCatch(Action tryAction, Action catchAction)
  49. {
  50. try
  51. {
  52. tryAction.Invoke();
  53. }
  54. catch (Exception)
  55. {
  56. catchAction.Invoke();
  57. }
  58. }
  59. public static void PrintKeysAndValuesOfBaseEvent(string seperator, BaseEvent baseEvent)
  60. {
  61. Debug.LogWarning(seperator);
  62. foreach (var key in baseEvent.Params.Keys)
  63. {
  64. Debug.Log("Key " + key);
  65. }
  66. foreach (var value in baseEvent.Params.Values)
  67. {
  68. Debug.Log("value " + value);
  69. }
  70. Debug.LogWarning(seperator);
  71. }
  72. }