IDebugService.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace SRDebugger.Services
  6. {
  7. public interface IDebugService
  8. {
  9. /// <summary>
  10. /// Current settings being used by the debugger
  11. /// </summary>
  12. Settings Settings { get; }
  13. /// <summary>
  14. /// True if the debug panel is currently being shown
  15. /// </summary>
  16. bool IsDebugPanelVisible { get; }
  17. /// <summary>
  18. /// True if the trigger is currently enabled
  19. /// </summary>
  20. bool IsTriggerEnabled { get; set; }
  21. /// <summary>
  22. /// True if new errors cause the trigger to display an error notification.
  23. /// Note: <see cref="IsTriggerEnabled"/> must also be true for notification to display.
  24. /// </summary>
  25. bool IsTriggerErrorNotificationEnabled { get; set; }
  26. IDockConsoleService DockConsole { get; }
  27. /// <summary>
  28. /// Access the SRDebugger console current filter states.
  29. /// </summary>
  30. IConsoleFilterState ConsoleFilter { get; }
  31. bool IsProfilerDocked { get; set; }
  32. /// <summary>
  33. /// Add <paramref name="entry"/> to the system information tab. See <seealso cref="InfoEntry"/> for how to create
  34. /// an info instance.
  35. /// </summary>
  36. /// <param name="entry">The entry to be added.</param>
  37. /// <param name="category">The category the entry should be added to.</param>
  38. void AddSystemInfo(InfoEntry entry, string category = "Default");
  39. /// <summary>
  40. /// Show the debug panel
  41. /// </summary>
  42. /// <param name="requireEntryCode">
  43. /// If true and entry code is enabled in settings, the user will be prompted for a passcode
  44. /// before opening the panel.
  45. /// </param>
  46. void ShowDebugPanel(bool requireEntryCode = true);
  47. /// <summary>
  48. /// Show the debug panel and open a certain tab
  49. /// </summary>
  50. /// <param name="tab">Tab that will appear when the debug panel is opened</param>
  51. /// <param name="requireEntryCode">
  52. /// If true and entry code is enabled in settings, the user will be prompted for a passcode
  53. /// before opening the panel.
  54. /// </param>
  55. void ShowDebugPanel(DefaultTabs tab, bool requireEntryCode = true);
  56. /// <summary>
  57. /// Hide the debug panel
  58. /// </summary>
  59. void HideDebugPanel();
  60. /// <summary>
  61. /// Set the entry code required to open the debug panel.
  62. /// Entry code requirement will be enabled if it is not already.
  63. ///
  64. /// If the user has already entered the correct pin code, their authorization will be reset
  65. /// and they will be required to enter the new pin code next time they open the debug panel.
  66. ///
  67. /// Use <see cref="DisableEntryCode"/> to disable the entry code requirement.
  68. /// </summary>
  69. /// <param name="newCode">New entry code.</param>
  70. void SetEntryCode(EntryCode newCode);
  71. /// <summary>
  72. /// Disable the requirement for an entry code when opening the debug panel.
  73. /// Use <see cref="SetEntryCode"/> to enable entry code the requirement again.
  74. /// </summary>
  75. void DisableEntryCode();
  76. /// <summary>
  77. /// Hide the debug panel, then remove it from the scene to save memory.
  78. /// </summary>
  79. void DestroyDebugPanel();
  80. /// <summary>
  81. /// Add all an objects compatible properties and methods to the options panel.
  82. /// <remarks>NOTE: It is not recommended to use this on a MonoBehaviour, it should be used on a standard
  83. /// class made specifically for use as a settings object.</remarks>
  84. /// </summary>
  85. /// <param name="container">The object to add.</param>
  86. void AddOptionContainer(object container);
  87. /// <summary>
  88. /// Remove all properties and methods that the <paramref name="container"/> added to the options panel.
  89. /// </summary>
  90. /// <param name="container">The container to remove.</param>
  91. void RemoveOptionContainer(object container);
  92. /// <summary>
  93. /// Add an option to the options panel.
  94. /// </summary>
  95. void AddOption(OptionDefinition option);
  96. /// <summary>
  97. /// Remove an option from the options panel.
  98. /// </summary>
  99. /// <returns>True if option was successfully removed, otherwise false.</returns>
  100. bool RemoveOption(OptionDefinition option);
  101. /// <summary>
  102. /// Pin all options in a category.
  103. /// </summary>
  104. /// <param name="category"></param>
  105. void PinAllOptions(string category);
  106. /// <summary>
  107. /// Unpin all options in a category.
  108. /// </summary>
  109. /// <param name="category"></param>
  110. void UnpinAllOptions(string category);
  111. void PinOption(string name);
  112. void UnpinOption(string name);
  113. /// <summary>
  114. /// Clear all pinned options.
  115. /// </summary>
  116. void ClearPinnedOptions();
  117. /// <summary>
  118. /// Open a bug report sheet.
  119. /// </summary>
  120. /// <param name="onComplete">Callback to invoke once the bug report is completed or cancelled. Null to ignore.</param>
  121. /// <param name="takeScreenshot">
  122. /// Take a screenshot before opening the report sheet (otherwise a screenshot will be taken as
  123. /// the report is sent, if enabled in settings)
  124. /// </param>
  125. /// <param name="descriptionContent">Initial content of the bug report description</param>
  126. void ShowBugReportSheet(ActionCompleteCallback onComplete = null, bool takeScreenshot = true,
  127. string descriptionContent = null);
  128. /// <summary>
  129. /// Event invoked whenever the debug panel opens or closes
  130. /// </summary>
  131. event VisibilityChangedDelegate PanelVisibilityChanged;
  132. event PinnedUiCanvasCreated PinnedUiCanvasCreated;
  133. /// <summary>
  134. /// ADVANCED FEATURE. This will convert the debug panel to a world space object and return the RectTransform.
  135. /// This can be used to position the SRDebugger panel somewhere in your scene.
  136. /// This feature is for advanced users only who know what they are doing. Only limited support will be provided
  137. /// for this method.
  138. /// The debug panel will be made visible if it is not already.
  139. /// </summary>
  140. /// <returns>The debug panel RectTransform.</returns>
  141. RectTransform EnableWorldSpaceMode();
  142. /// <summary>
  143. /// Set a custom bug reporter handler.
  144. /// NOTE: This should be done on startup, ideally before the debug panel is opened.
  145. /// The visibility of the bug report tab will be determined when the debug panel opens so the bug reporter handler
  146. /// should be set before then.
  147. /// </summary>
  148. /// <param name="bugReporterHandler">Custom bug report handler.</param>
  149. void SetBugReporterHandler(IBugReporterHandler bugReporterHandler);
  150. }
  151. }
  152. namespace SRDebugger
  153. {
  154. public delegate void VisibilityChangedDelegate(bool isVisible);
  155. public delegate void ActionCompleteCallback(bool success);
  156. public delegate void PinnedUiCanvasCreated(RectTransform canvasTransform);
  157. public struct EntryCode : IReadOnlyList<int>
  158. {
  159. public readonly int Digit1;
  160. public readonly int Digit2;
  161. public readonly int Digit3;
  162. public readonly int Digit4;
  163. public EntryCode(int digit1, int digit2, int digit3, int digit4)
  164. {
  165. if (digit1 < 0 || digit1 > 9) throw new ArgumentException("Pin digit must be between 0 and 9", "digit1");
  166. if (digit2 < 0 || digit2 > 9) throw new ArgumentException("Pin digit must be between 0 and 9", "digit2");
  167. if (digit3 < 0 || digit3 > 9) throw new ArgumentException("Pin digit must be between 0 and 9", "digit3");
  168. if (digit4 < 0 || digit4 > 9) throw new ArgumentException("Pin digit must be between 0 and 9", "digit4");
  169. Digit1 = digit1;
  170. Digit2 = digit2;
  171. Digit3 = digit3;
  172. Digit4 = digit4;
  173. }
  174. public IEnumerator<int> GetEnumerator()
  175. {
  176. return new List<int> { Digit1, Digit2, Digit3, Digit4 }.GetEnumerator();
  177. }
  178. IEnumerator IEnumerable.GetEnumerator()
  179. {
  180. return GetEnumerator();
  181. }
  182. public int Count
  183. {
  184. get { return 4; }
  185. }
  186. public int this[int index]
  187. {
  188. get
  189. {
  190. switch (index)
  191. {
  192. case 0: return Digit1;
  193. case 1: return Digit2;
  194. case 2: return Digit3;
  195. case 3: return Digit4;
  196. default: throw new ArgumentOutOfRangeException("index");
  197. }
  198. }
  199. }
  200. }
  201. }