ForceRebuildInspectors() private method

private ForceRebuildInspectors ( ) : void
return void
        public bool MissingMonoBehaviourGUI()
        {
            base.serializedObject.Update();
            SerializedProperty serializedProperty = base.serializedObject.FindProperty("m_Script");

            if (serializedProperty == null)
            {
                return(false);
            }
            EditorGUILayout.PropertyField(serializedProperty, new GUILayoutOption[0]);
            MonoScript monoScript = serializedProperty.objectReferenceValue as MonoScript;
            bool       flag       = true;

            if (monoScript != null && monoScript.GetScriptTypeWasJustCreatedFromComponentMenu())
            {
                flag = false;
            }
            if (flag)
            {
                GUIContent gUIContent = EditorGUIUtility.TextContent("GenericInspector.ScriptIsInvalid");
                EditorGUILayout.HelpBox(gUIContent.text, MessageType.Warning, true);
            }
            if (base.serializedObject.ApplyModifiedProperties())
            {
                EditorUtility.ForceRebuildInspectors();
            }
            return(true);
        }
示例#2
0
        internal static void ApplyPrefabAddedGameObjects(object userData)
        {
            ObjectInstanceAndSourcePathInfo[] infos = (ObjectInstanceAndSourcePathInfo[])userData;

            GameObject[] gameObjects = new GameObject[infos.Length];
            for (int i = 0; i < infos.Length; i++)
            {
                ObjectInstanceAndSourcePathInfo info = infos[i];
                gameObjects[i] = info.instanceObject as GameObject;
            }

            if (!PrefabUtility.HasSameParent(gameObjects))
            {
                throw new ArgumentException(nameof(gameObjects), "ApplyPrefabAddedGameObjects requires that GameObjects share the same parent.");
            }

            if (!HasSameAssetPath(infos))
            {
                throw new ArgumentException(nameof(infos), "ApplyPrefabAddedGameObjects requires that GameObjects share the same parent asset path.");
            }

            if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(infos[0].assetPath, PrefabUtility.SaveVerb.Apply))
            {
                return;
            }

            PrefabUtility.ApplyAddedGameObjects(gameObjects, infos[0].assetPath, InteractionMode.UserAction);
            EditorUtility.ForceRebuildInspectors();
        }
        public bool MissingMonoBehaviourGUI()
        {
            base.serializedObject.Update();
            SerializedProperty property = base.serializedObject.FindProperty("m_Script");

            if (property == null)
            {
                return(false);
            }
            EditorGUILayout.PropertyField(property, new GUILayoutOption[0]);
            MonoScript objectReferenceValue = property.objectReferenceValue as MonoScript;
            bool       flag2 = true;

            if ((objectReferenceValue != null) && objectReferenceValue.GetScriptTypeWasJustCreatedFromComponentMenu())
            {
                flag2 = false;
            }
            if (flag2)
            {
                EditorGUILayout.HelpBox(EditorGUIUtility.TextContent("The associated script can not be loaded.\nPlease fix any compile errors\nand assign a valid script.").text, MessageType.Warning, true);
            }
            if (base.serializedObject.ApplyModifiedProperties())
            {
                EditorUtility.ForceRebuildInspectors();
            }
            return(true);
        }
        internal static void RevertPrefabAddedGameObject(object userData)
        {
            GameObject obj = (GameObject)userData;

            PrefabUtility.RevertAddedGameObject(obj, InteractionMode.UserAction);
            EditorUtility.ForceRebuildInspectors();
        }
        public bool MissingMonoBehaviourGUI()
        {
            serializedObject.Update();
            SerializedProperty scriptProperty = serializedObject.FindProperty("m_Script");

            if (scriptProperty == null)
            {
                return(false);
            }

            EditorGUILayout.PropertyField(scriptProperty);

            MonoScript targetScript      = scriptProperty.objectReferenceValue as MonoScript;
            bool       showScriptWarning = true;

            if (targetScript != null && targetScript.GetScriptTypeWasJustCreatedFromComponentMenu())
            {
                showScriptWarning = false;
            }

            if (showScriptWarning)
            {
                GUIContent c = EditorGUIUtility.TrTextContent("The associated script can not be loaded.\nPlease fix any compile errors\nand assign a valid script.");
                EditorGUILayout.HelpBox(c.text, MessageType.Warning, true);
            }

            if (serializedObject.ApplyModifiedProperties())
            {
                EditorUtility.ForceRebuildInspectors();
            }

            return(true);
        }
        internal static void RevertPrefabRemovedComponent(object userData)
        {
            ObjectInstanceAndSourceInfo info = (ObjectInstanceAndSourceInfo)userData;

            PrefabUtility.RevertRemovedComponent((GameObject)info.instanceObject, (Component)info.correspondingObjectInSource, InteractionMode.UserAction);
            EditorUtility.ForceRebuildInspectors();
        }
