[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>
|
<h1 style="text-align:center">Uuid Convert</h1>
|
||||||
<hr />
|
<hr />
|
||||||
<div>
|
<div>
|
||||||
<h2 style="text-align:left">1. 填入要轉換的UUID</h2>
|
<h2 style="text-align:left">1. 填入要轉換的資源</h2>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
<div>
|
<div>
|
||||||
<h1 style="text-align:left">要轉換的UUID</h1>
|
<div id="ReplaceResource1" style="display:''">
|
||||||
<div class="input-group input-group-lg">
|
<h1 style="text-align:left">要轉換的UUID</h1>
|
||||||
<input id="uuid" type="text" class="form-control" placeholder="UUID">
|
<div class="input-group input-group-lg">
|
||||||
</div>
|
<input id="uuid" type="text" class="form-control" placeholder="UUID">
|
||||||
<br>
|
</div>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
<div id="ReplaceResource2" style="display:none">
|
||||||
|
<h3 style="text-align:left">原本的資源</h3>
|
||||||
|
</div>
|
||||||
<div class="input-group input-group-lg">
|
<div class="input-group input-group-lg">
|
||||||
<ui-asset id="asset" class="flex-1" type="native-asset" droppable="asset">
|
<ui-asset id="asset" class="flex-1" type="native-asset" droppable="asset">
|
||||||
</ui-asset>
|
</ui-asset>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<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">
|
<div style="text-align:right">
|
||||||
<ui-button id="run" class="blue btn btn-primary btn-lg btn-block">執行</ui-button>
|
<ui-button id="run" class="blue btn btn-primary btn-lg btn-block">執行</ui-button>
|
||||||
</div>
|
</div>
|
||||||
|
151
main.js
151
main.js
@ -1,5 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
var fs = require('fs'); // 引用檔案物件
|
||||||
const EditorAPI = require('./src/main/editor-api');
|
const EditorAPI = require('./src/main/editor-api');
|
||||||
|
|
||||||
// ------------decode-uuid
|
// ------------decode-uuid
|
||||||
@ -21,69 +21,98 @@ const Indices = UuidTemplate.map((x, i) => x === '-' ? NaN : i).filter(isFinite)
|
|||||||
|
|
||||||
let HexMap = {}
|
let HexMap = {}
|
||||||
{
|
{
|
||||||
for (let i = 0; i < HexChars.length; i++) {
|
for (let i = 0; i < HexChars.length; i++) {
|
||||||
let char = HexChars[i]
|
let char = HexChars[i]
|
||||||
HexMap[char] = i
|
HexMap[char] = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
load() {
|
load() {
|
||||||
this.init();
|
this.init();
|
||||||
},
|
},
|
||||||
unload() {
|
unload() {
|
||||||
// Editor.log("卸載執行");
|
// Editor.log("卸載執行");
|
||||||
},
|
},
|
||||||
/** 初始化 */
|
/** 初始化 */
|
||||||
init() {
|
init() {
|
||||||
// this.createDirectory();
|
// this.createDirectory();
|
||||||
},
|
},
|
||||||
/** 創建Spine節點 */
|
/** 讀取資源資訊 */
|
||||||
uuidconvert(...args) {
|
uuidconvert(...args) {
|
||||||
let self = this;
|
let self = this;
|
||||||
try {
|
try {
|
||||||
let needconvertuuid = args[0];
|
let needconvertuuid = args[0];
|
||||||
let uuid;
|
let long_uuid;
|
||||||
let long_uuid;
|
let short_uuid;
|
||||||
let short_uuid;
|
let path;
|
||||||
if (needconvertuuid.indexOf("-") === -1) {
|
if (needconvertuuid.indexOf("-") === -1) {
|
||||||
// let convertuuid = this.decodeUuid(needconvertuuid);
|
// let convertuuid = this.decodeUuid(needconvertuuid);
|
||||||
let convertuuid = EditorAPI.decompressUuid(needconvertuuid);
|
let convertuuid = EditorAPI.decompressUuid(needconvertuuid);
|
||||||
uuid = convertuuid;
|
short_uuid = needconvertuuid;
|
||||||
short_uuid = needconvertuuid;
|
long_uuid = convertuuid;
|
||||||
long_uuid = convertuuid;
|
} else {
|
||||||
} else {
|
// let convertuuid = this.compressUuid(needconvertuuid);
|
||||||
// let convertuuid = this.compressUuid(needconvertuuid);
|
let convertuuid = EditorAPI.compressUuid(needconvertuuid);
|
||||||
let convertuuid = EditorAPI.compressUuid(needconvertuuid);
|
short_uuid = convertuuid;
|
||||||
uuid = needconvertuuid;
|
long_uuid = needconvertuuid;
|
||||||
short_uuid = convertuuid;
|
}
|
||||||
long_uuid = needconvertuuid;
|
path = Editor.assetdb.uuidToUrl(long_uuid);
|
||||||
}
|
return [short_uuid, long_uuid, path];
|
||||||
Editor.log('short uuid', short_uuid);
|
} catch (error) {
|
||||||
Editor.log('long uuid', long_uuid);
|
Editor.error(`uuidconvert error: ${error}`);
|
||||||
Editor.Ipc.sendToAll('assets:hint', uuid);
|
}
|
||||||
Editor.log('path: ', Editor.assetdb.uuidToUrl(uuid));
|
},
|
||||||
} catch (error) {
|
/** 替換資源 */
|
||||||
Editor.log(`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: {
|
let sourceInfo = EditorAPI.assetInfoByUuid(source);
|
||||||
/** 打開面板 */
|
let source_path = sourceInfo.path;
|
||||||
"open-panel"() {
|
let sourceData = fs.readFileSync(source_path, "utf8"); // 讀取檔案
|
||||||
Editor.Panel.open("uuidconvert");
|
sourceData = sourceData.replace(new RegExp(short_uuid1, 'g'), short_uuid2);
|
||||||
},
|
fs.writeFileSync(source_path, sourceData);
|
||||||
/** 保存按鈕點擊 */
|
Editor.assetdb.refresh(path3, function (err, results) { });
|
||||||
"run-click"(event, ...args) {
|
} catch (error) {
|
||||||
this.uuidconvert(...args);
|
Editor.error(`replaceResource error: ${error}`);
|
||||||
},
|
}
|
||||||
// /** 面板加載完成 */
|
},
|
||||||
// "panel-load-finish"(evnet, ...args) {
|
|
||||||
// Editor.Scene.callSceneScript("uuidconvert", "get-default-info", { args: args }, function (err, response) {
|
messages: {
|
||||||
// // Editor.log("callSceneScript: " + response);
|
/** 打開面板 */
|
||||||
// Editor.Ipc.sendToPanel("uuidconvert", "setDefault", response);
|
"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");
|
const fs = require("fs");
|
||||||
|
|
||||||
Editor.Panel.extend({
|
Editor.Panel.extend({
|
||||||
style: fs.readFileSync(Editor.url(`packages://${PACKAGE_NAME}/static/style/default/index.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')),
|
.concat(fs.readFileSync(Editor.url(`packages://${PACKAGE_NAME}/static/style/default/bootstrap.min.css`), 'utf-8')),
|
||||||
|
|
||||||
template: fs.readFileSync(
|
template: fs.readFileSync(
|
||||||
Editor.url(`packages://${PACKAGE_NAME}/index.html`), 'utf-8'),
|
Editor.url(`packages://${PACKAGE_NAME}/index.html`), 'utf-8'),
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
run: '#run',
|
run: '#run',
|
||||||
uuid: '#uuid',
|
uuid: '#uuid',
|
||||||
asset: '#asset',
|
asset: '#asset',
|
||||||
},
|
asset2: '#asset2',
|
||||||
|
source: '#source',
|
||||||
|
isReplaceResource: '#isReplaceResource',
|
||||||
|
ReplaceResource: '#ReplaceResource',
|
||||||
|
ReplaceResource1: '#ReplaceResource1',
|
||||||
|
ReplaceResource2: '#ReplaceResource2',
|
||||||
|
},
|
||||||
|
|
||||||
ready() {
|
ready() {
|
||||||
this.$run.addEventListener("confirm", this.methods.run.bind(this));
|
this.$run.addEventListener("confirm", this.methods.run.bind(this));
|
||||||
},
|
this.$isReplaceResource.addEventListener("change", this.methods.setReplaceResource.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
run() {
|
run() {
|
||||||
let uuid = "";
|
let uuid = "";
|
||||||
// Editor.log(`$asset: ${this.$asset.value}`);
|
// Editor.log(`$asset: ${this.$asset.value}`);
|
||||||
if (!this.$uuid.value) {
|
if (!this.$uuid.value) {
|
||||||
if (!this.$asset.value) {
|
if (!this.$asset.value) {
|
||||||
Editor.error("請輸入要轉換的UUID");
|
Editor.error("請輸入要轉換的UUID");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
uuid = this.$asset.value;
|
uuid = this.$asset.value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uuid = this.$uuid.value;
|
uuid = this.$uuid.value;
|
||||||
}
|
}
|
||||||
Editor.Ipc.sendToMain("uuidconvert:run-click", uuid);
|
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";
|
"use strict";
|
||||||
let fs = require("fs");
|
let fs = require("fs");
|
||||||
let path = require("path");
|
let path = require("path");
|
||||||
|
const EditorAPI = require('./src/main/editor-api');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
* 獲取場景節點下的配置信息
|
* 獲取場景節點下的配置信息
|
||||||
* @param event event
|
* @param event event
|
||||||
* @param data 這邊把panel的Node帶進來
|
* @param data 這邊把panel的Node帶進來
|
||||||
*/
|
*/
|
||||||
"getFsPath": function (event, request) {
|
"replaceResource": function (event, request) {
|
||||||
let self = this;
|
let self = this;
|
||||||
var response = null;
|
var response = null;
|
||||||
var args = request.args;
|
var args = request.args;
|
||||||
try {
|
try {
|
||||||
let url = `db://assets/${args[0]._value}`;
|
let uuid1 = args[0];
|
||||||
url = url.replace(/\\/g, "/");
|
let uuid2 = args[1];
|
||||||
// let url = `db://assets/=SceneLobby`;
|
let uuid3 = args[2];
|
||||||
// Editor.log(`url: ${url}`);
|
let path = Editor.assetdb.uuidToUrl(uuid3);
|
||||||
let fsPath = Editor.remote.assetdb.urlToFspath(url);
|
// let assetInfo = EditorAPI.assetInfoByUuid(uuid1);
|
||||||
// Editor.log(`fsPath: ${fsPath}`);
|
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 = {
|
// let source = cc.find("SlotPaytable_66");
|
||||||
url: url,
|
// // 修改运行中的节点属性:
|
||||||
fsPath, fsPath
|
// Editor.Ipc.sendToPanel('scene', 'scene:set-property', {
|
||||||
}
|
// id: uuid1,
|
||||||
response = JSON.stringify(res);
|
// path: "name",//要修改的属性
|
||||||
} catch (error) {
|
// type: "String",
|
||||||
Editor.log(`getFsPath error: ${error}`);
|
// value: "8787",
|
||||||
}
|
// isSubProp: false,
|
||||||
if (event.reply) {
|
// });
|
||||||
event.reply(null, response);
|
// 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);
|
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 获取子资源信息
|
* 通过 uuid 获取子资源信息
|
||||||
* @param {string} uuid
|
* @param {string} uuid
|
||||||
|
Loading…
Reference in New Issue
Block a user