Example #1
0
 void LoadFromMindMap(string fileName)
 {
     //data = null;  //reset data
     using (FileStream stream = new FileStream(fileName, FileMode.Open))
     {
         using (StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8))
         {
             Stack <PackedItemNode> stack = new Stack <PackedItemNode>();
             int lastTabCount             = 0;
             while (reader.Peek() >= 0)
             {
                 int    tabCount   = 0;
                 int    spaceIndex = 0;
                 string line       = reader.ReadLine();
                 char[] charArray  = line.ToCharArray();
                 for (int i = 0; i < charArray.Length; i++)
                 {
                     if (charArray[i] == '\t')
                     {
                         tabCount++;
                         continue;
                     }
                     else if (charArray[i] == ' ')
                     {
                         spaceIndex = i;
                     }
                 }
                 string         itemName = line.Substring(tabCount, spaceIndex - tabCount);
                 string         sizeStr  = line.Substring(spaceIndex + 1);
                 PackedItemNode node     = new PackedItemNode(itemName);
                 node.sizeStr = sizeStr;
                 if (tabCount == 0 && lastTabCount == 0)
                 {
                     memoryRootNode = node;
                 }
                 else if (tabCount < lastTabCount)
                 {
                     while (lastTabCount-- > tabCount)
                     {
                         stack.Pop();
                     }
                     stack.Pop();
                     stack.Peek().AddNode(node);
                 }
                 else if (tabCount > lastTabCount)
                 {
                     stack.Peek().AddNode(node);
                 }
                 else
                 {
                     stack.Pop();
                     stack.Peek().AddNode(node);
                 }
                 stack.Push(node);
                 lastTabCount = tabCount;
             }
             memoryRootNode.SetCount();
             //memoryRootNode.Convert();
             //memoryRootNode.Sort();
         }
     }
 }
