Tanoda
SceneDumper.cs
Go to the documentation of this file.
1using System;
2using System.Diagnostics;
3using System.IO;
4using System.Reflection;
5using System.Text;
6using UnityEngine;
7
9{
10 internal static class SceneDumper
11 {
12 public static void DumpObjects(params GameObject[] objects)
13 {
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))
19 {
20 foreach (var obj in objects)
21 PrintRecursive(sw, obj);
22 }
23 var pi = new ProcessStartInfo(fname) { UseShellExecute = true };
24 RuntimeUnityEditorCore.Logger.Log(LogLevel.Info, string.Format("Opening {0}", fname));
25 Process.Start(pi);
26 }
27
28 private static void PrintRecursive(TextWriter sw, GameObject obj, int d = 0)
29 {
30 if (obj == null) return;
31
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);
36
37 foreach (var c in obj.GetComponents<Component>())
38 {
39 sw.WriteLine(pad2 + "::" + c.GetType().Name);
40
41 var ct = c.GetType();
42 var props = ct.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);
43 foreach (var p in props)
44 {
45 try
46 {
47 var v = p.GetValue(c, null);
48 sw.WriteLine(pad3 + "@" + p.Name + "<" + p.PropertyType.Name + "> = " + v);
49 }
50 catch (Exception e)
51 {
52 RuntimeUnityEditorCore.Logger.Log(LogLevel.Debug, e);
53 }
54 }
55 }
56 foreach (Transform t in obj.transform)
57 PrintRecursive(sw, t.gameObject, d + 1);
58 }
59 }
60}
UnityEngine.Component Component
RuntimeUnityEditor.Core.LogLevel LogLevel
Definition: RUEInvoker.cs:5