/*创建预制体*/ async Task creatorPrefab(string filePath) {
//这个相对路径最好修改为当前脚本路径,具体方法参考我另外一篇获得脚本路径得文章 GameObject _newPrefab = AssetDatabase.
LoadAssetAtPath<GameObject>(
"Assets/Editor/XLua/EditorWindow/Function2/ModleDialog.prefab"); _newPrefab =
GameObject.Instantiate(_newPrefab);//先实例化出来 await Task.Delay(System.TimeSpan.
FromSeconds(0.2));延时一下 //保存到filePath路径下 Object createObj = PrefabUtility.
SaveAsPrefabAsset(_newPrefab,filePath);//使用绝对路径会警告,尽量转为相对路径 GameObject.
DestroyImmediate(_newPrefab);//立即删除实例化出来的物体 }
示例
/*模板预制体*/ Task _prefabtask = creatorPrefab(@"Assets/Resources/Prefabs/UI/"+
enableName+"/"+enableName+".prefab");