Example #2
0
        void IncomingSnapshot(PackedMemorySnapshot snapshot)
        {
            if (null == snapshot)
            {
                return;
            }
            lastRefreshTime = DateTime.Now;
            Debug.Log("GoProfilerWindow.IncomingSnapshot");
            data.mSnapshot = snapshot;
            memoryRootNode = new PackedItemNode("Root");
            PackedItemNode assetsRoot           = new PackedItemNode("Assets");
            PackedItemNode sceneMemoryRoot      = new PackedItemNode("SceneMemory");
            PackedItemNode notSavedRoot         = new PackedItemNode("NotSaved");
            PackedItemNode builtinResourcesRoot = new PackedItemNode("BuiltinResources");
            PackedItemNode unknownRoot          = new PackedItemNode("Unknown");

            //PackedItemNode managerNode = PackedItemNode.BuildNode<PackedItemNode>("Managers");
            memoryRootNode.AddNode(assetsRoot);
            memoryRootNode.AddNode(sceneMemoryRoot);
            memoryRootNode.AddNode(notSavedRoot);
            memoryRootNode.AddNode(builtinResourcesRoot);
            //assetsRoot.AddNode(managerNode);
            Dictionary <int, Group> assetGroup                         = new Dictionary <int, Group>();
            Dictionary <int, Group> sceneMemoryGroup                   = new Dictionary <int, Group>();
            Dictionary <int, Group> notSavedGroup                      = new Dictionary <int, Group>();
            Dictionary <int, Group> builtinResourcesGroup              = new Dictionary <int, Group>();
            Dictionary <int, Group> unknownGroup                       = new Dictionary <int, Group>();//I can't find any unknown object yet.
            List <PackedNativeUnityEngineObject> assetsObjectList      = new List <PackedNativeUnityEngineObject>();
            List <PackedNativeUnityEngineObject> sceneMemoryObjectList = new List <PackedNativeUnityEngineObject>();
            List <PackedNativeUnityEngineObject> notSavedObjectList    = new List <PackedNativeUnityEngineObject>();
            List <PackedNativeUnityEngineObject> builtinResourcesList  = new List <PackedNativeUnityEngineObject>();
            List <PackedNativeUnityEngineObject> unknownObjectList     = new List <PackedNativeUnityEngineObject>();

            //List<PackedNativeUnityEngineObject> managerList = new List<PackedNativeUnityEngineObject>();
            for (int i = 0; i < snapshot.nativeObjects.Length; i++)
            {
                PackedNativeUnityEngineObject obj = snapshot.nativeObjects[i];
                if (obj.isPersistent && ((obj.hideFlags & HideFlags.DontUnloadUnusedAsset) == 0))
                {
                    assetsObjectList.Add(obj);
                }
                else if (!obj.isPersistent && obj.hideFlags == HideFlags.None)
                {
                    sceneMemoryObjectList.Add(obj);
                }
                else if (!obj.isPersistent && (obj.hideFlags & HideFlags.HideAndDontSave) != 0)
                {
                    notSavedObjectList.Add(obj);
                }
                else if (obj.isPersistent && (obj.hideFlags & HideFlags.HideAndDontSave) != 0)
                {
                    builtinResourcesList.Add(obj);
                }
                else
                {
                    unknownObjectList.Add(obj);
                }
            }
            if (unknownObjectList.Count > 0)//I can't find any unknown object yet.
            {
                memoryRootNode.AddNode(unknownRoot);
            }
            for (int i = 0; i < assetsObjectList.Count; i++)
            {
                PackedNativeUnityEngineObject assetsObject = assetsObjectList[i];
                if (!assetGroup.ContainsKey(assetsObject.nativeTypeArrayIndex))
                {
                    assetGroup.Add(assetsObject.nativeTypeArrayIndex, new Group(assetsObject.nativeTypeArrayIndex, data.mSnapshot.nativeTypes[assetsObject.nativeTypeArrayIndex].name));
                }
                assetGroup[assetsObject.nativeTypeArrayIndex].packedNativeObjectList.Add(assetsObject);
            }
            for (int i = 0; i < sceneMemoryObjectList.Count; i++)
            {
                PackedNativeUnityEngineObject sceneObject = sceneMemoryObjectList[i];
                if (!sceneMemoryGroup.ContainsKey(sceneObject.nativeTypeArrayIndex))
                {
                    sceneMemoryGroup.Add(sceneObject.nativeTypeArrayIndex, new Group(sceneObject.nativeTypeArrayIndex, data.mSnapshot.nativeTypes[sceneObject.nativeTypeArrayIndex].name));
                }
                sceneMemoryGroup[sceneObject.nativeTypeArrayIndex].packedNativeObjectList.Add(sceneObject);
            }
            for (int i = 0; i < notSavedObjectList.Count; i++)
            {
                PackedNativeUnityEngineObject notSavedObject = notSavedObjectList[i];
                if (!notSavedGroup.ContainsKey(notSavedObject.nativeTypeArrayIndex))
                {
                    notSavedGroup.Add(notSavedObject.nativeTypeArrayIndex, new Group(notSavedObject.nativeTypeArrayIndex, data.mSnapshot.nativeTypes[notSavedObject.nativeTypeArrayIndex].name));
                }
                notSavedGroup[notSavedObject.nativeTypeArrayIndex].packedNativeObjectList.Add(notSavedObject);
            }
            for (int i = 0; i < builtinResourcesList.Count; i++)
            {
                PackedNativeUnityEngineObject builtinResourcesObject = builtinResourcesList[i];
                if (!builtinResourcesGroup.ContainsKey(builtinResourcesObject.nativeTypeArrayIndex))
                {
                    builtinResourcesGroup.Add(builtinResourcesObject.nativeTypeArrayIndex, new Group(builtinResourcesObject.nativeTypeArrayIndex, data.mSnapshot.nativeTypes[builtinResourcesObject.nativeTypeArrayIndex].name));
                }
                builtinResourcesGroup[builtinResourcesObject.nativeTypeArrayIndex].packedNativeObjectList.Add(builtinResourcesObject);
            }
            for (int i = 0; i < unknownObjectList.Count; i++)
            {
                PackedNativeUnityEngineObject unknownObject = unknownObjectList[i];
                if (!unknownGroup.ContainsKey(unknownObject.nativeTypeArrayIndex))
                {
                    unknownGroup.Add(unknownObject.nativeTypeArrayIndex, new Group(unknownObject.nativeTypeArrayIndex, data.mSnapshot.nativeTypes[unknownObject.nativeTypeArrayIndex].name));
                }
                unknownGroup[unknownObject.nativeTypeArrayIndex].packedNativeObjectList.Add(unknownObject);
            }
            using (var i = assetGroup.GetEnumerator())//replace foreach
            {
                while (i.MoveNext())
                {
                    Group group = i.Current.Value;
                    SetNodeByClassID(group.classId, group.itemNode, group.packedNativeObjectList);
                    if (group.itemNode != null)
                    {
                        assetsRoot.AddNode(group.itemNode);
                    }
                }
            }
            using (var i = sceneMemoryGroup.GetEnumerator())//replace foreach
            {
                while (i.MoveNext())
                {
                    Group group = i.Current.Value;
                    SetNodeByClassID(group.classId, group.itemNode, group.packedNativeObjectList);
                    if (group.itemNode != null)
                    {
                        sceneMemoryRoot.AddNode(group.itemNode);
                    }
                }
            }
            using (var i = notSavedGroup.GetEnumerator())//replace foreach
            {
                while (i.MoveNext())
                {
                    Group group = i.Current.Value;
                    SetNodeByClassID(group.classId, group.itemNode, group.packedNativeObjectList);
                    if (group.itemNode != null)
                    {
                        notSavedRoot.AddNode(group.itemNode);
                    }
                }
            }
            using (var i = builtinResourcesGroup.GetEnumerator())//replace foreach
            {
                while (i.MoveNext())
                {
                    Group group = i.Current.Value;
                    SetNodeByClassID(group.classId, group.itemNode, group.packedNativeObjectList);
                    if (group.itemNode != null)
                    {
                        builtinResourcesRoot.AddNode(group.itemNode);
                    }
                }
            }
            using (var i = unknownGroup.GetEnumerator())//replace foreach
            {
                while (i.MoveNext())
                {
                    Group group = i.Current.Value;
                    SetNodeByClassID(group.classId, group.itemNode, group.packedNativeObjectList);
                    if (group.itemNode != null)
                    {
                        unknownRoot.AddNode(group.itemNode);
                    }
                }
            }
            memoryRootNode.SetCount();
            memoryRootNode.Convert();
            memoryRootNode.Sort();
            //ClearEditorReferences();//To release gc and memory.
            RemoveNotification();
        }