SRDebug.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 bool IsInitialized { get; private set; }
  14. public static IDebugService Instance
  15. {
  16. get { return SRServiceManager.GetService<IDebugService>(); }
  17. }
  18. /// <summary>
  19. /// Action to be invoked whenever the user selects "copy" in the console window.
  20. /// If null, copy/paste will not be available.
  21. /// </summary>
  22. public static Action<ConsoleEntry> CopyConsoleItemCallback = GetDefaultCopyConsoleItemCallback();
  23. public static void Init()
  24. {
  25. IsInitialized = true;
  26. SRServiceManager.RegisterAssembly<IDebugService>();
  27. // Initialize console if it hasn't already initialized.
  28. SRServiceManager.GetService<IConsoleService>();
  29. // Load the debug service
  30. SRServiceManager.GetService<IDebugService>();
  31. #if UNITY_EDITOR
  32. SRDebugger.Scripts.Internal.SRScriptRecompileHelper.SetHasInitialized();
  33. #endif
  34. }
  35. public static Action<ConsoleEntry> GetDefaultCopyConsoleItemCallback()
  36. {
  37. #if COPY_TO_CLIPBOARD_SUPPORTED
  38. return entry =>
  39. {
  40. GUIUtility.systemCopyBuffer =
  41. string.Format("{0}: {1}\n\r\n\r{2}", entry.LogType, entry.Message, entry.StackTrace);
  42. };
  43. #else
  44. return null;
  45. #endif
  46. }
  47. }