84 lines
2.9 KiB
JavaScript
84 lines
2.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const csharp_1 = require("csharp");
|
|
const TweenCoustomInspector_1 = require("./TweenCoustomInspector");
|
|
const TweenSettings = require('./TweenSettings').default;
|
|
const App = csharp_1.FairyEditor.App;
|
|
// 首先读取本地文件配置获取是否本地配置还是远程配置
|
|
// local
|
|
let filePath = `${csharp_1.FairyEditor.App.project.basePath}/plugins/whoot-tween/config.json`;
|
|
let config;
|
|
try {
|
|
let sw = new csharp_1.System.IO.StreamReader(filePath);
|
|
let data = sw.ReadToEnd();
|
|
sw.Close();
|
|
console.log("获取到本地配置:", data);
|
|
config = JSON.parse(data);
|
|
}
|
|
catch (e) {
|
|
console.warn(e);
|
|
}
|
|
if (config.remote) {
|
|
// remote
|
|
let url = config.remote;
|
|
let request = csharp_1.System['Net']['WebRequest'].Create(url);
|
|
request.Method = "GET";
|
|
request.ContentType = "text/html;charset=UTF-8";
|
|
let response = request.GetResponse();
|
|
let responseStream = response.GetResponseStream();
|
|
let streamReader = new csharp_1.System.IO.StreamReader(responseStream);
|
|
let res = streamReader.ReadToEnd();
|
|
try {
|
|
console.log("获取到远程配置:", config);
|
|
config = JSON.parse(res);
|
|
}
|
|
catch (e) {
|
|
console.warn(e);
|
|
}
|
|
}
|
|
App.pluginManager.LoadUIPackage(App.pluginManager.basePath + "/" + eval("__dirname") + '/TweenAttributer');
|
|
for (let i = 0; i < config.inspectors.length; i++) {
|
|
let inspector = config.inspectors[i];
|
|
let { parent, title } = inspector;
|
|
App.inspectorView.AddInspector(() => new TweenCoustomInspector_1.CustomAttributer(inspector), title, title);
|
|
App.docFactory.ConnectInspector(title, "mixed", parent, false);
|
|
}
|
|
// 当层级结构变化(增删控件)时,自动清理 JSON 中已删除组件的记录
|
|
const onHierarchyChanged = (_ctx) => {
|
|
try {
|
|
const activeDoc = App.activeDoc;
|
|
if (!activeDoc)
|
|
return;
|
|
const packageName = activeDoc.packageItem.owner.name;
|
|
const docUrl = activeDoc.docURL;
|
|
const ids = [];
|
|
const visited = {};
|
|
const collect = (node) => {
|
|
if (!node)
|
|
return;
|
|
const nid = node.id;
|
|
if (nid && !visited[nid]) {
|
|
visited[nid] = true;
|
|
ids.push(nid);
|
|
}
|
|
if (node instanceof csharp_1.FairyEditor.FComponent) {
|
|
const cnt = node.numChildren;
|
|
for (let i = 0; i < cnt; i++) {
|
|
const child = node.GetChildAt(i);
|
|
collect(child);
|
|
}
|
|
}
|
|
};
|
|
const docAny = activeDoc;
|
|
if (docAny && docAny.content)
|
|
collect(docAny.content);
|
|
TweenSettings.cleanupDoc(packageName, docUrl, ids);
|
|
}
|
|
catch (err) {
|
|
console.error('HierarchyChanged 自动清理失败', err);
|
|
}
|
|
};
|
|
// 订阅层级变化事件
|
|
// @ts-ignore
|
|
App.On(csharp_1.FairyEditor.EditorEvents.HierarchyChanged, onHierarchyChanged);
|