SceneDumper.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using BepInEx;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using TMPro;
  9. using UnityEngine;
  10. using UnityEngine.SceneManagement;
  11. namespace SceneDumper
  12. {
  13. class SceneDumper : BaseUnityPlugin
  14. {
  15. public override string Name => "Scene Dumper";
  16. void OnUpdate()
  17. {
  18. if (UnityEngine.Event.current.Equals(Event.KeyboardEvent("f8")))
  19. {
  20. DumpScene();
  21. }
  22. }
  23. static List<string> lines;
  24. public static void DumpScene()
  25. {
  26. lines = new List<string>();
  27. string filename = @"M:\unity-scene.txt";
  28. Debug.Log("Dumping scene to " + filename + " ...");
  29. using (StreamWriter writer = new StreamWriter(filename, false))
  30. {
  31. foreach (GameObject gameObject in GameObject.FindObjectsOfType<GameObject>())
  32. {
  33. if (gameObject.activeInHierarchy)
  34. DumpGameObject(gameObject, writer, "");
  35. }
  36. foreach (string line in lines)
  37. {
  38. writer.WriteLine(line);
  39. }
  40. }
  41. Debug.Log("Scene dumped to " + filename);
  42. }
  43. private static void DumpGameObject(GameObject gameObject, StreamWriter writer, string indent)
  44. {
  45. //writer.WriteLine("{0}+{1}+{2}", indent, gameObject.name, gameObject.GetType().FullName);
  46. foreach (Component component in gameObject.GetComponents<Component>())
  47. {
  48. DumpComponent(component, writer, indent + " ");
  49. }
  50. foreach (Transform child in gameObject.transform)
  51. {
  52. DumpGameObject(child.gameObject, writer, indent + " ");
  53. }
  54. }
  55. private static void DumpComponent(Component component, StreamWriter writer, string indent)
  56. {
  57. //writer.WriteLine("{0}{1}", indent, (component == null ? "(null)" : component.GetType().FullName));
  58. if (component is TextMeshProUGUI)
  59. {
  60. string text = ((TextMeshProUGUI)component).text;
  61. if (text.Trim() != ""
  62. && !text.Contains("Reset")
  63. && Regex.Replace(text, @"[\d-]", string.Empty).Trim() != "")
  64. {
  65. if (!lines.Contains(text))
  66. lines.Add(text);
  67. }
  68. }
  69. }
  70. }
  71. }