コード例 #1
0
        public static Texture2D GetTypeImage(PackedMemorySnapshot snapshot, PackedManagedType type)
        {
            if (type.isArray)
            {
                return(csReferenceTypeImage);
            }

            if (type.isValueType)
            {
                if (snapshot.IsSubclassOf(type, snapshot.coreTypes.systemEnum))
                {
                    return(csEnumTypeImage);
                }

                return(csValueTypeImage);
            }

            if (snapshot.IsSubclassOf(type, snapshot.coreTypes.systemDelegate))
            {
                return(csDelegateTypeImage);
            }

            return(csReferenceTypeImage);
        }
コード例 #2
0
        public static GUIContent GetTypeContent(PackedMemorySnapshot snapshot, PackedManagedType type)
        {
            const string valueTypeLabel     = "Value types are either stack-allocated or allocated inline in a structure.";
            const string referenceTypeLabel = "Reference types are heap-allocated.";

            if (type.isValueType)
            {
                if (snapshot.IsSubclassOf(type, snapshot.coreTypes.systemEnum))
                {
                    return(new GUIContent(csEnumTypeImage, valueTypeLabel));
                }

                return(new GUIContent(csValueTypeImage, valueTypeLabel));
            }

            return(new GUIContent(csReferenceTypeImage, referenceTypeLabel));
        }
コード例 #3
0
        public TreeViewItem BuildDuplicatesTree(PackedMemorySnapshot snapshot, BuildArgs buildArgs)
        {
            m_Snapshot           = snapshot;
            m_UniqueId           = 1;
            m_NativeObjectsCount = 0;
            m_NativeObjectsSize  = 0;

            var root = new TreeViewItem {
                id = 0, depth = -1, displayName = "Root"
            };

            if (m_Snapshot == null)
            {
                root.AddChild(new TreeViewItem {
                    id = 1, depth = -1, displayName = ""
                });
                return(root);
            }

            var dupesLookup = new Dictionary <Hash128, List <int> >();

            for (int n = 0, nend = m_Snapshot.nativeObjects.Length; n < nend; ++n)
            {
                var no = m_Snapshot.nativeObjects[n];
                if (!no.isPersistent)
                {
                    continue;
                }

                if (!buildArgs.CanAdd(no))
                {
                    continue;
                }

                if (no.nativeTypesArrayIndex == -1)
                {
                    continue;
                }

                var nativeType = m_Snapshot.nativeTypes[no.nativeTypesArrayIndex];
                if (nativeType.managedTypeArrayIndex == -1)
                {
                    continue;
                }

                if (m_Snapshot.IsSubclassOf(m_Snapshot.managedTypes[nativeType.managedTypeArrayIndex], m_Snapshot.coreTypes.unityEngineComponent))
                {
                    continue;
                }

                if (m_Snapshot.IsSubclassOf(m_Snapshot.managedTypes[nativeType.managedTypeArrayIndex], m_Snapshot.coreTypes.unityEngineGameObject))
                {
                    continue;
                }

                var hash = new Hash128((uint)no.nativeTypesArrayIndex, (uint)no.size, (uint)no.name.GetHashCode(), 0);

                List <int> list;
                if (!dupesLookup.TryGetValue(hash, out list))
                {
                    dupesLookup[hash] = list = new List <int>();
                }

                list.Add(n);
            }

            // int=typeIndex
            var groupLookup = new Dictionary <Hash128, GroupItem>();

            foreach (var dupePair in dupesLookup)
            {
                for (int n = 0, nend = dupePair.Value.Count; n < nend; ++n)
                {
                    var list = dupePair.Value;
                    if (list.Count <= 1)
                    {
                        continue;
                    }

                    var no = m_Snapshot.nativeObjects[list[n]];

                    GroupItem group;
                    if (!groupLookup.TryGetValue(dupePair.Key, out group))
                    {
                        group = new GroupItem
                        {
                            id          = m_UniqueId++,
                            depth       = root.depth + 1,
                            displayName = no.name
                        };
                        group.Initialize(m_Snapshot, no.nativeTypesArrayIndex);

                        groupLookup[dupePair.Key] = group;
                        root.AddChild(group);
                    }

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

                    m_NativeObjectsCount++;
                    m_NativeObjectsSize += item.size;

                    group.AddChild(item);
                }
            }

            SortItemsRecursive(root, OnSortItem);

            if (!root.hasChildren)
            {
                root.AddChild(new TreeViewItem {
                    id = 1, depth = -1, displayName = ""
                });
            }

            return(root);
        }