2using System.Diagnostics;
4using System.Reflection;
10 internal static class SceneDumper
12 public static void DumpObjects(params GameObject[] objects)
14 var fname = Path.GetTempFileName() +
".txt";
15 RuntimeUnityEditorCore.Logger.Log(
LogLevel.Info,
16 string.Format(
"Dumping {0} GameObjects to {1}", objects.Length, fname));
17 using (var f =
File.OpenWrite(fname))
18 using (var sw =
new StreamWriter(f, Encoding.UTF8))
20 foreach (var obj
in objects)
21 PrintRecursive(sw, obj);
23 var pi =
new ProcessStartInfo(fname) { UseShellExecute =
true };
24 RuntimeUnityEditorCore.Logger.Log(
LogLevel.Info,
string.Format(
"Opening {0}", fname));
28 private static void PrintRecursive(TextWriter sw, GameObject obj,
int d = 0)
30 if (obj ==
null)
return;
32 var pad1 =
new string(
' ', 3 * d);
33 var pad2 =
new string(
' ', 3 * (d + 1));
34 var pad3 =
new string(
' ', 3 * (d + 2));
35 sw.WriteLine(pad1 + obj.name +
"--" + obj.GetType().FullName);
37 foreach (var c
in obj.GetComponents<
Component>())
39 sw.WriteLine(pad2 +
"::" + c.GetType().Name);
42 var props = ct.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
43 foreach (var p
in props)
47 var v = p.GetValue(c,
null);
48 sw.WriteLine(pad3 +
"@" + p.Name +
"<" + p.PropertyType.Name +
"> = " + v);
52 RuntimeUnityEditorCore.Logger.Log(
LogLevel.Debug, e);
56 foreach (Transform t
in obj.transform)
57 PrintRecursive(sw, t.gameObject, d + 1);
UnityEngine.Component Component
RuntimeUnityEditor.Core.LogLevel LogLevel