[add] first
This commit is contained in:
		
							
								
								
									
										60
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | ||||
| # Cocos Creater OutputComponent | ||||
|  | ||||
| ## 插件 安裝方式 | ||||
|  | ||||
| 1. 安裝在 **項目** 底下 | ||||
| > 把插件資料夾放到項目的packages(跟assets同層) | ||||
|  | ||||
| 2. 安裝在 **全局** 底下 | ||||
| > 把插件資料夾放到C:\Users\%USERNAME%\.CocosCreator\packages | ||||
|  | ||||
| ## 插件稍微說明(都是搬過來的資料  XD) | ||||
|  | ||||
| 剩下沒寫的可以到參考資料裡面看看😀 | ||||
|  | ||||
| 1. 定義你的包描述文件:**package.json** | ||||
| > **name** String - 定義了包的名字,包的名字是全局唯一的,他關係到你今後在官網服務器上登錄時的名字。 | ||||
| >  | ||||
| > **version** String - 版本號,我們推薦使用semver格式管理你的包版本。 | ||||
| >  | ||||
| > **description** String(可选) - 一句話描述你的包是做什麼的。 | ||||
| >  | ||||
| > **author** String(可选) - 擴展包的作者 | ||||
| >  | ||||
| > **main** String (可选) - 入口程序 | ||||
| >  | ||||
| > **scene-script** String (可选) - 調用引擎API 和項目腳本 | ||||
| >  | ||||
| > **main-menu** Object (可选) - 主菜單定義 | ||||
| >  | ||||
| > **有要使用介面的話:** | ||||
| >  | ||||
| > **panel** Object (可选) - 定義的面板在package裡的描述 | ||||
| >  | ||||
| > **注意panel的type有兩種:** | ||||
| >  | ||||
| > dockable:可停靠面板,打開該面板後,可以通過拖拽面板標籤到編輯器裡,實現擴展面板嵌入到編輯器中。下面我們介紹的面板入口程序都是按照可停靠面板的要求聲明的。 | ||||
| >  | ||||
| > simple:簡單Web面板,不可停靠到編輯器主窗口,相當於一份通用的HTML前端頁面。詳細情況請見定義簡單面板。 | ||||
| >  | ||||
| > 在simple-package文件夾下面創建一個panel文件夾,然後在panel文件夾下創建一個index.js或者一個html文件都可以 | ||||
|  | ||||
| 2. 入口程序:**main.js** | ||||
|  | ||||
| 3. 定義介面以及按鈕綁定的方法,和主進程的通信:**index.js** | ||||
|  | ||||
| 3. 可以使用包括全部引擎API 和用戶組件腳本里聲明的方法和屬性:**scene-obtain..js** | ||||
| > 可以在擴展包中獲取到場景裡的Canvas根節點有多少子節點,當然還可以用來對場景節點進行更多的查詢和操作。 | ||||
|  | ||||
| ## 參考資料 | ||||
|  | ||||
| * 你的第一個擴展包 | ||||
| > https://docs.cocos.com/creator/manual/zh/extension/your-first-extension.html | ||||
|  | ||||
| * CocosCreator拓展编辑器 | ||||
| > https://blog.csdn.net/qq_34772097/category_9577457.html | ||||
|  | ||||
| * Cocos Creator Editor 編輯器擴展API記錄 | ||||
| > https://blog.csdn.net/kingbook928/article/details/108659319 | ||||
| > https://blog.csdn.net/qq_17209641/article/details/106822296 | ||||
| > https://forum.cocos.org/t/creator-api/92605 | ||||
							
								
								
									
										83
									
								
								main.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								main.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,83 @@ | ||||
