public void Initialize(RootPathControl owner, PackedMemorySnapshot snapshot, PackedNativeUnityEngineObject nativeObject) { m_Owner = owner; m_Snapshot = snapshot; m_NativeObject = new RichNativeObject(snapshot, nativeObject.nativeObjectsArrayIndex); m_Value = m_NativeObject.name; m_Address = m_NativeObject.address; displayName = m_NativeObject.type.name; // If it's a MonoBehaviour or ScriptableObject, use the C# typename instead // It makes it easier to understand what it is, otherwise everything displays 'MonoBehaviour' only. // TODO: Move to separate method if (m_NativeObject.type.IsSubclassOf(m_Snapshot.coreTypes.nativeMonoBehaviour) || m_NativeObject.type.IsSubclassOf(m_Snapshot.coreTypes.nativeScriptableObject)) { string monoScriptName; if (m_Snapshot.FindNativeMonoScriptType(m_NativeObject.packed.nativeObjectsArrayIndex, out monoScriptName) != -1) { if (!string.IsNullOrEmpty(monoScriptName)) { displayName = monoScriptName; } } } }
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); }