Ejemplo n.º 1
0
 private void DoPrefabButtons(PrefabType prefabType, GameObject go)
 {
     if (this.m_HasInstance)
     {
         using (new EditorGUI.DisabledScope(EditorApplication.isPlayingOrWillChangePlaymode))
         {
             EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
             GUIContent gUIContent = (base.targets.Length <= 1) ? GameObjectInspector.s_Styles.goTypeLabel[(int)prefabType] : GameObjectInspector.s_Styles.goTypeLabelMultiple;
             if (gUIContent != null)
             {
                 EditorGUILayout.BeginHorizontal(new GUILayoutOption[]
                 {
                     GUILayout.Width(24f + GameObjectInspector.s_Styles.tagFieldWidth)
                 });
                 GUILayout.FlexibleSpace();
                 if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                 {
                     GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor;
                     GUILayout.Label(gUIContent, EditorStyles.whiteLabel, new GUILayoutOption[]
                     {
                         GUILayout.ExpandWidth(false)
                     });
                     GUI.contentColor = Color.white;
                 }
                 else
                 {
                     GUILayout.Label(gUIContent, new GUILayoutOption[]
                     {
                         GUILayout.ExpandWidth(false)
                     });
                 }
                 EditorGUILayout.EndHorizontal();
             }
             if (base.targets.Length > 1)
             {
                 GUILayout.Label("Instance Management Disabled", GameObjectInspector.s_Styles.instanceManagementInfo, new GUILayoutOption[0]);
             }
             else
             {
                 if (prefabType != PrefabType.MissingPrefabInstance)
                 {
                     if (GUILayout.Button("Select", "MiniButtonLeft", new GUILayoutOption[0]))
                     {
                         Selection.activeObject = PrefabUtility.GetPrefabParent(base.target);
                         EditorGUIUtility.PingObject(Selection.activeObject);
                     }
                 }
                 using (new EditorGUI.DisabledScope(AnimationMode.InAnimationMode()))
                 {
                     if (prefabType != PrefabType.MissingPrefabInstance)
                     {
                         if (GUILayout.Button("Revert", "MiniButtonMid", new GUILayoutOption[0]))
                         {
                             PrefabUtility.RevertPrefabInstanceWithUndo(go);
                             if (go != null)
                             {
                                 this.CalculatePrefabStatus();
                             }
                             GUIUtility.ExitGUI();
                         }
                         if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                         {
                             GameObject gameObject = PrefabUtility.FindValidUploadPrefabInstanceRoot(go);
                             GUI.enabled = (gameObject != null && !AnimationMode.InAnimationMode());
                             if (GUILayout.Button("Apply", "MiniButtonRight", new GUILayoutOption[0]))
                             {
                                 UnityEngine.Object prefabParent = PrefabUtility.GetPrefabParent(gameObject);
                                 string             assetPath    = AssetDatabase.GetAssetPath(prefabParent);
                                 bool flag = Provider.PromptAndCheckoutIfNeeded(new string[]
                                 {
                                     assetPath
                                 }, "The version control requires you to check out the prefab before applying changes.");
                                 if (flag)
                                 {
                                     PrefabUtility.ReplacePrefabWithUndo(gameObject);
                                     this.CalculatePrefabStatus();
                                     GUIUtility.ExitGUI();
                                 }
                             }
                         }
                     }
                 }
                 if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance)
                 {
                     if (GUILayout.Button("Open", "MiniButtonRight", new GUILayoutOption[0]))
                     {
                         AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(base.target));
                         GUIUtility.ExitGUI();
                     }
                 }
             }
             EditorGUILayout.EndHorizontal();
         }
     }
 }
        private void DoPrefabButtons(PrefabType prefabType, GameObject go)
        {
            // @TODO: If/when we support multi-editing of prefab/model instances,
            // handle it here. Only show prefab bar if all are same type?
            if (!m_HasInstance)
            {
                return;
            }

            using (new EditorGUI.DisabledScope(EditorApplication.isPlayingOrWillChangePlaymode))
            {
                EditorGUILayout.BeginHorizontal();

                // Prefab information
                GUIContent prefixLabel = targets.Length > 1 ? s_Styles.goTypeLabelMultiple : s_Styles.goTypeLabel[(int)prefabType];

                if (prefixLabel != null)
                {
                    EditorGUILayout.BeginHorizontal(GUILayout.Width(kIconSize + s_Styles.tagFieldWidth));
                    GUILayout.FlexibleSpace();
                    if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                    {
                        GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor;
                        GUILayout.Label(prefixLabel, EditorStyles.whiteLabel, GUILayout.ExpandWidth(false));
                        GUI.contentColor = Color.white;
                    }
                    else
                    {
                        GUILayout.Label(prefixLabel, GUILayout.ExpandWidth(false));
                    }
                    EditorGUILayout.EndHorizontal();
                }

                if (targets.Length > 1)
                {
                    GUILayout.Label("Instance Management Disabled", s_Styles.instanceManagementInfo);
                }
                else
                {
                    // Select prefab
                    if (prefabType != PrefabType.MissingPrefabInstance)
                    {
                        if (GUILayout.Button("Select", "MiniButtonLeft"))
                        {
                            Selection.activeObject = PrefabUtility.GetCorrespondingObjectFromSource(target);
                            EditorGUIUtility.PingObject(Selection.activeObject);
                        }
                    }

                    using (new EditorGUI.DisabledScope(AnimationMode.InAnimationMode()))
                    {
                        if (prefabType != PrefabType.MissingPrefabInstance)
                        {
                            // Revert this gameobject and components to prefab
                            if (GUILayout.Button("Revert", "MiniButtonMid"))
                            {
                                PrefabUtility.RevertPrefabInstanceWithUndo(go);

                                // case931300 - The selected gameobject might get destroyed by RevertPrefabInstance
                                if (go != null)
                                {
                                    CalculatePrefabStatus();
                                }

                                // This is necessary because Revert can potentially destroy game objects and components
                                // In that case the Editor classes would be destroyed but still be invoked. (case 837113)
                                GUIUtility.ExitGUI();
                            }

                            // Apply to prefab
                            if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                            {
                                GameObject rootUploadGameObject = PrefabUtility.FindValidUploadPrefabInstanceRoot(go);

                                GUI.enabled = rootUploadGameObject != null && !AnimationMode.InAnimationMode();

                                if (GUILayout.Button("Apply", "MiniButtonRight"))
                                {
                                    UnityObject correspondingAssetObject = PrefabUtility.GetCorrespondingObjectFromSource(rootUploadGameObject);
                                    string      prefabAssetPath = AssetDatabase.GetAssetPath(correspondingAssetObject);
                                    bool        isRootFolder, isReadonly;
                                    bool        validPath = AssetDatabase.GetAssetFolderInfo(prefabAssetPath, out isRootFolder, out isReadonly);

                                    if (validPath && isReadonly)
                                    {
                                        string prefabName = FileUtil.GetLastPathNameComponent(FileUtil.GetPathWithoutExtension(prefabAssetPath));
                                        EditorUtility.DisplayDialog("Cannot apply changes", string.Format("Original prefab \"{0}\" is immutable.", prefabName), "Close");
                                    }
                                    else
                                    {
                                        bool editablePrefab = Provider.PromptAndCheckoutIfNeeded(
                                            new string[] { prefabAssetPath },
                                            "The version control requires you to check out the prefab before applying changes.");

                                        if (editablePrefab)
                                        {
                                            PrefabUtility.ReplacePrefabWithUndo(rootUploadGameObject);

                                            CalculatePrefabStatus();

                                            // This is necessary because ReplacePrefab can potentially destroy game objects and components
                                            // In that case the Editor classes would be destroyed but still be invoked. (case 468434)
                                            GUIUtility.ExitGUI();
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Edit model prefab
                    if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance)
                    {
                        if (GUILayout.Button("Open", "MiniButtonRight"))
                        {
                            AssetDatabase.OpenAsset(PrefabUtility.GetCorrespondingObjectFromSource(target));
                            GUIUtility.ExitGUI();
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
        }