void AddNativeUnityObject(TreeViewItem parent, PackedNativeUnityEngineObject nativeObject) { var item = new NativeObjectItem { id = m_UniqueId++, depth = parent.depth + 1, }; item.Initialize(this, m_Snapshot, nativeObject); parent.AddChild(item); }
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); }
public TreeViewItem BuildTree(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); } // int=typeIndex var groupLookup = new Dictionary <long, GroupItem>(); for (int n = 0, nend = m_Snapshot.nativeObjects.Length; n < nend; ++n) { var no = m_Snapshot.nativeObjects[n]; if (!buildArgs.CanAdd(no)) { continue; } GroupItem group; if (!groupLookup.TryGetValue(no.nativeTypesArrayIndex, out group)) { group = new GroupItem { id = m_UniqueId++, depth = root.depth + 1, displayName = "" }; group.Initialize(m_Snapshot, no.nativeTypesArrayIndex); groupLookup[no.nativeTypesArrayIndex] = group; root.AddChild(group); } var typeNameOverride = ""; // Derived MonoBehaviour types appear just as MonoBehaviour on the native side. // This is not very informative. However, the actual name can be derived from the MonoScript of such MonoBehaviour instead. // The following tries to find the corresponding MonoScript and uses the MonoScript name instead. #region Add MonoBehaviour using name of MonoScript if (no.nativeTypesArrayIndex == m_Snapshot.coreTypes.nativeMonoBehaviour || no.nativeTypesArrayIndex == m_Snapshot.coreTypes.nativeScriptableObject) { string monoScriptName; var monoScriptIndex = m_Snapshot.FindNativeMonoScriptType(no.nativeObjectsArrayIndex, out monoScriptName); if (monoScriptIndex != -1 && monoScriptIndex < m_Snapshot.nativeTypes.Length) { typeNameOverride = monoScriptName; long key = (monoScriptName.GetHashCode() << 32) | monoScriptIndex; GroupItem group2; if (!groupLookup.TryGetValue(key, out group2)) { group2 = new GroupItem { id = m_UniqueId++, depth = group.depth + 1, //displayName = monoScriptName, typeNameOverride = monoScriptName, }; group2.Initialize(m_Snapshot, no.nativeTypesArrayIndex); groupLookup[key] = group2; group.AddChild(group2); } group = group2; } } #endregion var item = new NativeObjectItem { id = m_UniqueId++, depth = group.depth + 1, displayName = "", typeNameOverride = typeNameOverride }; item.Initialize(this, no); m_NativeObjectsCount++; m_NativeObjectsSize += item.size; group.AddChild(item); } // remove groups if it contains one item only if (root.hasChildren) { for (int n = root.children.Count - 1; n >= 0; --n) { var group = root.children[n]; if (group.children.Count == 1) { group.children[0].depth -= 1; root.AddChild(group.children[0]); root.children.RemoveAt(n); } } } SortItemsRecursive(root, OnSortItem); if (!root.hasChildren) { root.AddChild(new TreeViewItem { id = 1, depth = -1, displayName = "" }); } return(root); }