使用代码在批量修改Prefab时,如果涉及到删除组件或节点,使用SetDirty保存会提示报错
1 |
Destroying assets is not permitted to avoid data loss |
这时就需要修改保存Prefab方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
if (PrefabUtility.GetPrefabAssetType(prefab) == PrefabAssetType.NotAPrefab) { GameObject instance = prefab; DoSomeThing(instance); //写自己逻辑 EditorUtility.SetDirty(instance); } else { string assetPath = AssetDatabase.GetAssetPath(prefab); GameObject instance = GameObject.Instantiate(prefab); DoSomeThing(instance); //写自己逻辑 PrefabUtility.SaveAsPrefabAsset(instance, assetPath); GameObject.DestroyImmediate(instance); } |
- 本文固定链接: http://www.u3d8.com/?p=2842
- 转载请注明: 网虫虫 在 u3d8.com 发表过