示例#7
0
        public bool MissingMonoBehaviourGUI()
        {
            base.serializedObject.Update();
            SerializedProperty serializedProperty = base.serializedObject.FindProperty("m_Script");
            bool result;

            if (serializedProperty == null)
            {
                result = false;
            }
            else
            {
                EditorGUILayout.PropertyField(serializedProperty, new GUILayoutOption[0]);
                MonoScript monoScript = serializedProperty.objectReferenceValue as MonoScript;
                bool       flag       = true;
                if (monoScript != null && monoScript.GetScriptTypeWasJustCreatedFromComponentMenu())
                {
                    flag = false;
                }
                if (flag)
                {
                    GUIContent gUIContent = EditorGUIUtility.TrTextContent("The associated script can not be loaded.\nPlease fix any compile errors\nand assign a valid script.", null, null);
                    EditorGUILayout.HelpBox(gUIContent.text, MessageType.Warning, true);
                }
                if (base.serializedObject.ApplyModifiedProperties())
                {
                    EditorUtility.ForceRebuildInspectors();
                }
                result = true;
            }
            return(result);
        }
示例#8
0
        public bool MissingMonoBehaviourGUI()
        {
            serializedObject.Update();
            SerializedProperty scriptProperty = serializedObject.FindProperty("m_Script");

            if (scriptProperty == null)
            {
                return(false);
            }

            bool scriptLoaded  = CheckIfScriptLoaded(scriptProperty);
            bool oldGUIEnabled = GUI.enabled;

            if (!GUI.enabled && !scriptLoaded)
            {
                GUI.enabled = true;
            }

            EditorGUILayout.PropertyField(scriptProperty);

            if (!scriptLoaded)
            {
                ShowScriptNotLoadedWarning();
            }

            GUI.enabled = oldGUIEnabled;

            if (serializedObject.ApplyModifiedProperties())
            {
                EditorUtility.ForceRebuildInspectors();
            }

            return(true);
        }
        bool RevertAll()
        {
            for (int i = 0; i < m_SelectedGameObjects.Length; i++)
            {
                PrefabUtility.RevertPrefabInstance(m_SelectedGameObjects[i], InteractionMode.UserAction);
            }

            EditorUtility.ForceRebuildInspectors();
            return(true);
        }
示例#10
0
        internal static void RevertPrefabAddedGameObjects(object userData)
        {
            GameObject[] gameObjects = (GameObject[])userData;

            foreach (GameObject go in gameObjects)
            {
                PrefabUtility.RevertAddedGameObject(go, InteractionMode.UserAction);
            }

            EditorUtility.ForceRebuildInspectors();
        }
        internal static void ApplyPrefabAddedGameObject(object userData)
        {
            ObjectInstanceAndSourcePathInfo info = (ObjectInstanceAndSourcePathInfo)userData;

            if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(info.assetPath, PrefabUtility.SaveVerb.Apply))
            {
                return;
            }
            PrefabUtility.ApplyAddedGameObject((GameObject)info.instanceObject, info.assetPath, InteractionMode.UserAction);
            EditorUtility.ForceRebuildInspectors();
        }
        internal static void ApplyPrefabRemovedComponent(object userData)
        {
            ObjectInstanceAndSourceInfo info = (ObjectInstanceAndSourceInfo)userData;
            string path = AssetDatabase.GetAssetPath(info.correspondingObjectInSource);

            if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(path, PrefabUtility.SaveVerb.Apply))
            {
                return;
            }
            PrefabUtility.ApplyRemovedComponent((GameObject)info.instanceObject, (Component)info.correspondingObjectInSource, InteractionMode.UserAction);
            EditorUtility.ForceRebuildInspectors();
        }
            void Apply(object prefabAssetPathObject)
            {
                string prefabAssetPath = (string)prefabAssetPathObject;

                if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(prefabAssetPath, PrefabUtility.SaveVerb.Apply))
                {
                    return;
                }
                m_Modification.Apply(prefabAssetPath);
                EditorUtility.ForceRebuildInspectors(); // handles applying RemovedComponents

                UpdateAndClose();
            }
