《creator插件开发常用API命令列表》备忘录

官方文档提供的插件通讯命令列表太少了这里额外做个总结


##【资源管理器API整理】
###官方API文档:
官方文件管理API: 移动、写入、重命名、创建、刷新、获得文件信息…
官方文件管理remote API: 移动、写入、重命名、创建、刷新、获得文件信息、uuid转url、uuid转绝对路径、url转uuid…
官方文件选中状态API: 获得选中的资源、设置选中状态、取消选中、获得选中的是资源还是节点…
参考文档:管理项目资源
参考文档:常用 IPC 消息

官方常用API例子,粘贴搬砖专用:

// 打印文件信息
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”

###可监听的事件名
“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”


##【场景编辑器API整理】
###官方API文档:
官方文件选中状态API: 获得选中的资源、设置选中状态、取消选中、获得选中的是资源还是节点…
参考文档:管理项目资源
参考文档:常用 IPC 消息

官方常用API例子,粘贴搬砖专用:

// 清除选中
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’);
//添加一个组件:
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,
});

API事件名

“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”


##事件来源追踪

// 面板通讯发送口
C:\CocosCreator\resources\electron.asar\renderer\api\ipc-renderer.js
在 ipcRenderer.send 函数设置断点查看面板通讯发送的信息与事件触发来源

##事件终点追踪

// 面板通讯接收口
/events.js
在 EventEmitter.prototype.emit 函数设置断点查看面板通讯接收信息与分发位置

##事件通讯日志打印(必备)

// 用于想知道某个动作会触发什么样的事件时
// 在控制台输入以下这段代码重写通讯函数打印通讯日志: 事件名、参数格式、
func = Editor.Ipc.sendToPanel
Editor.Ipc.sendToPanel = (n,r,…i)=>{console.log(n,r,…i); return func(n,r,…i)}

##编辑器自带面板api调用

非公开的东西仅仅开发自己用的插件
//修改场景编辑模式 2.0后面不支持了
panel = document.getElementById(“tools”)
panel.transformTool = “move” //其它的选项 move ,rotate ,scale ,rect

//场景渲染层
mm = document.getElementById(“scene”)
mm._newScene()
mm._onAlignTop()//顶对齐

//属性面板
mm = document.getElementById(“inspector”)
mm._clear() // 清空面板显示

//当前局域网的地址(127.0.0.1:7456)(2.0以上的版本)
document.getElementById(“toolbar”).__ vue __.$data.url

//当前局域网的地址(127.0.0.1:7456)(2.0以前的版本)
document.getElementById(“playButtons”).dataHost.previewURL;

其它文档

Editor.xxx 相关API
Electron 相关文档

