void TryConnectNativeObject(ref PackedManagedObject managedObj) { if (managedObj.nativeObjectsArrayIndex >= 0) { return; // connected already } // If it's not derived from UnityEngine.Object, it does not have the m_CachedPtr field and we can skip it var type = m_Snapshot.managedTypes[managedObj.managedTypesArrayIndex]; if (type.isValueType || type.isArray) { return; } // Only types derived from UnityEngine.Object have the m_cachePtr field if (!type.isUnityEngineObject) { return; } BeginProfilerSample("ReadPointer"); // Read the m_cachePtr value var nativeObjectAddress = m_MemoryReader.ReadPointer(managedObj.address + (uint)m_CachedPtr.offset); EndProfilerSample(); if (nativeObjectAddress == 0) { return; } // Try to find the corresponding native object BeginProfilerSample("FindNativeObjectOfAddress"); var nativeObjectArrayIndex = m_Snapshot.FindNativeObjectOfAddress(nativeObjectAddress); EndProfilerSample(); if (nativeObjectArrayIndex < 0) { return; } // Connect ManagedObject <> NativeObject managedObj.nativeObjectsArrayIndex = nativeObjectArrayIndex; m_Snapshot.nativeObjects[managedObj.nativeObjectsArrayIndex].managedObjectsArrayIndex = managedObj.managedObjectsArrayIndex; // Connect the ManagedType <> NativeType m_Snapshot.managedTypes[managedObj.managedTypesArrayIndex].nativeTypeArrayIndex = m_Snapshot.nativeObjects[managedObj.nativeObjectsArrayIndex].nativeTypesArrayIndex; m_Snapshot.nativeTypes[m_Snapshot.nativeObjects[managedObj.nativeObjectsArrayIndex].nativeTypesArrayIndex].managedTypeArrayIndex = m_Snapshot.managedTypes[managedObj.managedTypesArrayIndex].managedTypesArrayIndex; BeginProfilerSample("AddConnection"); // Add a Connection from ManagedObject to NativeObject (m_CachePtr) m_Snapshot.AddConnection(PackedConnection.Kind.Managed, managedObj.managedObjectsArrayIndex, PackedConnection.Kind.Native, managedObj.nativeObjectsArrayIndex); EndProfilerSample(); }
void TryDrawObjectButton(PropertyGridItem itm, ref Rect rect) { // We do not test against address==0 here, because if it is a static field its address might be 0 if (itm.type.managedTypesArrayIndex < 0 || (itm is BaseClassPropertyGridItem)) { return; } // If it is not a pointer, it does not point to another object //var type = m_snapshot.managedTypes[itm.typeIndex]; if (!itm.type.isPointer) { return; } // If it points to null, it has no object var pointer = itm.myMemoryReader.ReadPointer(itm.address); if (pointer == 0) { return; } // Check if it is a managed object var managedObjIndex = m_Snapshot.FindManagedObjectOfAddress(itm.type.isArray ? itm.address : pointer); if (managedObjIndex != -1) { if (HeEditorGUI.CsButton(HeEditorGUI.SpaceR(ref rect, rect.height))) { m_Owner.window.OnGoto(new GotoCommand(new RichManagedObject(m_Snapshot, managedObjIndex))); } } // Check if it is a native object var nativeObjIndex = m_Snapshot.FindNativeObjectOfAddress(pointer); if (nativeObjIndex != -1) { if (HeEditorGUI.CppButton(HeEditorGUI.SpaceR(ref rect, rect.height))) { m_Owner.window.OnGoto(new GotoCommand(new RichNativeObject(m_Snapshot, nativeObjIndex))); } } }