- 最后登录
- 2019-12-25
- 注册时间
- 2012-8-24
- 阅读权限
- 90
- 积分
- 71088
- 纳金币
- 52336
- 精华
- 343
|
来自: PlayerA
一个场景下可能包含多个预设体,当美术修改预设体后,可能因为忘记apply提交svn导致很多不必要的麻烦。下面介绍一键apply场景下所有预设体的方法。
[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);
}
}
}
|
|