Skip to content

Instantly share code, notes, and snippets.

@inertiave
Created February 23, 2020 11:51
Show Gist options
  • Save inertiave/91847d6a6958f87581ac3624f9e92b97 to your computer and use it in GitHub Desktop.
Save inertiave/91847d6a6958f87581ac3624f9e92b97 to your computer and use it in GitHub Desktop.
스크립트로 네스티드 프리팹을 편집하는 방법 How to edit nested prefab by script after 2018.3
using UnityEngine;
using UnityEditor;
public class EditPrefab {
[MenuItem("Prefab/Edit Prefabs")]
private static void EditPrefabs() {
AssetDatabase.StartAssetEditing();
var prefabs = AssetDatabase.FindAssets("prefab t:Prefab", new string[] {"Assets/Prefabs"});
foreach (var prefab in prefabs){
var path = AssetDatabase.GUIDToAssetPath(prefab);
var loaded = PrefabUtility.LoadPrefabContents(path);
// change prefab here
UnityEngine.Object.DestroyImmediate(loaded.GetComponent(typeof(Collider)));
// unload
PrefabUtility.SaveAsPrefabAsset(loaded, path);
PrefabUtility.UnloadPrefabContents(loaded);
}
AssetDatabase.StopAssetEditing();
AssetDatabase.SaveAssets();
Debug.Log($"{prefabs.Length} items processed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment