unity 保存实例到新预制,保存实例到原预制
创始人
2024-11-16 03:34:48
0

保存预制,很简单的功能,但是走了弯路,记录一下吧

private void SavePrefab(Transform root) {     PrefabInstanceStatus status = PrefabUtility.GetPrefabInstanceStatus(Root.gameObject);      if (status == PrefabInstanceStatus.NotAPrefab)     {         // 如果不是预制件,创建一个新的预制件         string path = EditorUtility.SaveFilePanel("Save prefab", "Assets/", Root.name + ".prefab", "prefab");         if (path.Length != 0)         {             bool suc;             PrefabUtility.SaveAsPrefabAssetAndConnect(Root.gameObject, path, InteractionMode.UserAction, out suc);             Debug.Log("suc =" + suc);         }     }     else {         string prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(Root.gameObject);         Debug.Log($"{prefabPath}");         PrefabUtility.SaveAsPrefabAssetAndConnect(Root.gameObject, prefabPath, InteractionMode.UserAction);         //Debug.Log("suc="+ suc);     }    }

如果要保存的Gameobject 本身就是一个预制,不能用下方方法

PrefabUtility.SavePrefabAsset(GameObject root) 这个不是实例才生效,否则报错:

ArgumentException: Can't save a Prefab instance

报错的原因:只要物体拖到场景里,就是一个实例了,所以这个只能用不是实例的物体才可以用

相关内容

热门资讯

9分钟了解!we poker辅... 9分钟了解!we poker辅助器下载,智星德州辅助译码插件靠谱吗(透视)从前有开挂辅助器(真实有挂...
实测教程!wpk系统是否存在透... 《实测教程!wpk系统是否存在透视挂行为,德州局透视脚本下载安装最新版本(透视)切实有开挂辅助器(有...
免费测试版!pokemmo辅助... 免费测试版!pokemmo辅助工具,hhpoker透视挂码怎么用(透视)一直有开挂辅助安装(有开挂细...
透视新版!hhpoker德州机... 透视新版!hhpoker德州机器人,wepoker怎么发冤家牌(透视)原先有开挂辅助安装(有人有开挂...
盘点几款!pokemmo辅助器... 盘点几款!pokemmo辅助器脚本下载,werplan辅助软件(透视)竟然有开挂辅助挂(有开挂头条)...
推荐一款!wepoker有辅助... 推荐一款!wepoker有辅助功能吗,poker辅助器免费安装(透视)原生有开挂辅助黑科技(有开挂教...
玩家必备科普!wpk私人局有透... 玩家必备科普!wpk私人局有透视吗,impoker辅助(透视)从前有开挂辅助下载(果真有开挂);玩家...
最新技巧!wepoker游戏下... 最新技巧!wepoker游戏下载,德州局hhpoker(透视)切实有开挂辅助神器(有开挂详细)是一款...
避坑细节!wepoker私人局... 【福星临门,好运相随】;避坑细节!wepoker私人局辅助挂,wepoker免费钻石(透视)总是有开...
传递经验!wepoker有辅助... 传递经验!wepoker有辅助吗,wepoker辅助软件价格(透视)本来有开挂辅助工具(讲解有挂);...