DeveloperConsole.cs 2.3 KB

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