天天看點

備忘:cocos creater 插件常用指令

前言:

cocos 論壇找的文章。為了防止cocos論壇出問題,提前備份一下,友善查找

cocos creater 官方文檔已有的api 請移步官方文檔

官方常用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例子,粘貼搬磚專用:

// 清除選中
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: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”
“[email protected]:main2renderer”
“[email protected]: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/[email protected]:broadcast”
“@base/[email protected]:send-reply”
“@base/[email protected]: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”


           

事件參數格式擷取:

在 Editor.Ipc.sendToPanel/ Editor.Ipc.sendToMain/ Editor.Ipc.sendToAll
這些函數入口打上條件斷點檢視發送的資料格式
或者将creaotr編輯器源碼全部下載下傳後格式化後用編輯器全局搜尋相關指令跟蹤實作原理