Ejemplo n.º 1
0
        void AddManagedObject(TreeViewItem parent, PackedManagedObject managedObject)
        {
            var item = new ManagedObjectItem
            {
                id    = m_UniqueId++,
                depth = parent.depth + 1
            };

            item.Initialize(this, m_Snapshot, managedObject.managedObjectsArrayIndex);
            parent.AddChild(item);
        }
Ejemplo n.º 2
0
        protected virtual void OnBuildTree(TreeViewItem root)
        {
            // int=typeIndex
            var groupLookup = new Dictionary <int, GroupItem>();

            for (int n = 0, nend = m_Snapshot.managedObjects.Length; n < nend; ++n)
            {
                if (window.isClosing) // the window is closing
                {
                    break;
                }

                var mo = m_Snapshot.managedObjects[n];
                if (!OnCanAddObject(mo))
                {
                    continue;
                }

                GroupItem group;
                if (!groupLookup.TryGetValue(mo.managedTypesArrayIndex, out group))
                {
                    group = new GroupItem
                    {
                        id          = m_UniqueId++,
                        depth       = 0,
                        displayName = ""
                    };
                    group.Initialize(m_Snapshot, m_Snapshot.managedTypes[mo.managedTypesArrayIndex]);

                    groupLookup[mo.managedTypesArrayIndex] = group;
                    root.AddChild(group);
                }

                var item = new ManagedObjectItem
                {
                    id          = m_UniqueId++,
                    depth       = group.depth + 1,
                    displayName = ""
                };
                item.Initialize(this, m_Snapshot, mo);

                group.AddChild(item);

                m_ManagedObjectCount++;
                m_ManagedObjectSize += item.size;
            }
        }
        protected override void OnBuildTree(TreeViewItem root)
        {
            progress.value = 0;

            var lookup       = new Dictionary <Hash128, AbstractItem>();
            var memoryReader = new MemoryReader(m_Snapshot);

            for (int n = 0, nend = m_Snapshot.managedObjects.Length; n < nend; ++n)
            {
                if (window.isClosing) // the window is closing
                {
                    break;
                }

                progress.value = (n + 1.0f) / nend;

                var obj = m_Snapshot.managedObjects[n];
                if (obj.address == 0)
                {
                    continue;
                }

                var type = m_Snapshot.managedTypes[obj.managedTypesArrayIndex];
                if (type.isPrimitive && !type.isPointer)
                {
                    continue;
                }

                if (type.isValueType)
                {
                    continue;
                }

                var hash = memoryReader.ComputeObjectHash(obj.address, type);

                AbstractItem parent;
                if (!lookup.TryGetValue(hash, out parent))
                {
                    var group = new GroupItem()
                    {
                        id          = m_UniqueId++,
                        depth       = root.depth + 1,
                        displayName = ""
                    };
                    group.Initialize(m_Snapshot, type);

                    lookup[hash] = parent = group;
                    root.AddChild(group);
                }

                var item = new ManagedObjectItem
                {
                    id          = m_UniqueId++,
                    depth       = parent.depth + 1,
                    displayName = ""
                };
                item.Initialize(this, m_Snapshot, obj);
                parent.AddChild(item);
            }

            if (root.hasChildren)
            {
                for (var n = root.children.Count - 1; n >= 0; --n)
                {
                    if (!root.children[n].hasChildren)
                    {
                        root.children.RemoveAt(n);
                        continue;
                    }

                    if (root.children[n].children.Count < 2)
                    {
                        root.children.RemoveAt(n);
                        continue;
                    }

                    var item = root.children[n] as AbstractItem;
                    m_ManagedObjectCount += item.count;
                    m_ManagedObjectSize  += item.size;
                }
            }

            progress.value = 1;
        }
        protected override void OnBuildTree(TreeViewItem root)
        {
            progress.value = 0;

            var lookup       = new Dictionary <string, AbstractItem>();
            var memoryReader = new MemoryReader(m_Snapshot);

            for (int n = 0, nend = m_Snapshot.managedObjects.Length; n < nend; ++n)
            {
                progress.value = (n + 1.0f) / nend;

                var obj = m_Snapshot.managedObjects[n];
                if (obj.address == 0)
                {
                    continue; // points to null
                }
                if (obj.nativeObjectsArrayIndex != -1)
                {
                    continue; // has a native object, thus can't be an empty shell object
                }
                var type = m_Snapshot.managedTypes[obj.managedTypesArrayIndex];

                // Only UnityEngine.Object objects can have a m_CachedPtr connection to a native object.
                if (!type.isUnityEngineObject)
                {
                    continue;
                }

                // Could be an array of an UnityEngine.Object, such as Texture[]
                if (type.isArray)
                {
                    continue;
                }

                // Get type as a "higher level" representation that is easier to work with
                var richType = new RichManagedType(m_Snapshot, obj.managedTypesArrayIndex);

                // Try to get the m_InstanceID field (only exists in editor, not in built players)
                PackedManagedField packedField;
                if (richType.FindField("m_InstanceID", out packedField))
                {
                    // The editor contains various empty shell objects whose instanceID all contain 0.
                    // I guess it's some kind of special object? In this case we just ignore them.
                    var instanceID = memoryReader.ReadInt32(obj.address + (ulong)packedField.offset);
                    if (instanceID == 0)
                    {
                        continue;
                    }
                }

                // Check if we already have a grouping node for that type.
                // Create a new node if we don't have it.
                AbstractItem parent;
                if (!lookup.TryGetValue(type.name, out parent))
                {
                    var group = new GroupItem()
                    {
                        id          = m_UniqueId++,
                        depth       = root.depth + 1,
                        displayName = ""
                    };
                    group.Initialize(m_Snapshot, type);

                    lookup[type.name] = parent = group;
                    root.AddChild(group);
                }

                // Create and add the managed object item
                var item = new ManagedObjectItem
                {
                    id          = m_UniqueId++,
                    depth       = parent.depth + 1,
                    displayName = ""
                };
                item.Initialize(this, m_Snapshot, obj);
                parent.AddChild(item);

                m_ManagedObjectCount++;
                m_ManagedObjectSize += item.size;
            }

            progress.value = 1;
        }