SRDebug.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #if UNITY_ANDROID || UNITY_IOS || UNITY_EDITOR || UNITY_STANDALONE
  2. #define COPY_TO_CLIPBOARD_SUPPORTED
  3. #endif
  4. using System;
  5. using System.Runtime.CompilerServices;
  6. using SRDebugger.Services;
  7. using SRF.Service;
  8. using UnityEngine;
  9. [assembly: InternalsVisibleTo("StompyRobot.SRDebugger.Editor")]
  10. public static class SRDebug
  11. {
  12. public const string Version = SRDebugger.VersionInfo.Version;
  13. public static IDebugService Instance
  14. {
  15. get { return SRServiceManager.GetService<IDebugService>(); }
  16. }
  17. /// <summary>
  18. /// Action to be invoked whenever the user selects "copy" in the console window.
  19. /// If null, copy/paste will not be available.
  20. /// </summary>
  21. public static Action<ConsoleEntry> CopyConsoleItemCallback = GetDefaultCopyConsoleItemCallback();
  22. public static void Init()
  23. {
  24. SRServiceManager.RegisterAssembly<IDebugService>();
  25. // Initialize console if it hasn't already initialized.
  26. SRServiceManager.GetService<IConsoleService>();
  27. // Load the debug service
  28. SRServiceManager.GetService<IDebugService>();
  29. #if UNITY_EDITOR
  30. SRDebugger.Scripts.Internal.SRScriptRecompileHelper.SetHasInitialized();
  31. #endif
  32. }
  33. public static Action<ConsoleEntry> GetDefaultCopyConsoleItemCallback()
  34. {
  35. #if COPY_TO_CLIPBOARD_SUPPORTED
  36. return entry =>
  37. {
  38. GUIUtility.systemCopyBuffer =
  39. string.Format("{0}: {1}\n\r\n\r{2}", entry.LogType, entry.Message, entry.StackTrace);
  40. };
  41. #else
  42. return null;
  43. #endif
  44. }
  45. }