Created
October 23, 2017 17:08
-
-
Save marcelschmidtdev/e7cd29fe43785bbd66f604a17381ad0d to your computer and use it in GitHub Desktop.
Helper menu to really break Unity prefab instances (removes the Inspector prefab buttons)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
using UnityEngine; | |
public class GameObjectTools | |
{ | |
private const string TempPrefabAssetPath = "Assets/tmp.prefab"; | |
[MenuItem ("GameObject/Really Break Prefab Instance", true)] | |
public static bool ValidateBreakPrefabInstance () | |
{ | |
GameObject selected = Selection.activeGameObject; | |
if (selected == null) | |
{ | |
return false; | |
} | |
PrefabType prefabType = PrefabUtility.GetPrefabType (selected); | |
return prefabType != PrefabType.None && prefabType != PrefabType.Prefab && prefabType != PrefabType.ModelPrefab; | |
} | |
[MenuItem ("GameObject/Really Break Prefab Instance")] | |
public static void BreakPrefabInstance () | |
{ | |
GameObject selected = Selection.activeGameObject; | |
Undo.RegisterFullObjectHierarchyUndo (selected, "Really Break Prefab Instance"); | |
Selection.activeGameObject = null; | |
Object prefab = PrefabUtility.CreateEmptyPrefab (TempPrefabAssetPath); | |
PrefabUtility.ReplacePrefab (selected, prefab, ReplacePrefabOptions.ConnectToPrefab); | |
PrefabUtility.DisconnectPrefabInstance (selected); | |
AssetDatabase.DeleteAsset (TempPrefabAssetPath); | |
AssetDatabase.Refresh (); | |
Selection.activeGameObject = selected; | |
EditorSceneManager.MarkSceneDirty (EditorSceneManager.GetActiveScene ()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment