public ComparisonViewPopup(Object source, Object instance, PrefabOverride modification, PrefabOverridesTreeView owner) { m_Owner = owner; m_Source = source; m_Instance = instance; m_Modification = modification; if (modification != null) { m_Unappliable = !PrefabUtility.IsPartOfPrefabThatCanBeAppliedTo(modification.GetAssetObject()); } else { m_Unappliable = false; } if (m_Source != null) { m_SourceEditor = Editor.CreateEditor(m_Source); } if (m_Instance != null) { m_InstanceEditor = Editor.CreateEditor(m_Instance); } if (m_Source == null || m_Instance == null || m_Modification == null) { m_PreviewSize.x /= 2; } if (modification is ObjectOverride) { Undo.postprocessModifications += RecheckOverrideStatus; } }
internal static void DisplayObjectContextMenu(Rect position, Object[] context, int contextUserData) { // Don't show context menu if we're inside the side-by-side diff comparison. if (EditorGUIUtility.comparisonViewMode != EditorGUIUtility.ComparisonViewMode.None) { return; } Vector2 temp = GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.y)); position.x = temp.x; position.y = temp.y; GenericMenu pm = new GenericMenu(); if (context != null && context.Length == 1 && context[0] is Component) { Object targetObject = context[0]; Component targetComponent = (Component)targetObject; // Do nothing if component is not on a prefab instance. if (PrefabUtility.GetCorrespondingObjectFromSource(targetComponent.gameObject) == null) { } // Handle added component. else if (PrefabUtility.GetCorrespondingObjectFromSource(targetObject) == null && targetComponent != null) { GameObject instanceGo = targetComponent.gameObject; PrefabUtility.HandleApplyRevertMenuItems( "Added Component", instanceGo, (menuItemContent, sourceGo) => { TargetChoiceHandler.ObjectInstanceAndSourcePathInfo info = new TargetChoiceHandler.ObjectInstanceAndSourcePathInfo(); info.instanceObject = targetComponent; info.assetPath = AssetDatabase.GetAssetPath(sourceGo); GameObject rootObject = PrefabUtility.GetRootGameObject(sourceGo); if (!PrefabUtility.IsPartOfPrefabThatCanBeAppliedTo(rootObject)) { pm.AddDisabledItem(menuItemContent); } else { pm.AddItem(menuItemContent, false, TargetChoiceHandler.ApplyPrefabAddedComponent, info); } }, (menuItemContent) => { pm.AddItem(menuItemContent, false, TargetChoiceHandler.RevertPrefabAddedComponent, targetComponent); } ); } else { SerializedObject so = new SerializedObject(targetObject); SerializedProperty property = so.GetIterator(); bool hasPrefabOverride = false; while (property.Next(property.hasChildren)) { if (property.isInstantiatedPrefab && property.prefabOverride && !property.isDefaultOverride) { hasPrefabOverride = true; break; } } // Handle modified component. if (hasPrefabOverride) { bool defaultOverrides = PrefabUtility.IsObjectOverrideAllDefaultOverridesComparedToAnySource(targetObject); PrefabUtility.HandleApplyRevertMenuItems( "Modified Component", targetObject, (menuItemContent, sourceObject) => { TargetChoiceHandler.ObjectInstanceAndSourcePathInfo info = new TargetChoiceHandler.ObjectInstanceAndSourcePathInfo(); info.instanceObject = targetObject; info.assetPath = AssetDatabase.GetAssetPath(sourceObject); GameObject rootObject = PrefabUtility.GetRootGameObject(sourceObject); if (!PrefabUtility.IsPartOfPrefabThatCanBeAppliedTo(rootObject)) { pm.AddDisabledItem(menuItemContent); } else { pm.AddItem(menuItemContent, false, TargetChoiceHandler.ApplyPrefabObjectOverride, info); } }, (menuItemContent) => { pm.AddItem(menuItemContent, false, TargetChoiceHandler.RevertPrefabObjectOverride, targetObject); }, defaultOverrides ); } } } pm.ObjectContextDropDown(position, context, contextUserData); ResetMouseDown(); }