##事件列表

  1. “editor:panel-run”
  2. “editor:panel-unload”
  3. “editor:panel-out-of-date”
  4. “editor:ipc-main2panel”
  5. “editor:ipc-main2renderer”
  6. “editor:ipc-reply”
  7. “editor:window-inspect”
  8. “editor:dragstart”
  9. “editor:dragend”
  10. “editor:reset-layout”
  11. “electron-ipc-plus@1.3.4:main2renderer”
  12. “electron-ipc-plus@1.3.4:reply”
  13. “electron-profile:changed”
  14. “editor:query-ipc-events”
  15. “_selection:selected”
  16. “_selection:unselected”
  17. “_selection:activated”
  18. “_selection:deactivated”
  19. “_selection:hoverin”
  20. “_selection:hoverout”
  21. “_selection:context”
  22. “_selection:patch”
  23. “app:global-step-changed”
  24. @base/electron-base-ipc@1.0.0:broadcast”
  25. @base/electron-base-ipc@1.0.0:send-reply”
  26. @base/electron-base-ipc@1.0.0:send”
  27. “asset-db:assets-moved”
  28. “asset-db:asset-changed”
  29. “asset-db:assets-deleted”
  30. “asset-db:state-changed”
  31. “asset-db:watch-state-changed”
  32. “compiler:state-changed”
  33. “editor:console-failed”
  34. “editor:console-warn”
  35. “editor:console-error”
  36. “editor:console-clear”
  37. “preview-server:connects-changed”
  38. “editor:ready”
  39. “profile:local-ip”
  40. “assets:copy”
  41. “assets:paste”
  42. “selection:selected”
  43. “selection:unselected”
  44. “selection:activated”
  45. “selection:deactivated”
  46. “asset-db:assets-created”
  47. “asset-db:asset-uuid-changed”
  48. “assets:hint”
  49. “assets:search”
  50. “assets:clearSearch”
  51. “assets:new-asset”
  52. “assets:find-usages”
  53. “assets:rename”
  54. “assets:delete”
  55. “assets:start-refresh”
  56. “assets:end-refresh”
  57. “editor:panel-undock”
  58. “editor:project-profile-updated”
  59. “scene:is-ready”
  60. “scene:new-scene”
  61. “scene:saved”
  62. “scene:play-on-device”
  63. “scene:reload-on-device”
  64. “scene:preview-server-scene-stashed”
  65. “scene:load-package-scene-script”
  66. “scene:unload-package-scene-script”
  67. “scene:stash-and-reload”
  68. “scene:soft-reload”
  69. “scene:enter-prefab-edit-mode”
  70. “scene:stash-and-save”
  71. “scene:print-simulator-log”
  72. “scene:generate-texture-packer-preview-files”
  73. “scene:query-texture-packer-preview-files”
  74. “scene:export-particle-plist”
  75. “scene:undo”
  76. “scene:redo”
  77. “scene:undo-record”
  78. “scene:undo-commit”
  79. “scene:undo-cancel”
  80. “scene:query-dirty-state”
  81. “scene:query-group-list”
  82. “scene:query-hierarchy”
  83. “scene:query-nodes-by-comp-name”
  84. “scene:query-node”
  85. “scene:query-node-info”
  86. “scene:query-node-functions”
  87. “scene:choose-last-rigid-body”
  88. “scene:choose-next-rigid-body”
  89. “scene:is-child-class-of”
  90. “scene:has-copied-component”
  91. “scene:query-animation-hierarchy”
  92. “scene:query-animation-list”
  93. “scene:query-animation-properties”
  94. “scene:query-animation-record”
  95. “scene:query-animation-clip”
  96. “scene:create-nodes-by-uuids”
  97. “scene:create-node-by-classid”
  98. “scene:create-node-by-prefab”
  99. “scene:new-property”
  100. “scene:reset-property”
  101. “scene:set-property”
  102. “scene:add-component”
  103. “scene:remove-component”
  104. “scene:reset-node”
  105. “scene:reset-all”
  106. “scene:move-up-component”
  107. “scene:move-down-component”
  108. “scene:reset-component”
  109. “scene:copy-component”
  110. “scene:paste-component”
  111. “scene:move-nodes”
  112. “scene:delete-nodes”
  113. “scene:copy-nodes”
  114. “scene:paste-nodes”
  115. “scene:duplicate-nodes”
  116. “scene:create-prefab”
  117. “scene:apply-prefab”
  118. “scene:revert-prefab”
  119. “scene:set-prefab-sync”
  120. “scene:break-prefab-instance”
  121. “scene:link-prefab”
  122. “scene:regenerate-polygon-points”
  123. “scene:change-node-lock”
  124. “scene:query-animation-time”
  125. “scene:animation-time-changed”
  126. “scene:animation-clip-changed”
  127. “scene:save-clip”
  128. “scene:set-animation-speed”
  129. “scene:change-animation-record”
  130. “scene:mount-clip”
  131. “scene:change-animation-state”
  132. “scene:change-animation-current-clip”
  133. “scene:center-nodes”
  134. “selection:hoverin”
  135. “selection:hoverout”
  136. “scene:ready”
  137. “scene:reloading”
  138. “scene:animation-record-changed”
  139. “change-filter”
  140. “delete”
  141. “rename”
  142. “show-path”
  143. “duplicate”
  144. “filter”
  145. “hint”
  146. “hierarchy:hint”
  147. “editor:record-node-changed”
  148. “scene:animation-state-changed”
  149. “scene:node-component-added”
  150. “scene:node-component-removed”
  151. “scene:node-component-updated”
  152. “timeline:property-add”
  153. “timeline:property-remove”
  154. “timeline:property-add-key”
  155. “timeline:property-delete-selected-key”
  156. “timeline:property-clear”
  157. “timeline:edit-event”
  158. “timeline:delete-event”
  159. “timeline:clear-node”
  160. “timeline:rename-node”
  161. “simple-code:customCmd”
  162. “node-library:delete-prefab”
  163. “node-library:rename-prefab”
  164. “node-library:set-prefab-icon”
  165. “onLoad”
  166. “onSearchAccept”
  167. “searchCmd”
  168. “onDestroy”
  169. “editor:console-log”
  170. “editor:console-success”
  171. “editor:console-info”
  172. “console:query-last-error-log”
  173. “editor:console-on-device-play”

事件参数格式获取:

在 Editor.Ipc.sendToPanel/ Editor.Ipc.sendToMain/ Editor.Ipc.sendToAll
这些函数入口打上条件断点查看发送的数据格式
或者将creaotr编辑器源码全部下载后格式化后用编辑器全局搜索相关命令跟踪实现原理

以上全都是之前懵懵懂懂被坑无数次之后走出的一条插件开发必经之道路

156赞

这个顶你一下。备忘

mark,备用

《creator插件开发通讯命令列表》备忘录

搞不懂官方文档为什么不写清楚都有什么事件

2赞

真是难为的要哭:disappointed_relieved:

当初搞个刷新资源功能都花了两天时间:confused:
写插件就是个玄学

2赞

《creator插件开发通讯命令列表》备忘录

mark11111111

《《creator插件开发通讯命令列表》备忘录》备忘录

至今editor的文档还是纯英文的 而且貌似在列表里还是找不到 搞不懂引擎组的人为什么要这么做。

《creator插件开发通讯命令列表》备忘录

我也mark

在 Editor.Ipc.sendToPanel/ Editor.Ipc.sendToMain/ Editor.Ipc.sendToAll
这些函数入口打上条件断点查看发送的数据格式,这里操作不是很明白,能说说嘛?

// 用于想知道某个动作会触发什么样的事件时
// 在控制台输入以下这段代码重写通讯函数打印通讯日志: 事件名、参数格式、
func = Editor.Ipc.sendToPanel
Editor.Ipc.sendToPanel = (n,r,…i)=>{console.log(n,r,…i); return func(n,r,…i)}

一般我是这样查看未知的通讯事件

一般我是这样查看未知的通讯事件

壮士多谢,俺记下了

很有用 记下了 qqq

mark一下

Mark Mark