DebugManager.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 Lab
  14. {
  15. get
  16. {
  17. if (Lab_ == null)
  18. {
  19. Lab = ResourceManager.Get<Text>(ObjectLabel.E_ScrrLab, false);
  20. }
  21. return Lab_;
  22. }
  23. set { Lab_ = value; }
  24. }
  25. private static Text Lab_;
  26. public int Counter;
  27. public float Timer;
  28. #endregion
  29. public void Update()
  30. {
  31. Timer += Time.deltaTime;
  32. Counter++;
  33. if (Timer >= 1)
  34. {
  35. //Log($"当前帧率 {Counter} 目标帧率 {Application.targetFrameRate}");
  36. Timer = 0;
  37. Counter = 0;
  38. }
  39. }
  40. public static void Log(string message)
  41. {
  42. if (Lab == null)
  43. {
  44. return;
  45. }
  46. Lab.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. }