| "use strict"; | ||||
|  | ||||
| const EditorAPI = require('./src/main/editor-api'); | ||||
|  | ||||
| // ------------decode-uuid | ||||
| const BASE64_KEYS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||||
| const values = new Array(123); // max char code in base64Keys | ||||
| for (let i = 0; i < 123; ++i) { values[i] = 64; } // fill with placeholder('=') index | ||||
| for (let i = 0; i < 64; ++i) { values[BASE64_KEYS.charCodeAt(i)] = i; } | ||||
|  | ||||
| // decoded value indexed by base64 char code | ||||
| const BASE64_VALUES = values; | ||||
|  | ||||
| const HexChars = '0123456789abcdef'.split(''); | ||||
|  | ||||
| const _t = ['', '', '', '']; | ||||
| const UuidTemplate = _t.concat(_t, '-', _t, '-', _t, '-', _t, '-', _t, _t, _t); | ||||
| const Indices = UuidTemplate.map((x, i) => x === '-' ? NaN : i).filter(isFinite); | ||||
|  | ||||
|  | ||||
|  | ||||
| let HexMap = {} | ||||
| { | ||||
| 	for (let i = 0; i < HexChars.length; i++) { | ||||
| 		let char = HexChars[i] | ||||
| 		HexMap[char] = i | ||||
| 	} | ||||
| } | ||||
|  | ||||
| module.exports = { | ||||
| 	load() { | ||||
| 		this.init(); | ||||
| 	}, | ||||
| 	unload() { | ||||
| 		// Editor.log("卸載執行"); | ||||
| 	}, | ||||
| 	/** 初始化 */ | ||||
| 	init() { | ||||
| 		// this.createDirectory(); | ||||
| 	}, | ||||
| 	/** 創建Spine節點 */ | ||||
| 	uuidconvert(...args) { | ||||
| 		let self = this; | ||||
| 		try { | ||||
| 			let needconvertuuid = args[0]; | ||||
| 			let uuid; | ||||
| 			if (needconvertuuid.indexOf("-") === -1) { | ||||
| 				// let convertuuid = this.decodeUuid(needconvertuuid); | ||||
| 				let convertuuid = EditorAPI.decompressUuid(needconvertuuid); | ||||
| 				Editor.log('convertuuid', convertuuid); | ||||
| 				uuid = convertuuid; | ||||
| 			} else { | ||||
| 				// let convertuuid = this.compressUuid(needconvertuuid); | ||||
| 				let convertuuid = EditorAPI.compressUuid(needconvertuuid); | ||||
| 				Editor.log('convertuuid', convertuuid); | ||||
| 				uuid = needconvertuuid; | ||||
| 			} | ||||
| 			Editor.Ipc.sendToAll('assets:hint', uuid); | ||||
| 			Editor.log('path: ', Editor.assetdb.uuidToUrl(uuid)); | ||||
| 		} catch (error) { | ||||
| 			Editor.log(`uuidconvert error: ${error}`); | ||||
| 		} | ||||
| 	}, | ||||
|  | ||||
| 	messages: { | ||||
| 		/** 打開面板 */ | ||||
| 		"open-panel"() { | ||||
| 			Editor.Panel.open("uuidconvert"); | ||||
| 		}, | ||||
| 		/** 保存按鈕點擊 */ | ||||
| 		"run-click"(event, ...args) { | ||||
| 			this.uuidconvert(...args); | ||||
| 		}, | ||||
| 		// /** 面板加載完成 */ | ||||
| 		// "panel-load-finish"(evnet, ...args) { | ||||
| 		// Editor.Scene.callSceneScript("uuidconvert", "get-default-info", { args: args }, function (err, response) { | ||||
| 		//     // Editor.log("callSceneScript: " + response); | ||||
| 		//     Editor.Ipc.sendToPanel("uuidconvert", "setDefault", response); | ||||
| 		// }); | ||||
| 		// }, | ||||
| 	}, | ||||
|  | ||||
| } | ||||
							
								
								
									
										21
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| { | ||||
| 	"name": "uuidconvert", | ||||
| 	"version": "0.0.1", | ||||
| 	"description": "Sample-Package", | ||||
| 	"author": "Sample", | ||||
| 	"main": "main.js", | ||||
| 	"scene-script": "scene-obtain.js", | ||||
| 	"engineSupport": true, | ||||
| 	"main-menu": { | ||||
| 		"扩展/Uuid Convert": { | ||||
| 			"message": "uuidconvert:open-panel" | ||||
| 		} | ||||
| 	}, | ||||
| 	"panel": { | ||||
| 		"main": "panel/index.js", | ||||
| 		"type": "dockable", | ||||
| 		"title": "Uuid Convert", | ||||
| 		"width": 400, | ||||
| 		"height": 350 | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										57
									
								
								panel/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								panel/index.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,57 @@ | ||||
| Editor.Panel.extend({ | ||||
| 	style: ` | ||||
|     :host { margin: 5px; } | ||||
|     h2 { color: #f90; } | ||||
|     .bottom { | ||||
|       height: 30px; | ||||
|     } | ||||
|   `, | ||||
|  | ||||
| 	template: ` | ||||
|     <h2 style="text-align:center">Uuid Convert</h2> | ||||
|     <hr /> | ||||
|         <div> | ||||
|             1. 填入要轉換的UUID<br> | ||||
|         </div> | ||||
|     <hr /> | ||||
|         <div> | ||||
|             要轉換的UUID | ||||
|             <ui-input placeholder="UUID" id="uuid"></ui-input> | ||||
|         </div> | ||||
|     <hr /> | ||||
|          <div style="text-align:right"> | ||||
|              <ui-button id="run" class="blue">執行</ui-button> | ||||
|          </div>       | ||||
|   `, | ||||
|  | ||||
| 	$: { | ||||
| 		/** uuid */ | ||||
| 		uuid: "#uuid", | ||||
| 		/** 生成按鈕 */ | ||||
| 		run: "#run", | ||||
| 	}, | ||||
|  | ||||
| 	ready() { | ||||
| 		// Editor.Ipc.sendToMain("uuidconvert:panel-load-finish"); | ||||
| 		this.onClickRun(); | ||||
|  | ||||
| 	}, | ||||
| 	/** 保存按鈕點擊事件 */ | ||||
| 	onClickRun() { | ||||
| 		this.$run.addEventListener("confirm", () => { | ||||
| 			if (!this.$uuid._value) { | ||||
| 				Editor.error("請輸入要轉換的UUID"); | ||||
| 				return; | ||||
| 			} | ||||
| 			Editor.Ipc.sendToMain("uuidconvert:run-click", this.$uuid._value); | ||||
| 		}); | ||||
| 	}, | ||||
| 	messages: { | ||||
| 		// "setDefault": function (event, ...agrs) { | ||||
| 		//     if (event.reply) { | ||||
| 		//         //if no error, the first argument should be null | ||||
| 		//         event.reply(null, "Fine, thank you!"); | ||||
| 		//     } | ||||
| 		// } | ||||
| 	} | ||||
| }); | ||||
							
								
								
									
										37
									
								
								scene-obtain.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								scene-obtain.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| "use strict"; | ||||
| let fs = require("fs"); | ||||
| let path = require("path"); | ||||
|  | ||||
| module.exports = { | ||||
|     /** | ||||
|      * 獲取場景節點下的配置信息 | ||||
|      * @param event event | ||||
|      * @param data 這邊把panel的Node帶進來 | ||||
|      */ | ||||
|     "getFsPath": function (event, request) { | ||||
|         let self = this; | ||||
|         var response = null; | ||||
|         var args = request.args; | ||||
|         try { | ||||
|             let url = `db://assets/${args[0]._value}`; | ||||
|             url = url.replace(/\\/g, "/"); | ||||
|             // let url = `db://assets/=SceneLobby`; | ||||
|             // Editor.log(`url: ${url}`); | ||||
|             let fsPath = Editor.remote.assetdb.urlToFspath(url); | ||||
|             // Editor.log(`fsPath: ${fsPath}`); | ||||
|  | ||||
|             // this.fileSearch(fsPath); | ||||
|  | ||||
|             let res = { | ||||
|                 url: url, | ||||
|                 fsPath, fsPath | ||||
|             } | ||||
|             response = JSON.stringify(res); | ||||
|         } catch (error) { | ||||
|             Editor.log(`getFsPath error: ${error}`); | ||||
|         } | ||||
|         if (event.reply) { | ||||
|             event.reply(null, response); | ||||
|         } | ||||
|     }, | ||||
| }; | ||||
							
								
								
									
										107
									
								
								src/main/editor-api.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								src/main/editor-api.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,107 @@ | ||||
| /** | ||||
|  * 编辑器 API(用于抹平不同版本编辑器之间的差异) | ||||
|  * @author 陈皮皮 (ifaswind) | ||||
|  * @version 20210830 | ||||
|  */ | ||||
| const EditorAPI = { | ||||
|  | ||||
| 	/** | ||||
| 	 * 当前语言 | ||||
| 	 * @returns {string} | ||||
| 	 */ | ||||
| 	getLanguage() { | ||||
| 		return Editor.lang || Editor.I18n.getLanguage(); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * 绝对路径转为编辑器资源路径 | ||||
| 	 * @param {string} fspath  | ||||
| 	 */ | ||||
| 	fspathToUrl(fspath) { | ||||
| 		return Editor.assetdb.fspathToUrl(fspath); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * 编辑器资源路径转为绝对路径 | ||||
| 	 * @param {string} url  | ||||
| 	 */ | ||||
| 	urlToFspath(url) { | ||||
| 		return Editor.assetdb.urlToFspath(url); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * 通过 uuid 获取资源信息 | ||||
| 	 * @param {string} uuid  | ||||
| 	 */ | ||||
| 	assetInfoByUuid(uuid) { | ||||
| 		return Editor.assetdb.assetInfoByUuid(uuid); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * 通过 uuid 获取子资源信息 | ||||
| 	 * @param {string} uuid  | ||||
| 	 */ | ||||
| 	subAssetInfosByUuid(uuid) { | ||||
| 		return Editor.assetdb.subAssetInfosByUuid(uuid); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * 获取当前选中的资源 uuid | ||||
| 	 * @returns {string[]} | ||||
| 	 */ | ||||
| 	getCurrentSelectedAssets() { | ||||
| 		return Editor.Selection.curSelection('asset'); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * 获取当前选中的节点 uuid | ||||
| 	 * @returns {string[]} | ||||
| 	 */ | ||||
| 	getCurrentSelectedNodes() { | ||||
| 		return Editor.Selection.curSelection('node'); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * 是否为 uuid | ||||
| 	 * @param {string} uuid  | ||||
| 	 */ | ||||
| 	isUuid(uuid) { | ||||
| 		return Editor.Utils.UuidUtils.isUuid(uuid); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * 压缩 uuid | ||||
| 	 * @param {string} uuid  | ||||
| 	 */ | ||||
| 	compressUuid(uuid) { | ||||
| 		return Editor.Utils.UuidUtils.compressUuid(uuid); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * 反压缩 uuid | ||||
| 	 * @param {string} uuid  | ||||
| 	 */ | ||||
| 	decompressUuid(uuid) { | ||||
| 		return Editor.Utils.UuidUtils.decompressUuid(uuid); | ||||
| 	}, | ||||
|  | ||||
| 	/** | ||||
| 	 * 获取uuid资源所在bundle的目录 | ||||
| 	 * @param {string} uuid | ||||
| 	 * @returns {string} | ||||
| 	 */ | ||||
| 	uuid2path(uuid) { | ||||
| 		return uuid.substr(0, 2) + "/" + uuid; | ||||
| 	}, | ||||
|  | ||||
| 	/**  | ||||
| 	 * 获取uuid对应的资源所在的文件夹 | ||||
| 	 * @param {string} uuid | ||||
| 	 * @returns {string} | ||||
| 	 */ | ||||
| 	uuiddir(uuid) { | ||||
| 		return uuid.substr(0, 2) | ||||
| 	}, | ||||
| }; | ||||
|  | ||||
| module.exports = EditorAPI; | ||||
		Reference in New Issue
	
	Block a user