private static void DumpGameObjectRecursive(StringBuilder str, Transform tx, int indent, bool includeComponents = false)
 {
     if (tx == null)
     {
         return;
     }
     for (int i = 0; i < indent; i++)
     {
         str.Append(" ");
     }
     str.AppendFormat("{0} {1:N0}", tx.name, (int)tx.GetComponents <Component>().Length - 1);
     str.AppendLine();
     if (includeComponents)
     {
         Component[] components = tx.GetComponents <Component>();
         for (int j = 0; j < (int)components.Length; j++)
         {
             Component component = components[j];
             if (!(component is Transform))
             {
                 for (int k = 0; k < indent + 1; k++)
                 {
                     str.Append(" ");
                 }
                 str.AppendFormat("[c] {0}", (component == null ? "NULL" : component.GetType().ToString()));
                 str.AppendLine();
             }
         }
     }
     for (int l = 0; l < tx.childCount; l++)
     {
         DiagnosticsConSys.DumpGameObjectRecursive(str, tx.GetChild(l), indent + 2, includeComponents);
     }
 }
    private static void DumpGameObjects(string targetFolder)
    {
        int i;

        Transform[]   rootObjects   = TransformUtil.GetRootObjects();
        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.AppendLine("All active game objects");
        stringBuilder.AppendLine();
        Transform[] transformArrays = rootObjects;
        for (i = 0; i < (int)transformArrays.Length; i++)
        {
            DiagnosticsConSys.DumpGameObjectRecursive(stringBuilder, transformArrays[i], 0, false);
            stringBuilder.AppendLine();
        }
        DiagnosticsConSys.WriteTextToFile(string.Concat(targetFolder, "GameObject.Hierarchy.txt"), stringBuilder.ToString());
        stringBuilder = new StringBuilder();
        stringBuilder.AppendLine("All active game objects including components");
        stringBuilder.AppendLine();
        transformArrays = rootObjects;
        for (i = 0; i < (int)transformArrays.Length; i++)
        {
            DiagnosticsConSys.DumpGameObjectRecursive(stringBuilder, transformArrays[i], 0, true);
            stringBuilder.AppendLine();
        }
        DiagnosticsConSys.WriteTextToFile(string.Concat(targetFolder, "GameObject.Hierarchy.Components.txt"), stringBuilder.ToString());
        stringBuilder = new StringBuilder();
        stringBuilder.AppendLine("Root gameobjects, grouped by name, ordered by the total number of objects excluding children");
        stringBuilder.AppendLine();
        foreach (IGrouping <string, Transform> strs in
                 from x in (IEnumerable <Transform>) rootObjects
                 group x by x.name into x
                 orderby x.Count <Transform>() descending
                 select x)
        {
            Transform transforms = strs.First <Transform>();
            stringBuilder.AppendFormat("{1:N0}\t{0}", transforms.name, strs.Count <Transform>());
            stringBuilder.AppendLine();
        }
        DiagnosticsConSys.WriteTextToFile(string.Concat(targetFolder, "GameObject.Count.txt"), stringBuilder.ToString());
        stringBuilder = new StringBuilder();
        stringBuilder.AppendLine("Root gameobjects, grouped by name, ordered by the total number of objects including children");
        stringBuilder.AppendLine();
        foreach (KeyValuePair <Transform, int> keyValuePair in
                 from x in (IEnumerable <Transform>) rootObjects
                 group x by x.name into x
                 select new KeyValuePair <Transform, int>(x.First <Transform>(), x.Sum <Transform>((Transform y) => y.GetAllChildren().Count)) into x
                 orderby x.Value descending
                 select x)
        {
            stringBuilder.AppendFormat("{1:N0}\t{0}", keyValuePair.Key.name, keyValuePair.Value);
            stringBuilder.AppendLine();
        }
        DiagnosticsConSys.WriteTextToFile(string.Concat(targetFolder, "GameObject.Count.Children.txt"), stringBuilder.ToString());
    }
    private static void DumpGameObjects(string targetFolder)
    {
        Transform[]   rootObjects = TransformUtil.GetRootObjects();
        StringBuilder str1        = new StringBuilder();

        str1.AppendLine("All active game objects");
        str1.AppendLine();
        foreach (Transform tx in rootObjects)
        {
            DiagnosticsConSys.DumpGameObjectRecursive(str1, tx, 0, false);
            str1.AppendLine();
        }
        DiagnosticsConSys.WriteTextToFile(targetFolder + "GameObject.Hierarchy.txt", str1.ToString());
        StringBuilder str2 = new StringBuilder();

        str2.AppendLine("All active game objects including components");
        str2.AppendLine();
        foreach (Transform tx in rootObjects)
        {
            DiagnosticsConSys.DumpGameObjectRecursive(str2, tx, 0, true);
            str2.AppendLine();
        }
        DiagnosticsConSys.WriteTextToFile(targetFolder + "GameObject.Hierarchy.Components.txt", str2.ToString());
        StringBuilder stringBuilder1 = new StringBuilder();

        stringBuilder1.AppendLine("Root gameobjects, grouped by name, ordered by the total number of objects excluding children");
        stringBuilder1.AppendLine();
        using (IEnumerator <IGrouping <string, Transform> > enumerator = ((IEnumerable <IGrouping <string, Transform> >)((IEnumerable <Transform>)rootObjects).GroupBy <Transform, string>((Func <Transform, string>)(x => ((Object)x).get_name())).OrderByDescending <IGrouping <string, Transform>, int>((Func <IGrouping <string, Transform>, int>)(x => ((IEnumerable <Transform>)x).Count <Transform>()))).GetEnumerator())
        {
            while (((IEnumerator)enumerator).MoveNext())
            {
                IGrouping <string, Transform> current = enumerator.Current;
                Transform transform = ((IEnumerable <Transform>)current).First <Transform>();
                stringBuilder1.AppendFormat("{1:N0}\t{0}", (object)((Object)transform).get_name(), (object)((IEnumerable <Transform>)current).Count <Transform>());
                stringBuilder1.AppendLine();
            }
        }
        DiagnosticsConSys.WriteTextToFile(targetFolder + "GameObject.Count.txt", stringBuilder1.ToString());
        StringBuilder stringBuilder2 = new StringBuilder();

        stringBuilder2.AppendLine("Root gameobjects, grouped by name, ordered by the total number of objects including children");
        stringBuilder2.AppendLine();
        using (IEnumerator <KeyValuePair <Transform, int> > enumerator = ((IEnumerable <KeyValuePair <Transform, int> >)((IEnumerable <Transform>)rootObjects).GroupBy <Transform, string>((Func <Transform, string>)(x => ((Object)x).get_name())).Select <IGrouping <string, Transform>, KeyValuePair <Transform, int> >((Func <IGrouping <string, Transform>, KeyValuePair <Transform, int> >)(x => new KeyValuePair <Transform, int>(((IEnumerable <Transform>)x).First <Transform>(), ((IEnumerable <Transform>)x).Sum <Transform>((Func <Transform, int>)(y => y.GetAllChildren().Count))))).OrderByDescending <KeyValuePair <Transform, int>, int>((Func <KeyValuePair <Transform, int>, int>)(x => x.Value))).GetEnumerator())
        {
            while (((IEnumerator)enumerator).MoveNext())
            {
                KeyValuePair <Transform, int> current = enumerator.Current;
                stringBuilder2.AppendFormat("{1:N0}\t{0}", (object)((Object)current.Key).get_name(), (object)current.Value);
                stringBuilder2.AppendLine();
            }
        }
        DiagnosticsConSys.WriteTextToFile(targetFolder + "GameObject.Count.Children.txt", stringBuilder2.ToString());
    }
 private static void DumpGameObjectRecursive(
     StringBuilder str,
     Transform tx,
     int indent,
     bool includeComponents = false)
 {
     if (Object.op_Equality((Object)tx, (Object)null))
     {
         return;
     }
     for (int index = 0; index < indent; ++index)
     {
         str.Append(" ");
     }
     str.AppendFormat("{0} {1:N0}", (object)((Object)tx).get_name(), (object)(((Component)tx).GetComponents <Component>().Length - 1));
     str.AppendLine();
     if (includeComponents)
     {
         foreach (Component component in (Component[])((Component)tx).GetComponents <Component>())
         {
             if (!(component is Transform))
             {
                 for (int index = 0; index < indent + 1; ++index)
                 {
                     str.Append(" ");
                 }
                 str.AppendFormat("[c] {0}", Object.op_Equality((Object)component, (Object)null) ? (object)"NULL" : (object)((object)component).GetType().ToString());
                 str.AppendLine();
             }
         }
     }
     for (int index = 0; index < tx.get_childCount(); ++index)
     {
         DiagnosticsConSys.DumpGameObjectRecursive(str, tx.GetChild(index), indent + 2, includeComponents);
     }
 }