[MenuItem("Extend/场景工具/预制体一键Apply")]
public static void OnekeyApply()
{
Scene scene = SceneManager.GetActiveScene();
foreach (GameObject go in scene.GetRootGameObjects())
{
ApplyByRoot(go);
}
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
}
private static void ApplyByRoot(GameObject root)
{
PrefabType type = PrefabUtility.GetPrefabType(root);
if (type == PrefabType.PrefabInstance || type == PrefabType.DisconnectedPrefabInstance)
{
string path = AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(root));
//CreateNew(root,path);
PrefabUtility.ReplacePrefab(root, PrefabUtility.GetPrefabParent(root), ReplacePrefabOptions.ConnectToPrefab);
}
else
{
for(int i =0;i < root.transform.childCount;i++)
{
ApplyByRoot(root.transform.GetChild(i).gameObject);
}
}
}