[add] 替換資源
This commit is contained in:
parent
c5f2494657
commit
f836b1ecaf
34
index.html
34
index.html
@ -3,21 +3,43 @@
|
||||
<h1 style="text-align:center">Uuid Convert</h1>
|
||||
<hr />
|
||||
<div>
|
||||
<h2 style="text-align:left">1. 填入要轉換的UUID</h2>
|
||||
<h2 style="text-align:left">1. 填入要轉換的資源</h2>
|
||||
</div>
|
||||
<hr />
|
||||
<div>
|
||||
<h1 style="text-align:left">要轉換的UUID</h1>
|
||||
<div class="input-group input-group-lg">
|
||||
<input id="uuid" type="text" class="form-control" placeholder="UUID">
|
||||
</div>
|
||||
<br>
|
||||
<div id="ReplaceResource1" style="display:''">
|
||||
<h1 style="text-align:left">要轉換的UUID</h1>
|
||||
<div class="input-group input-group-lg">
|
||||
<input id="uuid" type="text" class="form-control" placeholder="UUID">
|
||||
</div>
|
||||
<br>
|
||||
</div>
|
||||
<div id="ReplaceResource2" style="display:none">
|
||||
<h3 style="text-align:left">原本的資源</h3>
|
||||
</div>
|
||||
<div class="input-group input-group-lg">
|
||||
<ui-asset id="asset" class="flex-1" type="native-asset" droppable="asset">
|
||||
</ui-asset>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div>
|
||||
<ui-checkbox id="isReplaceResource">是否替換資源</ui-checkbox>
|
||||
<div id="ReplaceResource" style="display:none">
|
||||
<h3 style="text-align:left">2. 要覆蓋上去的資源(TS)</h3>
|
||||
<div class="input-group input-group-lg">
|
||||
<ui-asset id="asset2" class="flex-1" type="native-asset" droppable="asset">
|
||||
</ui-asset>
|
||||
</div>
|
||||
<hr />
|
||||
<h3 style="text-align:left">3. 需要替換的檔案(Scene、Prefab)</h3>
|
||||
<div class="input-group input-group-lg">
|
||||
<ui-asset id="source" class="flex-1" type="native-asset" droppable="asset">
|
||||
</ui-asset>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div style="text-align:right">
|
||||
<ui-button id="run" class="blue btn btn-primary btn-lg btn-block">執行</ui-button>
|
||||
</div>
|
||||
|
151
main.js
151
main.js
@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var fs = require('fs'); // 引用檔案物件
|
||||
const EditorAPI = require('./src/main/editor-api');
|
||||
|
||||
// ------------decode-uuid
|
||||
@ -21,69 +21,98 @@ 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
|
||||
}
|
||||
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;
|
||||
let long_uuid;
|
||||
let short_uuid;
|
||||
if (needconvertuuid.indexOf("-") === -1) {
|
||||
// let convertuuid = this.decodeUuid(needconvertuuid);
|
||||
let convertuuid = EditorAPI.decompressUuid(needconvertuuid);
|
||||
uuid = convertuuid;
|
||||
short_uuid = needconvertuuid;
|
||||
long_uuid = convertuuid;
|
||||
} else {
|
||||
// let convertuuid = this.compressUuid(needconvertuuid);
|
||||
let convertuuid = EditorAPI.compressUuid(needconvertuuid);
|
||||
uuid = needconvertuuid;
|
||||
short_uuid = convertuuid;
|
||||
long_uuid = needconvertuuid;
|
||||
}
|
||||
Editor.log('short uuid', short_uuid);
|
||||
Editor.log('long uuid', long_uuid);
|
||||
Editor.Ipc.sendToAll('assets:hint', uuid);
|
||||
Editor.log('path: ', Editor.assetdb.uuidToUrl(uuid));
|
||||
} catch (error) {
|
||||
Editor.log(`uuidconvert error: ${error}`);
|
||||
}
|
||||
},
|
||||
load() {
|
||||
this.init();
|
||||
},
|
||||
unload() {
|
||||
// Editor.log("卸載執行");
|
||||
},
|
||||
/** 初始化 */
|
||||
init() {
|
||||
// this.createDirectory();
|
||||
},
|
||||
/** 讀取資源資訊 */
|
||||
uuidconvert(...args) {
|
||||
let self = this;
|
||||
try {
|
||||
let needconvertuuid = args[0];
|
||||
let long_uuid;
|
||||
let short_uuid;
|
||||
let path;
|
||||
if (needconvertuuid.indexOf("-") === -1) {
|
||||
// let convertuuid = this.decodeUuid(needconvertuuid);
|
||||
let convertuuid = EditorAPI.decompressUuid(needconvertuuid);
|
||||
short_uuid = needconvertuuid;
|
||||
long_uuid = convertuuid;
|
||||
} else {
|
||||
// let convertuuid = this.compressUuid(needconvertuuid);
|
||||
let convertuuid = EditorAPI.compressUuid(needconvertuuid);
|
||||
short_uuid = convertuuid;
|
||||
long_uuid = needconvertuuid;
|
||||
}
|
||||
path = Editor.assetdb.uuidToUrl(long_uuid);
|
||||
return [short_uuid, long_uuid, path];
|
||||
} catch (error) {
|
||||
Editor.error(`uuidconvert error: ${error}`);
|
||||
}
|
||||
},
|
||||
/** 替換資源 */
|
||||
replaceResource(...args) {
|
||||
try {
|
||||
let uuid1 = args[0];
|
||||
let uuid2 = args[1];
|
||||
let source = args[2];
|
||||
let [short_uuid1, long_uuid1, path1] = this.uuidconvert(uuid1);
|
||||
let [short_uuid2, long_uuid2, path2] = this.uuidconvert(uuid2);
|
||||
let [short_uuid3, long_uuid3, path3] = this.uuidconvert(source);
|
||||
// Editor.log(`path1: ${uuid1}`);
|
||||
// Editor.log(`path2: ${uuid2}`);
|
||||
// Editor.log(`path3: ${source}`);
|
||||
|
||||
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);
|
||||
// });
|
||||
// },
|
||||
},
|
||||
let sourceInfo = EditorAPI.assetInfoByUuid(source);
|
||||
let source_path = sourceInfo.path;
|
||||
let sourceData = fs.readFileSync(source_path, "utf8"); // 讀取檔案
|
||||
sourceData = sourceData.replace(new RegExp(short_uuid1, 'g'), short_uuid2);
|
||||
fs.writeFileSync(source_path, sourceData);
|
||||
Editor.assetdb.refresh(path3, function (err, results) { });
|
||||
} catch (error) {
|
||||
Editor.error(`replaceResource error: ${error}`);
|
||||
}
|
||||
},
|
||||
|
||||
messages: {
|
||||
/** 打開面板 */
|
||||
"open-panel"() {
|
||||
Editor.Panel.open("uuidconvert");
|
||||
Editor.log("Uuid Convert Ver 20220818");
|
||||
},
|
||||
/** 保存按鈕點擊 */
|
||||
"run-click"(event, ...args) {
|
||||
// this.uuidconvert(...args);
|
||||
let [short_uuid, long_uuid, path] = this.uuidconvert(...args);
|
||||
Editor.log('short uuid', short_uuid);
|
||||
Editor.log('long uuid', long_uuid);
|
||||
Editor.Ipc.sendToAll('assets:hint', long_uuid);
|
||||
Editor.log('path: ', path);
|
||||
},
|
||||
/** 保存按鈕點擊 */
|
||||
"replaceResource"(event, ...args) {
|
||||
this.replaceResource(...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);
|
||||
// });
|
||||
// },
|
||||
},
|
||||
|
||||
}
|
@ -2,40 +2,66 @@ const PACKAGE_NAME = "uuidconvert";
|
||||
const fs = require("fs");
|
||||
|
||||
Editor.Panel.extend({
|
||||
style: fs.readFileSync(Editor.url(`packages://${PACKAGE_NAME}/static/style/default/index.css`), 'utf-8')
|
||||
.concat(fs.readFileSync(Editor.url(`packages://${PACKAGE_NAME}/static/style/default/bootstrap.min.css`), 'utf-8')),
|
||||
style: fs.readFileSync(Editor.url(`packages://${PACKAGE_NAME}/static/style/default/index.css`), 'utf-8')
|
||||
.concat(fs.readFileSync(Editor.url(`packages://${PACKAGE_NAME}/static/style/default/bootstrap.min.css`), 'utf-8')),
|
||||
|
||||
template: fs.readFileSync(
|
||||
Editor.url(`packages://${PACKAGE_NAME}/index.html`), 'utf-8'),
|
||||
template: fs.readFileSync(
|
||||
Editor.url(`packages://${PACKAGE_NAME}/index.html`), 'utf-8'),
|
||||
|
||||
$: {
|
||||
run: '#run',
|
||||
uuid: '#uuid',
|
||||
asset: '#asset',
|
||||
},
|
||||
$: {
|
||||
run: '#run',
|
||||
uuid: '#uuid',
|
||||
asset: '#asset',
|
||||
asset2: '#asset2',
|
||||
source: '#source',
|
||||
isReplaceResource: '#isReplaceResource',
|
||||
ReplaceResource: '#ReplaceResource',
|
||||
ReplaceResource1: '#ReplaceResource1',
|
||||
ReplaceResource2: '#ReplaceResource2',
|
||||
},
|
||||
|
||||
ready() {
|
||||
this.$run.addEventListener("confirm", this.methods.run.bind(this));
|
||||
},
|
||||
ready() {
|
||||
this.$run.addEventListener("confirm", this.methods.run.bind(this));
|
||||
this.$isReplaceResource.addEventListener("change", this.methods.setReplaceResource.bind(this));
|
||||
},
|
||||
|
||||
methods: {
|
||||
run() {
|
||||
let uuid = "";
|
||||
// Editor.log(`$asset: ${this.$asset.value}`);
|
||||
if (!this.$uuid.value) {
|
||||
if (!this.$asset.value) {
|
||||
Editor.error("請輸入要轉換的UUID");
|
||||
return;
|
||||
} else {
|
||||
uuid = this.$asset.value;
|
||||
}
|
||||
} else {
|
||||
uuid = this.$uuid.value;
|
||||
}
|
||||
Editor.Ipc.sendToMain("uuidconvert:run-click", uuid);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
run() {
|
||||
let uuid = "";
|
||||
// Editor.log(`$asset: ${this.$asset.value}`);
|
||||
if (!this.$uuid.value) {
|
||||
if (!this.$asset.value) {
|
||||
Editor.error("請輸入要轉換的UUID");
|
||||
return;
|
||||
} else {
|
||||
uuid = this.$asset.value;
|
||||
}
|
||||
} else {
|
||||
uuid = this.$uuid.value;
|
||||
}
|
||||
let ReplaceResource = this.$isReplaceResource.value;
|
||||
if (ReplaceResource) {
|
||||
// if (!this.$asset2.value) {
|
||||
// Editor.error("請輸入要取代的資源");
|
||||
// return;
|
||||
// } else if (!this.$source.value) {
|
||||
// Editor.error("請輸入要取代的檔案");
|
||||
// return;
|
||||
// }
|
||||
Editor.Ipc.sendToMain("uuidconvert:replaceResource", uuid, this.$asset2.value, this.$source.value);
|
||||
} else {
|
||||
Editor.Ipc.sendToMain("uuidconvert:run-click", uuid);
|
||||
}
|
||||
},
|
||||
setReplaceResource() {
|
||||
// Editor.log(`$isReplaceResource: ${this.$isReplaceResource.value}`);
|
||||
let ReplaceResource = this.$isReplaceResource.value;
|
||||
this.$ReplaceResource.style.display = ReplaceResource ? "" : "none";
|
||||
this.$ReplaceResource1.style.display = ReplaceResource ? "none" : "";
|
||||
this.$ReplaceResource2.style.display = ReplaceResource ? "" : "none";
|
||||
},
|
||||
},
|
||||
|
||||
messages: {
|
||||
}
|
||||
messages: {
|
||||
}
|
||||
});
|
@ -1,37 +1,65 @@
|
||||
"use strict";
|
||||
let fs = require("fs");
|
||||
let path = require("path");
|
||||
const EditorAPI = require('./src/main/editor-api');
|
||||
|
||||
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}`);
|
||||
/**
|
||||
* 獲取場景節點下的配置信息
|
||||
* @param event event
|
||||
* @param data 這邊把panel的Node帶進來
|
||||
*/
|
||||
"replaceResource": function (event, request) {
|
||||
let self = this;
|
||||
var response = null;
|
||||
var args = request.args;
|
||||
try {
|
||||
let uuid1 = args[0];
|
||||
let uuid2 = args[1];
|
||||
let uuid3 = args[2];
|
||||
let path = Editor.assetdb.uuidToUrl(uuid3);
|
||||
// let assetInfo = EditorAPI.assetInfoByUuid(uuid1);
|
||||
Editor.log(`path: ${path}`);
|
||||
// Editor.log(`node: ${JSON.stringify(assetInfo)}`);
|
||||
// let Version_path = Version_assetInfo.path;
|
||||
// Editor.log("Version_path: " + Version_path);
|
||||
// let Version = fs.readFileSync(Version_path, "utf8"); // 讀取檔案
|
||||
// Editor.log(`uuid3: ${uuid3}`);
|
||||
// Editor.assetdb.queryInfoByUuid(uuid1, function (err, info) {
|
||||
// Editor.log(`path: ${info.path}`);
|
||||
// Editor.log(`url: ${info.url}`);
|
||||
// Editor.log(`type: ${info.type}`);
|
||||
// // Editor.assetdb.queryAssets(info.url, info.type, function (err, info) {
|
||||
// // Editor.log(`info: ${JSON.stringify(info)}`);
|
||||
// // });
|
||||
// });
|
||||
|
||||
// this.fileSearch(fsPath);
|
||||
// Editor.Selection.select('asset', uuid1);
|
||||
// Editor.Selection.clear('node')
|
||||
// let nodeUuids = Editor.Selection.curSelection("node");
|
||||
// Editor.Ipc.sendToPanel("scene", "scene:create-nodes-by-uuids", [uuid1], nodeUuids, { unlinkPrefab: null })
|
||||
// Editor.Selection.select('node', uuid1)
|
||||
// nodeUuids = Editor.Selection.curSelection("node");
|
||||
|
||||
let res = {
|
||||
url: url,
|
||||
fsPath, fsPath
|
||||
}
|
||||
response = JSON.stringify(res);
|
||||
} catch (error) {
|
||||
Editor.log(`getFsPath error: ${error}`);
|
||||
}
|
||||
if (event.reply) {
|
||||
event.reply(null, response);
|
||||
}
|
||||
},
|
||||
// let source = cc.find("SlotPaytable_66");
|
||||
// // 修改运行中的节点属性:
|
||||
// Editor.Ipc.sendToPanel('scene', 'scene:set-property', {
|
||||
// id: uuid1,
|
||||
// path: "name",//要修改的属性
|
||||
// type: "String",
|
||||
// value: "8787",
|
||||
// isSubProp: false,
|
||||
// });
|
||||
// Editor.log(`node: ${JSON.stringify(source)}`);
|
||||
// Editor.log(`node: ${source}`);
|
||||
|
||||
// response = JSON.stringify(res);
|
||||
} catch (error) {
|
||||
Editor.error(`replaceResource error: ${error}`);
|
||||
}
|
||||
response = "666";
|
||||
if (event.reply) {
|
||||
event.reply(null, response);
|
||||
}
|
||||
},
|
||||
};
|
@ -37,6 +37,22 @@ const EditorAPI = {
|
||||
return Editor.assetdb.assetInfoByUuid(uuid);
|
||||
},
|
||||
|
||||
/**
|
||||
* 通过 uuid 获取资源信息
|
||||
* @param {string} uuid
|
||||
*/
|
||||
queryInfoByUuid(uuid, Function) {
|
||||
Editor.assetdb.queryInfoByUuid(uuid3, Function(err, info));
|
||||
},
|
||||
|
||||
/**
|
||||
* 通过 uuid 获取资源信息
|
||||
* @param {string} uuid
|
||||
*/
|
||||
queryAssets(url, type, Function) {
|
||||
Editor.assetdb.queryAssets(url, type, Function(err, info));
|
||||
},
|
||||
|
||||
/**
|
||||
* 通过 uuid 获取子资源信息
|
||||
* @param {string} uuid
|
||||
|
Loading…
Reference in New Issue
Block a user