Esempio n. 1
0
        void UpdateStatusChecks(GameObject prefabInstanceRoot)
        {
            if (PrefabUtility.HasPrefabInstanceAnyOverrides(prefabInstanceRoot, false))
            {
                m_AnyOverrides = true;
            }
            if (PrefabUtility.IsDisconnectedFromPrefabAsset(prefabInstanceRoot))
            {
                m_Disconnected = true;
            }
            if (PrefabUtility.HasInvalidComponent(prefabInstanceRoot))
            {
                m_InvalidComponentOnInstance = true;
            }

            GameObject prefabAssetRoot = PrefabUtility.GetCorrespondingObjectFromSource(prefabInstanceRoot);

            if (PrefabUtility.IsPartOfModelPrefab(prefabAssetRoot))
            {
                m_ModelPrefab = true;
            }
            if (PrefabUtility.IsPartOfImmutablePrefab(prefabAssetRoot))
            {
                m_Immutable = true;
            }
            if (PrefabUtility.HasInvalidComponent(prefabAssetRoot))
            {
                m_InvalidComponentOnAsset = true;
            }
        }
        void UpdateStatusChecks(GameObject prefabInstanceRoot)
        {
            // Can't reset values inside this method, since it's called consecutively for each target.

            if (PrefabUtility.HasPrefabInstanceAnyOverrides(prefabInstanceRoot, false))
            {
                m_AnyOverrides = true;
            }
            if (PrefabUtility.IsDisconnectedFromPrefabAsset(prefabInstanceRoot))
            {
                m_Disconnected = true;
            }
            if (PrefabUtility.HasInvalidComponent(prefabInstanceRoot))
            {
                m_InvalidComponentOnInstance = true;
            }

            GameObject prefabAssetRoot = PrefabUtility.GetCorrespondingObjectFromSource(prefabInstanceRoot);

            if (PrefabUtility.IsPartOfModelPrefab(prefabAssetRoot))
            {
                m_ModelPrefab = true;
            }
            if (PrefabUtility.IsPartOfImmutablePrefab(prefabAssetRoot))
            {
                m_Immutable = true;
            }
            if (PrefabUtility.HasInvalidComponent(prefabAssetRoot))
            {
                m_InvalidComponentOnAsset = true;
            }
        }
        void UpdateStatusChecks(GameObject prefabInstanceRoot)
        {
            // Can't reset values inside this method, since it's called consecutively for each target.

            if (PrefabUtility.HasPrefabInstanceAnyOverrides(prefabInstanceRoot, false))
            {
                m_AnyOverrides = true;
            }
            if (PrefabUtility.HasInvalidComponent(prefabInstanceRoot))
            {
                m_InvalidComponentOnInstance = true;
            }

            GameObject prefabAssetRoot = PrefabUtility.GetCorrespondingObjectFromSource(prefabInstanceRoot);

            if (PrefabUtility.IsPartOfModelPrefab(prefabAssetRoot))
            {
                m_ModelPrefab = true;
            }
            if (PrefabUtility.IsPartOfImmutablePrefab(prefabAssetRoot))
            {
                m_Immutable = true;
            }
            if (PrefabUtility.HasInvalidComponent(prefabAssetRoot))
            {
                m_InvalidComponentOnAsset = true;
            }

            if (PrefabUtility.HasManagedReferencesWithMissingTypes(prefabAssetRoot))
            {
                m_HasManagedReferencesWithMissingTypesOnAsset = true;
            }

            m_HasApplicableOverrides = m_TreeView == null || m_TreeView.hasApplicableModifications;
        }
        void SetPrefabModeButtonVisibility(GameObjectTreeViewItem item)
        {
            item.showPrefabModeButton = false;

            GameObject go = item.objectPPTR as GameObject;

            if (go == null)
            {
                return;
            }

            if (!PrefabUtility.IsPartOfAnyPrefab(go))
            {
                return;
            }

            if (!PrefabUtility.IsAnyPrefabInstanceRoot(go))
            {
                return;
            }

            // Don't show button if prefab asset is missing
            if (PrefabUtility.GetPrefabInstanceStatus(go) == PrefabInstanceStatus.Connected)
            {
                var source = PrefabUtility.GetOriginalSourceOrVariantRoot(go);
                if (source == null)
                {
                    return;
                }

                // Don't show buttons for model prefabs but allow buttons for other immutables
                if (PrefabUtility.IsPartOfModelPrefab(source))
                {
                    return;
                }
            }
            else if (PrefabUtility.GetPrefabInstanceHandle(go) == null)
            {
                return;
            }
            else
            {
                var assetPath = PrefabUtility.GetAssetPathOfSourcePrefab(go);
                var broken    = AssetDatabase.LoadMainAssetAtPath(assetPath) as BrokenPrefabAsset;
                if (broken == null || !broken.isPrefabFileValid)
                {
                    return;
                }
            }

            item.showPrefabModeButton = true;
        }
        void SetPrefabModeButtonVisibility(GameObjectTreeViewItem item)
        {
            item.showPrefabModeButton = false;

            GameObject go = item.objectPPTR as GameObject;

            if (go == null)
            {
                return;
            }

            if (!PrefabUtility.IsPartOfAnyPrefab(go))
            {
                return;
            }

            if (!PrefabUtility.IsAnyPrefabInstanceRoot(go))
            {
                return;
            }

            // Don't show button for disconnected prefab instances and if prefab asset is missing
            if (PrefabUtility.GetPrefabInstanceStatus(go) != PrefabInstanceStatus.Connected)
            {
                return;
            }

            var source = PrefabUtility.GetOriginalSourceOrVariantRoot(go);

            if (source == null)
            {
                return;
            }

            // Don't show buttons for model prefabs but allow buttons for other immutables
            if (PrefabUtility.IsPartOfModelPrefab(source))
            {
                return;
            }

            item.showPrefabModeButton = true;
        }
        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();
            }
        }