你好,现有的 node-library 插件就是管理 prefab 预设的,在顶部 菜单 》 面板 》 Node Library 点击开启
你说的这个我有看过,但好像也不是我的意思,这个我可以自己开发相关插件去生成处理预设吗?有开放相关API不?其实我就想要相关生成预设的API而已
需求是我想自己做个插件来根据设计图自动生成预设的。
那增加component方面呢? 或者我可以在哪里查到相关的接口的?大概源码的哪个类?
节点增加 component 吗,引擎 api 里 node.addComponent(cid: string)
噢,这个编辑器的api跟运行时的那个是一样的呀,好,我试试
谢谢你的抽空回答
你好,3.3.2 距今一年多了,期间 prefab 数据或接口都有过 bug 修复,建议升级到现在最新的 3.7.2,目前 v3.7.x 迭代周期比较长,是比较稳定的版本了,建议尝试一下用它来调用接口做功能插件。
公司项目有3.3.2的维护,要向下兼容插件.在新的版本已经可以了,目前就卡在这步
是用插件环境去生成吗?我在场景去生成的话也是成功的
要生成为资源的节点,先挂在当前场景树上,确保能被查询到
3.7.2 亲测在编辑器扩展的场景脚本可以生成 prefab
const { director } = require('cc');
const scene = director.getScene() as cc.Node;
if (!scene) {
console.error("can not get scene");
return false;
}
const canvas = scene.children[0];
if (!canvas) {
console.error("can not get canvas");
return false;
}
let helloNode: cc.Node | undefined;
for (const child of canvas.children) {
if (child.name === "hello") {
helloNode = child;
break;
}
}
if (!helloNode) {
console.error("can not find hello node");
return;
}
const filePath = `db://assets/prefabs/test.prefab`;
const nodeUuid = helloNode.uuid;
const prefabUuid = await cce.Prefab.createPrefabAssetFromNode(nodeUuid, filePath);
no, 3.8.3 version , bug report error , Message does not exist: asset-db - create-prefab
没找到直接新增的接口,我是直接创建了一个空的prefab,然后使用 ‘asset-db:copy-asset’ 指令复制出新的资源;再使用 ‘asset-db:open-asset’ 打开创建出的预制进行操作。
打开预制后,怎么操作当前打开的预制体呢
谢谢您,我已经解决了,我今天早上发现使用await Editor.Message.request(‘scene’, ‘open-scene’, asset.uuid);也可以打开一个预制体,并且能够在director.getScene()的子物体中找到这个预制体节点,可以正常增删组件,最后调用await Editor.Message.request(‘scene’, ‘save-scene’);保存预制
但是我还是不知道怎么给组件排序,参考帖子: 3.x编辑器扩展怎么统一修改预制体资源 - Creator 3.x - Cocos中文社区,我想把UITransform组件放到Node组件下面,不知道怎么操作




