/// <summary> /// Dump world to the given folder. /// </summary> /// <param name="folder">The folder without trailing slash to dump world to - /// must exists.</param> public void Dump(string folder) { UnityEngine.Object[] objects = Resources.FindObjectsOfTypeAll <UnityEngine.Object>(); cssStylePath = $"{folder}/style.css"; WriteStyles(); HTMLWriter.WriteDocument( $"{folder}/index.html", "INDEX", cssStylePath, (HTMLWriter writer) => { writer.StartTag("table"); writer.StartTag("tr"); { writer.OneLiner("td", "#"); writer.OneLiner("td", "Name"); writer.OneLiner("td", "Type"); } writer.EndTag(); int index = 1; foreach (var obj in objects) { if (CanSkipObject(obj)) { continue; } writer.StartTag("tr"); { writer.OneLiner("td", index.ToString()); string objectFile = DumpObject(obj, folder, writer.FileName); writer.StartTag("td"); { writer.Link(objectFile, ((obj.name.Trim().Length > 0) ? obj.name : "NO NAME")); } writer.EndTag(); writer.StartTag("td"); { writer.WriteValue(obj.GetType().Name); } writer.EndTag(); } writer.EndTag(); ++index; System.GC.Collect(); } writer.EndTag(); }); }
string DumpObject( UnityEngine.Object obj, string folder, string previousFile = "") { Directory.CreateDirectory(folder); DumpObjectDelegate bestDumpDelegate = null; foreach (var kv in dumpMethods) { if (kv.Key.GetHashCode() == obj.GetType().GetHashCode()) { bestDumpDelegate = kv.Value; break; } if (obj.GetType().IsSubclassOf(kv.Key)) { bestDumpDelegate = kv.Value; } } try { if (bestDumpDelegate != null) { string fileName = $"{folder}/{BuildFileName(obj)}"; HTMLWriter.WriteDocument(fileName, $"{obj.name} - {obj.GetType().FullName}", cssStylePath, (HTMLWriter writer) => { writer.Link(previousFile, "< GO BACK"); writer.NewLine(); writer.OneLiner("h1", obj.name); writer.OneLiner("b", $"Type: {obj.GetType().FullName}"); writer.ShortTag("hr"); bestDumpDelegate.Invoke(obj, writer, this, folder); }); return(fileName); } } catch (Exception e) { Logger.Error("Failed to dump object!"); Logger.Error(e.Message); Logger.Error(e.StackTrace); return($"#exception_{e.Message}"); } return("#failed_to_generate_file"); }