public override void OnGUI(Rect rect) { // Escape closes the window if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) { editorWindow.Close(); GUIUtility.ExitGUI(); } Rect headerRect = GUILayoutUtility.GetRect(20, 10000, k_HeaderHeight, k_HeaderHeight); EditorGUI.DrawRect(headerRect, headerBgColor); float labelSize = EditorStyles.boldLabel.CalcSize(Styles.instanceLabel).x; headerRect.height = EditorGUIUtility.singleLineHeight; Rect labelRect = new Rect(headerRect.x + k_HeaderLeftMargin, headerRect.y, labelSize, headerRect.height); Rect contentRect = headerRect; contentRect.xMin = labelRect.xMax; GUI.Label(labelRect, Styles.instanceLabel, Styles.boldRightAligned); GUI.Label(contentRect, m_InstanceContent, EditorStyles.boldLabel); labelRect.y += EditorGUIUtility.singleLineHeight; contentRect.y += EditorGUIUtility.singleLineHeight; GUI.Label(labelRect, Styles.contextLabel, Styles.boldRightAligned); GUI.Label(contentRect, m_StageContent, EditorStyles.boldLabel); GUILayout.Space(k_TreeViewPadding.top); // If we know there are no overrides and thus no meaningful actions we just show that and nothing more. if (!IsShowingActionButton()) { EditorGUILayout.LabelField("No Overrides"); return; } // Display tree view and/or instructions related to it. if (HasMultiSelection()) { if (m_InvalidComponentOnAsset || m_InvalidComponentOnInstance || m_ModelPrefab || m_Immutable) { EditorGUILayout.HelpBox(Styles.infoMultipleNoApply.text, MessageType.Info); } else { EditorGUILayout.HelpBox(Styles.infoMultiple.text, MessageType.Info); } } else { if (m_Disconnected) { EditorGUILayout.HelpBox(Styles.warningDisconnected.text, MessageType.Warning); } else if (m_AnyOverrides) { Rect treeViewRect = GUILayoutUtility.GetRect(100, 1000, 0, 1000); m_TreeView.OnGUI(treeViewRect); // Display info message telling user they can click on individual items for more detailed actions. if (m_ModelPrefab) { EditorGUILayout.HelpBox(Styles.infoModel.text, MessageType.Info); } else if (m_Immutable || m_InvalidComponentOnInstance) { EditorGUILayout.HelpBox(Styles.infoNoApply.text, MessageType.Info); } else { EditorGUILayout.HelpBox(Styles.infoDefault.text, MessageType.Info); } } if (IsShowingApplyWarning()) { // Display warnings about edge cases that make it impossible to apply. // Model Prefabs are not an edge case and not needed to warn about so it's // not included here but rather combined into the info message above. if (m_InvalidComponentOnAsset) { EditorGUILayout.HelpBox(Styles.warningInvalidAsset.text, MessageType.Warning); } else if (m_InvalidComponentOnInstance) { EditorGUILayout.HelpBox(Styles.warningInvalidInstance.text, MessageType.Warning); } else { EditorGUILayout.HelpBox(Styles.warningImmutable.text, MessageType.Warning); } } } // Display action buttons (Revert All and Apply All) GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); using (new EditorGUI.DisabledScope(m_InvalidComponentOnAsset)) { if (GUILayout.Button(m_RevertAllContent, GUILayout.Width(k_ButtonWidth))) { if (RevertAll() && editorWindow != null) { editorWindow.Close(); GUIUtility.ExitGUI(); } } using (new EditorGUI.DisabledScope(m_Immutable || m_InvalidComponentOnInstance)) { if (GUILayout.Button(m_ApplyAllContent, GUILayout.Width(k_ButtonWidth))) { if (ApplyAll() && editorWindow != null) { editorWindow.Close(); GUIUtility.ExitGUI(); } } } } GUILayout.EndHorizontal(); }
public override void OnGUI(Rect rect) { Rect headerRect = GUILayoutUtility.GetRect(20, 10000, k_HeaderHeight, k_HeaderHeight); EditorGUI.DrawRect(headerRect, headerBgColor); float labelSize = EditorStyles.boldLabel.CalcSize(Styles.instanceLabel).x; headerRect.height = EditorGUIUtility.singleLineHeight; Rect labelRect = new Rect(headerRect.x + k_HeaderLeftMargin, headerRect.y, labelSize, headerRect.height); Rect contentRect = headerRect; contentRect.xMin = labelRect.xMax; GUI.Label(labelRect, Styles.instanceLabel, Styles.boldRightAligned); GUI.Label(contentRect, m_InstanceContent, EditorStyles.boldLabel); labelRect.y += EditorGUIUtility.singleLineHeight; contentRect.y += EditorGUIUtility.singleLineHeight; GUI.Label(labelRect, Styles.contextLabel, Styles.boldRightAligned); GUI.Label(contentRect, m_StageContent, EditorStyles.boldLabel); GUILayout.Space(k_TreeViewPadding.top); if (!IsDisconnected()) { Rect treeViewRect = GUILayoutUtility.GetRect(100, 1000, 0, 1000); m_TreeView.OnGUI(treeViewRect); } if (IsShowingActionButton()) { if (IsDisconnected()) { EditorGUILayout.HelpBox("Disconnected. Cannot show overrides.", MessageType.Warning); } else if (m_TreeView.hasModifications) { if (m_InvalidComponentOnAsset) { EditorGUILayout.HelpBox( "Click on individual items to review and revert.\nThe Prefab file contains an invalid script. Applying is not possible. Enter Prefab Mode and remove the script.", MessageType.Info); } else if (m_InvalidComponentOnInstance) { EditorGUILayout.HelpBox( "Click on individual items to review and revert.\nThe Prefab instance contains an invalid script. Applying is not possible. Remove the script.", MessageType.Info); } else if (PrefabUtility.IsPartOfModelPrefab(m_SelectedGameObject)) { EditorGUILayout.HelpBox( "Click on individual items to review and revert.\nApplying to a model Prefab is not possible.", MessageType.Info); } else if (m_Immutable) { EditorGUILayout.HelpBox( "Click on individual items to review and revert.\nThe Prefab file is immutable. Applying is not possible.", MessageType.Info); } else { EditorGUILayout.HelpBox("Click on individual items to review, revert and apply.", MessageType.Info); } } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); using (new EditorGUI.DisabledScope(m_InvalidComponentOnAsset)) { if (GUILayout.Button(m_RevertAllContent, GUILayout.Width(k_ButtonWidth))) { PrefabUtility.RevertPrefabInstance(m_SelectedGameObject, InteractionMode.UserAction); if (editorWindow != null) { editorWindow.Close(); GUIUtility.ExitGUI(); } } using (new EditorGUI.DisabledScope(m_Immutable || m_InvalidComponentOnInstance)) { if (GUILayout.Button(m_ApplyAllContent, GUILayout.Width(k_ButtonWidth))) { string assetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(m_SelectedGameObject); if (PrefabUtility.PromptAndCheckoutPrefabIfNeeded(assetPath, PrefabUtility.SaveVerb.Apply)) { PrefabUtility.ApplyPrefabInstance(m_SelectedGameObject, InteractionMode.UserAction); if (editorWindow != null) { editorWindow.Close(); GUIUtility.ExitGUI(); } } } } } } // Escape closes the window if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) { editorWindow.Close(); GUIUtility.ExitGUI(); } }
public override void OnGUI(Rect rect) { // Escape closes the window if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) { editorWindow.Close(); GUIUtility.ExitGUI(); } Rect headerRect = GUILayoutUtility.GetRect(20, 10000, k_HeaderHeight, k_HeaderHeight); EditorGUI.DrawRect(headerRect, headerBgColor); float titleLabelSize = 0; if (m_ModelPrefab || m_Immutable || m_InvalidComponentOnInstance) { titleLabelSize = EditorStyles.boldLabel.CalcSize(Styles.titleLabelNoApply).x; Rect titleLabelRect = new Rect(headerRect.x + k_HeaderLeftMargin, headerRect.y, titleLabelSize, headerRect.height); titleLabelRect.height = EditorGUIUtility.singleLineHeight; GUI.Label(titleLabelRect, Styles.titleLabelNoApply, Styles.boldRightAligned); } else { titleLabelSize = EditorStyles.boldLabel.CalcSize(Styles.titleLabelDefault).x; Rect titleLabelRect = new Rect(headerRect.x + k_HeaderLeftMargin, headerRect.y, titleLabelSize, headerRect.height); titleLabelRect.height = EditorGUIUtility.singleLineHeight; GUI.Label(titleLabelRect, Styles.titleLabelDefault, Styles.boldRightAligned); } float labelSize = EditorStyles.label.CalcSize(Styles.instanceLabel).x; headerRect.height = EditorGUIUtility.singleLineHeight; Rect labelRect = new Rect(headerRect.x + k_HeaderLeftMargin, headerRect.y + 20, labelSize, headerRect.height); Rect contentRect = headerRect; contentRect.xMin = labelRect.xMax; contentRect.y = labelRect.y; GUI.Label(labelRect, Styles.instanceLabel, Styles.rightAligned); GUI.Label(contentRect, m_InstanceContent, EditorStyles.label); labelRect.y += EditorGUIUtility.singleLineHeight; contentRect.y += EditorGUIUtility.singleLineHeight; GUI.Label(labelRect, Styles.contextLabel, Styles.rightAligned); GUI.Label(contentRect, m_StageContent, EditorStyles.label); // If we know there are no overrides and thus no meaningful actions we just show that and nothing more. if (!IsShowingActionButton()) { if (m_UnusedOverridesExist) { DrawUnusedOverridesButton(); GUILayout.Space(k_RowPadding); } else { EditorGUILayout.LabelField(Styles.noOverridesText); } return; } // Display tree view and/or instructions related to it. if (HasMultiSelection()) { if (m_InvalidComponentOnAsset || m_HasManagedReferencesWithMissingTypesOnAsset || m_InvalidComponentOnInstance || m_ModelPrefab || m_Immutable) { EditorGUILayout.HelpBox(Styles.infoMultipleNoApply.text, MessageType.Info); } else { EditorGUILayout.HelpBox(Styles.infoMultiple.text, MessageType.Info); } if (m_UnusedOverridesExist) { DrawUnusedOverridesButton(); GUILayout.Space(k_RowPadding); } else { GUILayout.Space(2); } } else { GUILayout.Space(k_TreeViewPadding.top); if (m_AnyOverrides) { Rect treeViewRect = GUILayoutUtility.GetRect(100, 10000, 0, 10000); m_TreeView.OnGUI(treeViewRect); if (m_UnusedOverridesExist) { DrawUnusedOverridesButton(); GUILayout.Space(k_RowPadding); } if (m_ModelPrefab) { EditorGUILayout.HelpBox(Styles.infoModel.text, MessageType.Info); } } if (IsShowingApplyWarning()) { // Display warnings about edge cases that make it impossible to apply. // Model Prefabs are not an edge case and not needed to warn about so it's // not included here but rather combined into the info message above. if (m_InvalidComponentOnAsset) { EditorGUILayout.HelpBox(Styles.warningInvalidAsset.text, MessageType.Warning); } else if (m_InvalidComponentOnInstance) { EditorGUILayout.HelpBox(Styles.warningInvalidInstance.text, MessageType.Warning); } if (m_HasManagedReferencesWithMissingTypesOnAsset) { EditorGUILayout.HelpBox(Styles.warningHasManagedReferencesWithMissingTypes.text, MessageType.Warning); } else { EditorGUILayout.HelpBox(Styles.warningImmutable.text, MessageType.Warning); } } } // Display action buttons (Revert All and Apply All) GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); using (new EditorGUI.DisabledScope(m_InvalidComponentOnAsset || m_HasManagedReferencesWithMissingTypesOnAsset)) { if (m_TreeView != null && m_TreeView.GetSelection().Count > 1) { if (GUILayout.Button(m_RevertSelectedContent, GUILayout.Width(m_ButtonWidth))) { if (OperateSelectedOverrides(PrefabUtility.OverrideOperation.Revert)) { RefreshStatus(); // We don't close the window even if there are no more overrides left. // We want to diplay explicit confirmation, since it's not a given outcome // when using Revert Selected. Only Revert All button closes the window. } } using (new EditorGUI.DisabledScope(m_Immutable || m_InvalidComponentOnInstance)) { if (GUILayout.Button(m_ApplySelectedContent, GUILayout.Width(m_ButtonWidth))) { if (OperateSelectedOverrides(PrefabUtility.OverrideOperation.Apply)) { RefreshStatus(); // We don't close the window even if there are no more overrides left. // We want to diplay explicit confirmation, since it's not a given outcome // when using Apply Selected. Only Apply All button closes the window. } } } } else { if (GUILayout.Button(m_RevertAllContent, GUILayout.Width(m_ButtonWidth))) { if (RevertAll() && editorWindow != null) { editorWindow.Close(); GUIUtility.ExitGUI(); } } using (new EditorGUI.DisabledScope(m_Immutable || m_InvalidComponentOnInstance || !m_HasApplicableOverrides)) { if (GUILayout.Button(m_ApplyAllContent, GUILayout.Width(m_ButtonWidth))) { if (ApplyAll() && editorWindow != null) { editorWindow.Close(); GUIUtility.ExitGUI(); } } } } } GUILayout.EndHorizontal(); GUILayout.Space(k_RowPadding); }
public override void OnGUI(Rect rect) { // Escape closes the window if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) { editorWindow.Close(); GUIUtility.ExitGUI(); } Rect headerRect = GUILayoutUtility.GetRect(20, 10000, k_HeaderHeight, k_HeaderHeight); EditorGUI.DrawRect(headerRect, headerBgColor); float labelSize = EditorStyles.boldLabel.CalcSize(Styles.instanceLabel).x; headerRect.height = EditorGUIUtility.singleLineHeight; Rect labelRect = new Rect(headerRect.x + k_HeaderLeftMargin, headerRect.y, labelSize, headerRect.height); Rect contentRect = headerRect; contentRect.xMin = labelRect.xMax; GUI.Label(labelRect, Styles.instanceLabel, Styles.boldRightAligned); GUI.Label(contentRect, m_InstanceContent, EditorStyles.boldLabel); labelRect.y += EditorGUIUtility.singleLineHeight; contentRect.y += EditorGUIUtility.singleLineHeight; GUI.Label(labelRect, Styles.contextLabel, Styles.boldRightAligned); GUI.Label(contentRect, m_StageContent, EditorStyles.boldLabel); GUILayout.Space(k_TreeViewPadding.top); // If we know there are no overrides and thus no meaningful actions we just show that and nothing more. if (!IsShowingActionButton()) { EditorGUILayout.LabelField("No Overrides"); return; } // Display tree view and/or instructions related to it. if (HasMultiSelection()) { if (m_InvalidComponentOnAsset || m_InvalidComponentOnInstance || m_ModelPrefab || m_Immutable) { EditorGUILayout.HelpBox( "Multiple Prefabs selected. Cannot show overrides.\nApplying is not possible for one or more Prefabs. Select individual Prefabs for details.", MessageType.Info); } else { EditorGUILayout.HelpBox( "Multiple Prefabs selected. Cannot show overrides.", MessageType.Info); } } else { if (m_Disconnected) { EditorGUILayout.HelpBox("Disconnected. Cannot show overrides.", MessageType.Warning); } else if (m_AnyOverrides) { Rect treeViewRect = GUILayoutUtility.GetRect(100, 1000, 0, 1000); m_TreeView.OnGUI(treeViewRect); if (m_InvalidComponentOnAsset) { EditorGUILayout.HelpBox( "Click on individual items to review and revert.\nThe Prefab file contains an invalid script. Applying is not possible. Enter Prefab Mode and remove the script.", MessageType.Info); } else if (m_InvalidComponentOnInstance) { EditorGUILayout.HelpBox( "Click on individual items to review and revert.\nThe Prefab instance contains an invalid script. Applying is not possible. Remove the script.", MessageType.Info); } else if (m_ModelPrefab) { EditorGUILayout.HelpBox( "Click on individual items to review and revert.\nApplying to a model Prefab is not possible.", MessageType.Info); } else if (m_Immutable) { EditorGUILayout.HelpBox( "Click on individual items to review and revert.\nThe Prefab file is immutable. Applying is not possible.", MessageType.Info); } else { EditorGUILayout.HelpBox("Click on individual items to review, revert and apply.", MessageType.Info); } } } // Display action buttons (Revert All and Apply All) GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); using (new EditorGUI.DisabledScope(m_InvalidComponentOnAsset)) { if (GUILayout.Button(m_RevertAllContent, GUILayout.Width(k_ButtonWidth))) { if (RevertAll() && editorWindow != null) { editorWindow.Close(); GUIUtility.ExitGUI(); } } using (new EditorGUI.DisabledScope(m_Immutable || m_InvalidComponentOnInstance)) { if (GUILayout.Button(m_ApplyAllContent, GUILayout.Width(k_ButtonWidth))) { if (ApplyAll() && editorWindow != null) { editorWindow.Close(); GUIUtility.ExitGUI(); } } } } GUILayout.EndHorizontal(); }