DeveloperConsole.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using BepInEx;
  2. using System;
  3. using UnityEngine;
  4. namespace DeveloperConsole
  5. {
  6. public class DeveloperConsole : BaseUnityPlugin
  7. {
  8. public override string ID => "com.bepis.bepinex.developerconsole";
  9. public override string Name => "Developer Console";
  10. public override Version Version => new Version("1.0.1");
  11. private Rect UI = new Rect(20, 20, 400, 200);
  12. bool showingUI = false;
  13. string TotalLog = "";
  14. int showCounter = 0;
  15. string TotalShowingLog = "";
  16. void Awake()
  17. {
  18. BepInLogger.EntryLogged += (log, show) =>
  19. {
  20. string current = $"{TotalLog}\r\n{log}";
  21. if (current.Length > 2000)
  22. {
  23. current = current.Remove(0, 1000);
  24. }
  25. TotalLog = current;
  26. if (show)
  27. {
  28. if (showCounter == 0)
  29. TotalShowingLog = "";
  30. showCounter = 400;
  31. TotalShowingLog = $"{TotalShowingLog}\r\n{log}";
  32. }
  33. };
  34. }
  35. void Update()
  36. {
  37. if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.F12))
  38. {
  39. showingUI = !showingUI;
  40. }
  41. }
  42. void OnGUI()
  43. {
  44. ShowLog();
  45. if (showingUI)
  46. UI = GUI.Window(Name.GetHashCode() + 0, UI, WindowFunction, "Developer Console");
  47. }
  48. void ShowLog()
  49. {
  50. if (showCounter != 0)
  51. {
  52. showCounter--;
  53. GUI.Label(new Rect(40, 0, 600, 160), TotalShowingLog, new GUIStyle
  54. {
  55. alignment = TextAnchor.UpperLeft,
  56. fontSize = 26,
  57. normal = new GUIStyleState
  58. {
  59. textColor = Color.white
  60. }
  61. });
  62. }
  63. }
  64. void WindowFunction(int windowID)
  65. {
  66. GUI.Label(new Rect(10, 40, 380, 160), TotalLog, new GUIStyle
  67. {
  68. alignment = TextAnchor.LowerLeft,
  69. wordWrap = true,
  70. normal = new GUIStyleState
  71. {
  72. textColor = Color.white
  73. }
  74. });
  75. if (GUI.Button(new Rect(295, 20, 100, 20), "Dump scene"))
  76. {
  77. SceneDumper.DumpScene();
  78. }
  79. GUI.DragWindow();
  80. }
  81. }
  82. }