示例#14
0
        public bool MissingMonoBehaviourGUI()
        {
            serializedObject.Update();
            SerializedProperty scriptProperty = serializedObject.FindProperty("m_Script");

            if (scriptProperty == null)
            {
                return(false);
            }

            bool scriptLoaded = CheckIfScriptLoaded(scriptProperty);

            bool oldGUIEnabled = GUI.enabled;

            if (!scriptLoaded)
            {
                GUI.enabled = IsAnyMonoBehaviourTargetPartOfPrefabInstance(this) == false; // We don't support changing script as an override on Prefab Instances (case 1255454)
            }

            EditorGUILayout.PropertyField(scriptProperty);
            if (!scriptLoaded)
            {
                GUI.enabled = true;
                // if script is not loaded, this might also be because
                // the asset is tied to an EditorClassIdentifier rather than a MonoScript
                // (it happens when multiple types are defined in a C# script)
                switch (ShowTypeFixup())
                {
                case ShowTypeFixupResult.CantFindCandidate:
                    ShowScriptNotLoadedWarning(IsAnyMonoBehaviourTargetPartOfPrefabInstance(this));
                    break;

                case ShowTypeFixupResult.SelectedCandidate:
                    serializedObject.ApplyModifiedProperties();
                    EditorUtility.RequestScriptReload();
                    return(true);
                }
            }

            GUI.enabled = oldGUIEnabled;
            if (serializedObject.ApplyModifiedProperties())
            {
                EditorUtility.ForceRebuildInspectors();
            }
            return(true);
        }
        bool ApplyAll()
        {
            // Collect Prefab Asset paths and also check if there's more than one of the same.
            HashSet <string> prefabAssetPaths = new HashSet <string>();
            bool             multipleOfSame   = false;

            for (int i = 0; i < m_SelectedGameObjects.Length; i++)
            {
                string prefabAssetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(m_SelectedGameObjects[i]);
                if (prefabAssetPaths.Contains(prefabAssetPath))
                {
                    multipleOfSame = true;
                }
                else
                {
                    prefabAssetPaths.Add(prefabAssetPath);
                }
            }

            // If more than one instance of the same Prefab Asset, show dialog to user.
            if (multipleOfSame && !EditorUtility.DisplayDialog(
                    L10n.Tr("Multiple instances of same Prefab Asset"),
                    L10n.Tr("Multiple instances of the same Prefab Asset were detected. Potentially conflicting overrides will be applied sequentially and will overwrite each other."),
                    L10n.Tr("OK"),
                    L10n.Tr("Cancel")))
            {
                return(false);
            }

            // Make sure assets are checked out in version control.
            if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(prefabAssetPaths.ToArray(), PrefabUtility.SaveVerb.Apply))
            {
                return(false);
            }

            // Apply sequentially.
            AssetDatabase.StartAssetEditing();
            for (int i = 0; i < m_SelectedGameObjects.Length; i++)
            {
                PrefabUtility.ApplyPrefabInstance(m_SelectedGameObjects[i], InteractionMode.UserAction);
            }
            AssetDatabase.StopAssetEditing();

            EditorUtility.ForceRebuildInspectors();
            return(true);
        }
        public bool MissingMonoBehaviourGUI()
        {
            serializedObject.Update();
            SerializedProperty scriptProperty = serializedObject.FindProperty("m_Script");

            if (scriptProperty == null)
            {
                return(false);
            }

            EditorGUILayout.PropertyField(scriptProperty);

            CheckIfScriptLoaded(scriptProperty);

            if (serializedObject.ApplyModifiedProperties())
            {
                EditorUtility.ForceRebuildInspectors();
            }

            return(true);
        }
        bool OperateSelectedOverrides(PrefabUtility.OverrideOperation operation)
        {
            List <PrefabOverride> overrides = new List <PrefabOverride>();

            // Get all overrides from selection. Immediately accept any overrides with no dependencies.
            var selection = m_TreeView.GetSelection();

            for (int i = 0; i < selection.Count; i++)
            {
                PrefabOverride singleOverride = m_TreeView.FindOverride(selection[i]);
                if (singleOverride != null)
                {
                    overrides.Add(singleOverride);
                }
            }

            bool success = PrefabUtility.ProcessMultipleOverrides(m_SelectedGameObjects[0], overrides, operation, InteractionMode.UserAction);

            if (success)
            {
                EditorUtility.ForceRebuildInspectors();
            }
            return(success);
        }
