SRDebugUtil.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using SRF;
  5. using UnityEngine;
  6. using Debug = UnityEngine.Debug;
  7. public static class SRDebugUtil
  8. {
  9. public const int LineBufferCount = 512;
  10. public static bool IsFixedUpdate { get; set; }
  11. [DebuggerNonUserCode]
  12. [DebuggerStepThrough]
  13. public static void AssertNotNull(object value, string message = null, MonoBehaviour instance = null)
  14. {
  15. if (!EqualityComparer<object>.Default.Equals(value, null))
  16. {
  17. return;
  18. }
  19. message = message != null ? "NotNullAssert Failed: {0}".Fmt(message) : "Assert Failed";
  20. Debug.LogError(message, instance);
  21. if (instance != null)
  22. {
  23. instance.enabled = false;
  24. }
  25. throw new NullReferenceException(message);
  26. }
  27. [DebuggerNonUserCode]
  28. [DebuggerStepThrough]
  29. public static void Assert(bool condition, string message = null, MonoBehaviour instance = null)
  30. {
  31. if (condition)
  32. {
  33. return;
  34. }
  35. message = message != null ? "Assert Failed: {0}".Fmt(message) : "Assert Failed";
  36. Debug.LogError(message, instance);
  37. throw new Exception(message);
  38. }
  39. [Conditional("UNITY_EDITOR")]
  40. [DebuggerNonUserCode]
  41. [DebuggerStepThrough]
  42. public static void EditorAssertNotNull(object value, string message = null, MonoBehaviour instance = null)
  43. {
  44. AssertNotNull(value, message, instance);
  45. }
  46. [Conditional("UNITY_EDITOR")]
  47. [DebuggerNonUserCode]
  48. [DebuggerStepThrough]
  49. public static void EditorAssert(bool condition, string message = null, MonoBehaviour instance = null)
  50. {
  51. Assert(condition, message, instance);
  52. }
  53. }