Last active
October 24, 2018 11:31
-
-
Save robotron2084/8c5973d9bb24d3b2b8d2c03ddb5c79de to your computer and use it in GitHub Desktop.
REALLY breaks it! Really good.
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 UnityEngine; | |
using UnityEditor; | |
public class ReallyBreakPrefabInstance | |
{ | |
[MenuItem ("GameObject/REALLY Break Prefab Instance")] | |
public static void BreakIt() | |
{ | |
Transform xForm = Selection.activeTransform; | |
if(xForm != null) | |
{ | |
GameObject go = xForm.gameObject; | |
PrefabUtility.DisconnectPrefabInstance(go); | |
breakInstances(go); | |
} | |
} | |
public static void breakInstances(GameObject go) | |
{ | |
SerializedObject so = new SerializedObject(go); | |
SerializedProperty prop = so.FindProperty("m_PrefabParentObject"); | |
prop.objectReferenceValue = null; | |
so.ApplyModifiedProperties(); | |
Component[] components = go.GetComponents<Component>(); | |
foreach(Component c in components) | |
{ | |
so = new SerializedObject(c); | |
prop = so.FindProperty("m_PrefabParentObject"); | |
prop.objectReferenceValue = null; | |
so.ApplyModifiedProperties(); | |
} | |
foreach(Transform child in go.transform) | |
{ | |
breakInstances(child.gameObject); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment