kingBook

导航

Cocos Creator Editor 编辑器扩展API记录

更多:
https://forum.cocos.org/t/creator-api/92605
https://blog.csdn.net/qq_17209641/article/details/106822296

let nodeUuids=Editor.Selection.curSelection("node");
let node=cc.engine.getInstanceById(nodeUuids[0]);//获取当前选中的节点
let colliders=node.getComponents(cc.PhysicsCollider);//获取当前选中的节点的组件(在场景脚本执行)


Editor.Selection.curSelection('node');//获取NodeTree面板选中的Node的uuid列表

Editor.Selection.curSelection("asset");//获取assets面板中选中的资源数组

Editor.Selection.curGlobalActivate();//获取assets面板中最后一个选中的资源
Editor.Selection.curActivate("asset");//获取assets面板中最后一个选中的资源

//进入指定预制件的预制件模式
Editor.Ipc.sendToAll('scene:enter-prefab-edit-mode', '7e977c15-ba64-4b07-8187-1bbf59fbc9fe');

Editor.Selection.select('asset', assetUuid);//选中资源
Editor.Ipc.sendToAll('assets:hint', assetUuid);//高亮资源

let info=Editor.assetdb.assetInfoByUuid(uuid);//获取资源信息info.path,info.url,info.type,info.isSubAsset

cc.AssetLibrary.loadAsset(uuid, ...) //来创建出 cc.Prefab


// 清除选中
Editor.Selection.clear('node')
// 选中资源
Editor.Selection.select('node', uuid)
// 获得选中资源们
Editor.Selection.curSelection("node")

//创建一个空节点:
Editor.Ipc.sendToPanel('scene', 'scene:create-node-by-classid', 'New Node', '', 'parentUuid');//parentUuid不填或""时,添加到场景节点
//添加一个组件:
Editor.Ipc.sendToPanel('scene', 'scene:add-component', nodeID, 'cc.Animation');
//删除一个组件:
Editor.Ipc.sendToPanel('scene', 'scene:remove-component', nodeID, compID);
//复制节点
Editor.Ipc.sendToPanel('scene', 'scene:copy-nodes', uuids);
//粘贴节点:
Editor.Ipc.sendToPanel('scene', 'scene:paste-nodes', parentID);
// 插入个预制节点
Editor.Ipc.sendToPanel("scene","scene:create-nodes-by-uuids",[parfab_uuid],parentUuid,{unlinkPrefab:null})

// 修改运行中的节点属性:
Editor.Ipc.sendToPanel('scene', 'scene:set-property',{
id: info.args.uuid,
path: "name",//要修改的属性
type: "String",
value: info.args.name,
isSubProp: false,
});

// 修改精灵纹理
Editor.Ipc.sendToPanel('scene', 'scene:set-property',{
id: compObj.uuid,
path: "spriteFrame",//要修改的属性
type: "cc.SpriteFrame",
value: {uuid:spriteFrameUuid},
isSubProp: false,
});

let assetInfo=Editor.assetdb.assetInfoByUuid(assetUuid);//info.path,info.url,info.type,info.isSubAsset
// 打印文件信息
Editor.assetdb.queryInfoByUuid(uuid, function (err, info) { // info.path// info.url // info.type});
//移动、重命名文件
Editor.assetdb.move('db://assets/foo/bar/foobar.js', 'db://assets/foo/bar/foobar02.js');
//创建或写入文件
Editor.assetdb.createOrSave('db://assets/foo/bar/foobar.js', 'var foobar = 0;');
//删除文件
Editor.assetdb.delete(['db://assets/foo/bar/foobar.js','db://assets/foo/bar/foobar02.js',]);
//uuid转url
Editor.remote.assetdb.uuidToUrl(file_uuid);
//绝对路径转url
Editor.remote.assetdb.fspathToUrl(abs_path);
//url转uuid
Editor.remote.assetdb.urlToUuid(url);
// 编译uuid
//Editor.remote.UuidUtils.compressUuid(uuid)
// 解uuid
//Editor.remote.UuidUtils.decompressUuid(uuid)
// 生成新uuid
Editor.Utils.UuidUtils.decompressUuid( Editor.Utils.UuidUtils.uuid() )
// 清除选中
Editor.Selection.clear('asset')
// 选中资源
Editor.Selection.select('asset', uuid)
// 获得选中资源们
Editor.Selection.curSelection("asset")
// 检测面板焦点在资源管理器还是层级管理器
let activeInfo = Editor.Selection.curGlobalActivate()
if (activeInfo && activeInfo.type == "node"){
}
else (activeInfo && activeInfo.type == "asset"){
}

API事件名

"assets:copy"
"assets:paste"
"assets:hint" // 在资源管理器高亮该资源,例子: Editor.Ipc.sendToAll('assets:hint', file_uuid)
"assets:search"
"assets:clearSearch"
"assets:new-asset"
"assets:find-usages"
"assets:rename"
"assets:delete"
"assets:start-refresh"
"assets:end-refresh"
"assets:popup-context-menu" // 鼠标右击资源管理菜单
"assets:open-text-file" // 通过外部编辑器打开代码文件,例子: Editor.Ipc.sendToMain('assets:open-text-file',file_uuid);
"selection:selected"
"selection:unselected"
"selection:activated"
"selection:deactivated"
"selection:hoverin"
"selection:hoverout"

"scene:is-ready"
"scene:new-scene"// 新建场景
"scene:saved"// 场景保存
"scene:play-on-device"
"scene:reload-on-device"
"scene:preview-server-scene-stashed"
"scene:load-package-scene-script"
"scene:unload-package-scene-script"
"scene:stash-and-reload"
"scene:soft-reload"
"scene:enter-prefab-edit-mode" // 预制节点加载完,回调里可以获得预制节点文件uuid
"scene:stash-and-save"
"scene:print-simulator-log"
"scene:generate-texture-packer-preview-files"
"scene:query-texture-packer-preview-files"
"scene:export-particle-plist"
"scene:undo" //撤销重置
"scene:redo" //重置
"scene:undo-record"
"scene:undo-commit"
"scene:undo-cancel"
"scene:query-dirty-state"
"scene:query-group-list"
"scene:query-hierarchy"
"scene:query-nodes-by-comp-name"
"scene:query-node"
"scene:query-node-info"
"scene:query-node-functions"
"scene:choose-last-rigid-body"
"scene:choose-next-rigid-body"
"scene:is-child-class-of"
"scene:has-copied-component"
"scene:query-animation-hierarchy"
"scene:query-animation-list"
"scene:query-animation-properties"
"scene:query-animation-record"
"scene:query-animation-clip"
"scene:create-nodes-by-uuids" //通过uuid创建node
"scene:create-node-by-classid"
"scene:create-node-by-prefab" //通过uuid创建node
"scene:new-property"
"scene:reset-property"
"scene:set-property"
"scene:add-component"
"scene:remove-component"
"scene:reset-node"
"scene:reset-all"
"scene:move-up-component"
"scene:move-down-component"
"scene:reset-component"
"scene:copy-component"
"scene:paste-component"
"scene:move-nodes" //移动node
"scene:delete-nodes"//删除node
"scene:copy-nodes"
"scene:paste-nodes"
"scene:duplicate-nodes"
"scene:create-prefab"//创建预制节点
"scene:apply-prefab"
"scene:revert-prefab"
"scene:set-prefab-sync"
"scene:break-prefab-instance"
"scene:link-prefab"
"scene:regenerate-polygon-points"
"scene:change-node-lock"
"scene:query-animation-time"
"scene:animation-time-changed"
"scene:animation-clip-changed"
"scene:save-clip"
"scene:set-animation-speed"
"scene:change-animation-record"
"scene:mount-clip"
"scene:change-animation-state"
"scene:change-animation-current-clip"
"scene:center-nodes"
"scene:ready"// 场景加载完
"scene:reloading"
"scene:animation-record-changed"
"scene:animation-state-changed"
"scene:node-component-added"
"scene:node-component-removed"
"scene:node-component-updated"

"editor:panel-run"
"editor:panel-unload"
"editor:panel-out-of-date"
"editor:ipc-main2panel"
"editor:ipc-main2renderer"
"editor:ipc-reply"
"editor:window-inspect"
"editor:dragstart"
"editor:dragend"
"editor:reset-layout"
"electron-ipc-plus@1.3.4:main2renderer"
"electron-ipc-plus@1.3.4:reply"
"electron-profile:changed"
"editor:query-ipc-events"
"_selection:selected"
"_selection:unselected"
"_selection:activated"
"_selection:deactivated"
"_selection:hoverin"
"_selection:hoverout"
"_selection:context"
"_selection:patch"
"app:global-step-changed"
"@base/electron-base-ipc@1.0.0:broadcast"
"@base/electron-base-ipc@1.0.0:send-reply"
"@base/electron-base-ipc@1.0.0:send"
"asset-db:assets-moved"
"asset-db:asset-changed"
"asset-db:assets-deleted"
"asset-db:state-changed"
"asset-db:watch-state-changed"
"compiler:state-changed"
"editor:console-failed"
"editor:console-warn"
"editor:console-error"
"editor:console-clear"
"preview-server:connects-changed"
"editor:ready"
"profile:local-ip"
"assets:copy"
"assets:paste"
"selection:selected"
"selection:unselected"
"selection:activated"
"selection:deactivated"
"asset-db:assets-created"
"asset-db:asset-uuid-changed"
"assets:hint"
"assets:search"
"assets:clearSearch"
"assets:new-asset"
"assets:find-usages"
"assets:rename"
"assets:delete"
"assets:start-refresh"
"assets:end-refresh"
"editor:panel-undock"
"editor:project-profile-updated"
"scene:is-ready"
"scene:new-scene"
"scene:saved"
"scene:play-on-device"
"scene:reload-on-device"
"scene:preview-server-scene-stashed"
"scene:load-package-scene-script"
"scene:unload-package-scene-script"
"scene:stash-and-reload"
"scene:soft-reload"
"scene:enter-prefab-edit-mode"
"scene:stash-and-save"
"scene:print-simulator-log"
"scene:generate-texture-packer-preview-files"
"scene:query-texture-packer-preview-files"
"scene:export-particle-plist"
"scene:undo"
"scene:redo"
"scene:undo-record"
"scene:undo-commit"
"scene:undo-cancel"
"scene:query-dirty-state"
"scene:query-group-list"
"scene:query-hierarchy"
"scene:query-nodes-by-comp-name"
"scene:query-node"
"scene:query-node-info"
"scene:query-node-functions"
"scene:choose-last-rigid-body"
"scene:choose-next-rigid-body"
"scene:is-child-class-of"
"scene:has-copied-component"
"scene:query-animation-hierarchy"
"scene:query-animation-list"
"scene:query-animation-properties"
"scene:query-animation-record"
"scene:query-animation-clip"
"scene:create-nodes-by-uuids"
"scene:create-node-by-classid"
"scene:create-node-by-prefab"
"scene:new-property"
"scene:reset-property"
"scene:set-property"
"scene:add-component"
"scene:remove-component"
"scene:reset-node"
"scene:reset-all"
"scene:move-up-component"
"scene:move-down-component"
"scene:reset-component"
"scene:copy-component"
"scene:paste-component"
"scene:move-nodes"
"scene:delete-nodes"
"scene:copy-nodes"
"scene:paste-nodes"
"scene:duplicate-nodes"
"scene:create-prefab"
"scene:apply-prefab"
"scene:revert-prefab"
"scene:set-prefab-sync"
"scene:break-prefab-instance"
"scene:link-prefab"
"scene:regenerate-polygon-points"
"scene:change-node-lock"
"scene:query-animation-time"
"scene:animation-time-changed"
"scene:animation-clip-changed"
"scene:save-clip"
"scene:set-animation-speed"
"scene:change-animation-record"
"scene:mount-clip"
"scene:change-animation-state"
"scene:change-animation-current-clip"
"scene:center-nodes"
"selection:hoverin"
"selection:hoverout"
"scene:ready"
"scene:reloading"
"scene:animation-record-changed"
"change-filter"
"delete"
"rename"
"show-path"
"duplicate"
"filter"
"hint"
"hierarchy:hint"
"editor:record-node-changed"
"scene:animation-state-changed"
"scene:node-component-added"
"scene:node-component-removed"
"scene:node-component-updated"
"timeline:property-add"
"timeline:property-remove"
"timeline:property-add-key"
"timeline:property-delete-selected-key"
"timeline:property-clear"
"timeline:edit-event"
"timeline:delete-event"
"timeline:clear-node"
"timeline:rename-node"
"simple-code:customCmd"
"node-library:delete-prefab"
"node-library:rename-prefab"
"node-library:set-prefab-icon"
"onLoad"
"onSearchAccept"
"searchCmd"
"onDestroy"
"editor:console-log"
"editor:console-success"
"editor:console-info"
"console:query-last-error-log"
"editor:console-on-device-play"

可监听的事件名:

"asset-db:assets-created" // 文件创建
"asset-db:assets-moved" //文件移动
"asset-db:asset-changed" // 文件改变
"asset-db:assets-deleted" // 文件删除
"asset-db:state-changed" // 文件状态改变
"asset-db:asset-uuid-changed"

https://github.com/shpz/CreatorClean 资源清理插件

posted on 2020-07-16 10:52  kingBook  阅读(3037)  评论(0编辑  收藏  举报