示例#18
0
        // Internal for testing framework
        internal void SaveDirtyPrefabAssets(bool rebuildInspectors)
        {
            if (assetTargets == null)
            {
                return;
            }

            if (assetTarget == null)
            {
                return;
            }

            m_DirtyPrefabAssets.Clear();
            foreach (var asset in assetTargets)
            {
                // The asset could have been deleted when this method is called from OnDestroy().
                // E.g delete the selected prefab asset from the Project Browser.
                if (asset == null)
                {
                    continue;
                }

                if (!EditorUtility.IsPersistent(asset))
                {
                    continue;
                }

                if (!(asset is GameObject))
                {
                    continue;
                }

                var rootGameObject = (GameObject)asset;
                if (IsDirty(rootGameObject))
                {
                    m_DirtyPrefabAssets.Add(rootGameObject);
                }
            }

            if (m_DirtyPrefabAssets.Count > 0)
            {
                bool sourceFileChangedAfterSaving = false;
                AssetDatabase.StartAssetEditing();
                try
                {
                    foreach (var rootGameObject in m_DirtyPrefabAssets)
                    {
                        var guid             = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(rootGameObject));
                        var hashBeforeSaving = AssetDatabase.GetSourceAssetFileHash(guid);

                        bool savedSuccesfully;
                        PrefabUtility.SavePrefabAsset(rootGameObject, out savedSuccesfully);
                        if (!savedSuccesfully)
                        {
                            string title   = L10n.Tr("Saving Failed");
                            string message = L10n.Tr("Check the Console window to get more insight into what needs to be fixed on the Prefab Asset.\n\nYou can open Prefab Mode to fix any issues on child GameObjects");
                            EditorUtility.DisplayDialog(title, message, L10n.Tr("OK"));

                            m_SavingHasFailed = true;
                            break;
                        }

                        // Fix case 1239807: Prevent calling ForceRebuildInspectors() if the the user is dirtying the prefab asset on every CustomEditor::OnEnable() with a
                        // value that is the same as before (so the artifact does not change). This fix avoids constant rebuilding of the Inspector window.
                        sourceFileChangedAfterSaving |= AssetDatabase.GetSourceAssetFileHash(guid) != hashBeforeSaving;
                    }
                }
                finally
                {
                    AssetDatabase.StopAssetEditing();

                    // All inspectors needs to be rebuild to ensure property changes are reflected after saving the Prefab shown.
                    // (Saving clears the m_DirtyIndex of the target which is used for updating inspectors via SerializedObject::UpdateIfRequiredOrScript()
                    // and thus the cached dirty index in SerializedObject is not updated meaning the source object is not reloaded even though it changed)
                    if (sourceFileChangedAfterSaving && rebuildInspectors)
                    {
                        EditorUtility.ForceRebuildInspectors();
                    }
                }
            }
        }
        // Internal for testing framework
        internal void SaveDirtyPrefabAssets(bool rebuildInspectors)
        {
            if (assetTargets == null)
            {
                return;
            }

            if (assetTarget == null)
            {
                return;
            }

            m_DirtyPrefabAssets.Clear();
            foreach (var asset in assetTargets)
            {
                // The asset could have been deleted when this method is called from OnDestroy().
                // E.g delete the selected prefab asset from the Project Browser.
                if (asset == null)
                {
                    continue;
                }

                if (!EditorUtility.IsPersistent(asset))
                {
                    continue;
                }

                if (!(asset is GameObject))
                {
                    continue;
                }

                var rootGameObject = (GameObject)asset;
                if (IsDirty(rootGameObject))
                {
                    m_DirtyPrefabAssets.Add(rootGameObject);
                }
            }

            if (m_DirtyPrefabAssets.Count > 0)
            {
                bool savedPrefab = false;
                AssetDatabase.StartAssetEditing();
                try
                {
                    foreach (var rootGameObject in m_DirtyPrefabAssets)
                    {
                        bool savedSuccesfully;
                        PrefabUtility.SavePrefabAsset(rootGameObject, out savedSuccesfully);
                        if (!savedSuccesfully)
                        {
                            string title   = L10n.Tr("Saving Failed");
                            string message = L10n.Tr("Check the Console window to get more insight into what needs to be fixed on the Prefab Asset.\n\nYou can open Prefab Mode to fix any issues on child GameObjects");
                            EditorUtility.DisplayDialog(title, message, L10n.Tr("OK"));

                            m_SavingHasFailed = true;
                            break;
                        }

                        savedPrefab |= savedSuccesfully;
                    }
                }
                finally
                {
                    AssetDatabase.StopAssetEditing();

                    // All inspectors needs to be rebuild to ensure property changes are reflected after saving the Prefab shown.
                    // (Saving clears the m_DirtyIndex of the target which is used for updating inspectors via SerializedObject::UpdateIfRequiredOrScript()
                    // and thus the cached dirty index in SerializedObject is not updated meaning the source object is not reloaded even though it changed)
                    if (savedPrefab && rebuildInspectors)
                    {
                        EditorUtility.ForceRebuildInspectors();
                    }
                }
            }
        }
        bool ApplyAll()
        {
            // Collect Prefab Asset paths and also check if there's more than one of the same.
            HashSet <string> prefabAssetPaths = new HashSet <string>();
            bool             multipleOfSame   = false;

            for (int i = 0; i < m_SelectedGameObjects.Length; i++)
            {
                string prefabAssetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(m_SelectedGameObjects[i]);
                if (prefabAssetPaths.Contains(prefabAssetPath))
                {
                    multipleOfSame = true;
                }
                else
                {
                    prefabAssetPaths.Add(prefabAssetPath);
                }
            }

            // If more than one instance of the same Prefab Asset, show dialog to user.
            if (multipleOfSame && !EditorUtility.DisplayDialog(
                    L10n.Tr("Multiple instances of same Prefab Asset"),
                    L10n.Tr("Multiple instances of the same Prefab Asset were detected. Potentially conflicting overrides will be applied sequentially and will overwrite each other."),
                    L10n.Tr("OK"),
                    L10n.Tr("Cancel")))
            {
                return(false);
            }

            // Make sure assets are checked out in version control.
            if (!PrefabUtility.PromptAndCheckoutPrefabIfNeeded(prefabAssetPaths.ToArray(), PrefabUtility.SaveVerb.Apply))
            {
                return(false);
            }

            var undoStructs = new List <ApplyAllUndo>();
            var actionName  = "ApplyAll";

            for (var i = 0; i < m_SelectedGameObjects.Length; i++)
            {
                var us = new ApplyAllUndo();
                us.correspondingSourceObject = (GameObject)PrefabUtility.GetCorrespondingObjectFromSource(m_SelectedGameObjects[i]);
                Undo.RegisterFullObjectHierarchyUndo(us.correspondingSourceObject, actionName); // handles changes to existing objects and object what will be deleted but not objects that are created
                GameObject prefabInstanceRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(m_SelectedGameObjects[i]);
                Undo.RegisterFullObjectHierarchyUndo(prefabInstanceRoot, actionName);

                us.prefabHierarchy = new HashSet <int>();
                PrefabUtility.GetObjectListFromHierarchy(us.prefabHierarchy, us.correspondingSourceObject);
                undoStructs.Add(us);
            }

            // Apply sequentially.
            AssetDatabase.StartAssetEditing();
            try
            {
                foreach (var t in m_SelectedGameObjects)
                {
                    PrefabUtility.ApplyPrefabInstance(t, InteractionMode.UserAction);
                }
            }
            finally
            {
                AssetDatabase.StopAssetEditing();
            }

            foreach (var t in undoStructs)
            {
                PrefabUtility.RegisterNewObjects(t.correspondingSourceObject, t.prefabHierarchy, actionName);
            }

            EditorUtility.ForceRebuildInspectors();
            return(true);
        }