EditorUtility.DisplayProgressBar("Modify Prefab", "Please wait...", 0);
string[] ids = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/Resources/Prefabs"});
for (int i = 0; i < ids.Length; i++) {
string path = AssetDatabase.GUIDToAssetPath(ids[i]);
GameObject prefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
GameObject instance = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
// change instance
Transform[] trans = instance.GetComponentsInChildren<Transform>();
int layer = LayerMask.NameToLayer("Player");
for (int j = 0; j < trans.Length; j++) {
trans[j].gameObject.layer = layer;
}
// other change instance ... ...
// save
PrefabUtility.ReplacePrefab(instance, prefab, ReplacePrefabOptions.ConnectToPrefab);
DestroyImmediate(instance);
EditorUtility.DisplayProgressBar("Modify Prefab", "Please wait...", i/(float)ids.Length);
}
AssetDatabase.SaveAssets();
EditorUtility.ClearProgressBar();
参考链接
- https://blog.csdn.net/adamwu1988/article/details/55252935
- http://answers.unity3d.com/questions/996188/modify-prefabs-in-editor-script.html