授人以鱼不如授人以渔
常用方法
添加菜单
[MenuItem("path")]
[CreateAssetMenu(fileName = "", menuName = "")]
从Assets中获取Prefab
GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Res/···")
将GameObject存成Prefab
GameObject root = GameObject.Instantiate(go);
var path = ""; // 路径
// 修改···
PrefabUtility.SaveAsPrefabAsset(root, path);
GameObject.DestroyImediately(root);
批量生成代码
可以将模板存进txt,再将关键字替换成对应的代码段
var path = Path.Combine(Application.dataPath, "folder");
string src = File.ReadAllText(Path.Combine(path, fileName)); // 获取模板
src = src.Replace('#关键字#', content); // 内容替换
File.WriteAllText(Path.Combine(path, targetFileName), src); // 传出代码