first commit
This commit is contained in:
2
FGUIProject/plugins/nbc-puerts-plugins/.vscode/settings.json
vendored
Normal file
2
FGUIProject/plugins/nbc-puerts-plugins/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
28
FGUIProject/plugins/nbc-puerts-plugins/CodeWriter.d.ts
vendored
Normal file
28
FGUIProject/plugins/nbc-puerts-plugins/CodeWriter.d.ts
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
interface ICodeWriterConfig {
|
||||
blockStart?: string;
|
||||
blockEnd?: string;
|
||||
blockFromNewLine?: boolean;
|
||||
usingTabs?: boolean;
|
||||
endOfLine?: string;
|
||||
fileMark?: string;
|
||||
}
|
||||
export default class CodeWriter {
|
||||
private blockStart;
|
||||
private blockEnd;
|
||||
private blockFromNewLine;
|
||||
private indentStr;
|
||||
private endOfLine;
|
||||
private lines;
|
||||
private indent;
|
||||
private fileMark;
|
||||
constructor(config?: ICodeWriterConfig);
|
||||
writeMark(): void;
|
||||
writeln(fmt?: string, ...args: any[]): CodeWriter;
|
||||
startBlock(): CodeWriter;
|
||||
endBlock(): CodeWriter;
|
||||
incIndent(): CodeWriter;
|
||||
decIndent(): CodeWriter;
|
||||
reset(): void;
|
||||
toString(): string;
|
||||
save(filePath: string): void;
|
||||
}
|
||||
114
FGUIProject/plugins/nbc-puerts-plugins/GenCodeCustomInspector.js
Normal file
114
FGUIProject/plugins/nbc-puerts-plugins/GenCodeCustomInspector.js
Normal file
@@ -0,0 +1,114 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runGenCodeCustom = runGenCodeCustom;
|
||||
var FairyGUI = CS.FairyGUI;
|
||||
var FairyEditor = CS.FairyEditor;
|
||||
const GenCodeSettings_1 = require("./GenCodeSettings");
|
||||
const App = FairyEditor.App;
|
||||
App.pluginManager.LoadUIPackage(App.pluginManager.basePath + "/" + eval("__dirname") + '/WhootCustomInspector');
|
||||
class GenCodeCustomInspector extends FairyEditor.View.PluginInspector {
|
||||
combo;
|
||||
setScriptName;
|
||||
scriptName;
|
||||
scriptAnnotation;
|
||||
constructor() {
|
||||
super();
|
||||
this.panel = FairyGUI.UIPackage.CreateObject("WhootCustomInspector", "Component1").asCom;
|
||||
this.combo = this.panel.GetChild("genType").asComboBox;
|
||||
this.setScriptName = this.panel.GetChild("SetScriptName").asButton;
|
||||
this.scriptName = this.panel.GetChild("scriptName");
|
||||
this.scriptAnnotation = this.panel.GetChild("scriptAnnotation");
|
||||
// this.combo = this.panel.GetChild("SetScriptType").asComboBox;
|
||||
let self = this;
|
||||
this.combo.onChanged.Add(() => {
|
||||
self.updateData();
|
||||
});
|
||||
this.setScriptName.onChanged.Add(() => {
|
||||
this.updateData();
|
||||
});
|
||||
this.scriptName.onFocusOut.Add(() => {
|
||||
this.updateData();
|
||||
});
|
||||
this.scriptAnnotation.onFocusOut.Add(() => {
|
||||
this.updateData();
|
||||
});
|
||||
this.updateAction = () => { return self.updateUI(); };
|
||||
}
|
||||
updateData() {
|
||||
let activeDoc = App.activeDoc;
|
||||
let obj = activeDoc.inspectingTarget;
|
||||
//console.log("update==2", this.scriptName.title)
|
||||
GenCodeSettings_1.default.changeComponentSetting(obj.resourceURL, this.combo.value, activeDoc.packageItem.name, this.setScriptName.selected, this.scriptName.title, this.scriptAnnotation.title);
|
||||
}
|
||||
updateUI() {
|
||||
let sels = App.activeDoc.inspectingTargets;
|
||||
let obj = sels.get_Item(0);
|
||||
var data = GenCodeSettings_1.default.getComponentSetting(obj.resourceURL);
|
||||
if (data != null) {
|
||||
this.combo.value = data.scriptType;
|
||||
this.setScriptName.selected = data.isCustomName;
|
||||
this.scriptName.title = data.customName;
|
||||
this.scriptAnnotation.title = data.annotation;
|
||||
}
|
||||
else {
|
||||
this.combo.value = null;
|
||||
this.setScriptName.selected = false;
|
||||
this.scriptName.title = "";
|
||||
this.scriptAnnotation.title = "";
|
||||
}
|
||||
return true; //if everything is ok, return false to hide the inspector
|
||||
}
|
||||
}
|
||||
// class MembersGenCodeCustomInspector extends FairyEditor.View.PluginInspector {
|
||||
// private setScriptType: FairyGUI.GButton;
|
||||
// private scriptAnnotation: FairyEditor.Component.TextInput;
|
||||
// public constructor() {
|
||||
// super();
|
||||
// this.panel = FairyGUI.UIPackage.CreateObject("WhootCustomInspector", "Component2").asCom;
|
||||
// this.setScriptType = this.panel.GetChild("SetScriptType").asButton;
|
||||
// this.scriptAnnotation = this.panel.GetChild("scriptAnnotation") as FairyEditor.Component.TextInput
|
||||
// this.setScriptType.onChanged.Add(() => {
|
||||
// this.updateData()
|
||||
// });
|
||||
// this.scriptAnnotation.onFocusOut.Add(() => {
|
||||
// this.updateData()
|
||||
// })
|
||||
// this.updateAction = () => { return this.updateUI(); };
|
||||
// }
|
||||
// private updateData() {
|
||||
// let activeDoc = App.activeDoc
|
||||
// let obj = activeDoc.inspectingTarget
|
||||
// genSetting.changeMemberSetting(activeDoc.packageItem.GetURL(), obj.id, this.setScriptType.selected, obj.name, this.scriptAnnotation.title)
|
||||
// }
|
||||
// private updateUI(): boolean {
|
||||
// // let sels = App.activeDoc.inspectingTargets
|
||||
// // let obj = sels.get_Item(0);
|
||||
// let activeDoc = App.activeDoc
|
||||
// let obj = activeDoc.inspectingTarget
|
||||
// let data = genSetting.getMemberSetting(activeDoc.packageItem.GetURL(), obj.id)
|
||||
// if (data != null) {
|
||||
// this.setScriptType.selected = data.useCustomScript
|
||||
// this.scriptAnnotation.title = data.annotation
|
||||
// genSetting.changeMemberSetting(activeDoc.packageItem.GetURL(), obj.id, this.setScriptType.selected, obj.name, this.scriptAnnotation.title)
|
||||
// } else {
|
||||
// this.setScriptType.selected = false
|
||||
// this.scriptAnnotation.title = ""
|
||||
// }
|
||||
// //this.setScriptType.selected = obj.customData == "1"
|
||||
// return true; //if everything is ok, return false to hide the inspector
|
||||
// }
|
||||
// }
|
||||
function runGenCodeCustom() {
|
||||
// //Register a inspector
|
||||
// App.inspectorView.AddInspector(() => new MembersGenCodeCustomInspector(), "MembersGenCodeCustomInspectorJS", "成员脚本生成设置");
|
||||
// //Condition to show it
|
||||
// App.docFactory.ConnectInspector("MembersGenCodeCustomInspectorJS", "component", false, false);
|
||||
//Register a inspector
|
||||
App.inspectorView.AddInspector(() => new GenCodeCustomInspector(), "GenCodeCustomInspectorJS", "组件脚本生成设置");
|
||||
//Condition to show it
|
||||
App.docFactory.ConnectInspector("GenCodeCustomInspectorJS", "component", true, false);
|
||||
// "none", "graph", "image", "text", "richtext", "inputtext",
|
||||
// "movieclip", "swf", "loader", "group", "list", "loader3D",
|
||||
// "component", "Button", "Label", "Slider", "ProgressBar", "ScrollBar", "ComboBox", "mixed"
|
||||
//FairyEditor.FPackageItem(context.data)
|
||||
}
|
||||
138
FGUIProject/plugins/nbc-puerts-plugins/GenCodeCustomInspector.ts
Normal file
138
FGUIProject/plugins/nbc-puerts-plugins/GenCodeCustomInspector.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
import FairyGUI = CS.FairyGUI;
|
||||
import FairyEditor = CS.FairyEditor;
|
||||
import System = CS.System;
|
||||
import genSetting from './GenCodeSettings'
|
||||
|
||||
const App = FairyEditor.App;
|
||||
App.pluginManager.LoadUIPackage(App.pluginManager.basePath + "/" + eval("__dirname") + '/WhootCustomInspector')
|
||||
|
||||
class GenCodeCustomInspector extends FairyEditor.View.PluginInspector {
|
||||
private combo: FairyGUI.GComboBox;
|
||||
private setScriptName: FairyGUI.GButton
|
||||
private scriptName: FairyEditor.Component.TextInput;
|
||||
private scriptAnnotation: FairyEditor.Component.TextInput;
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
|
||||
this.panel = FairyGUI.UIPackage.CreateObject("WhootCustomInspector", "Component1").asCom;
|
||||
this.combo = this.panel.GetChild("genType").asComboBox;
|
||||
this.setScriptName = this.panel.GetChild("SetScriptName").asButton
|
||||
this.scriptName = this.panel.GetChild("scriptName") as FairyEditor.Component.TextInput
|
||||
this.scriptAnnotation = this.panel.GetChild("scriptAnnotation") as FairyEditor.Component.TextInput
|
||||
// this.combo = this.panel.GetChild("SetScriptType").asComboBox;
|
||||
let self = this
|
||||
this.combo.onChanged.Add(() => {
|
||||
self.updateData()
|
||||
});
|
||||
this.setScriptName.onChanged.Add(() => {
|
||||
this.updateData()
|
||||
});
|
||||
|
||||
this.scriptName.onFocusOut.Add(() => {
|
||||
this.updateData()
|
||||
})
|
||||
|
||||
this.scriptAnnotation.onFocusOut.Add(() => {
|
||||
this.updateData()
|
||||
})
|
||||
|
||||
this.updateAction = () => { return self.updateUI(); };
|
||||
}
|
||||
|
||||
private updateData() {
|
||||
let activeDoc = App.activeDoc
|
||||
let obj = activeDoc.inspectingTarget as FairyEditor.FComponent
|
||||
//console.log("update==2", this.scriptName.title)
|
||||
genSetting.changeComponentSetting(obj.resourceURL, this.combo.value, activeDoc.packageItem.name, this.setScriptName.selected, this.scriptName.title, this.scriptAnnotation.title)
|
||||
}
|
||||
|
||||
private updateUI(): boolean {
|
||||
let sels = App.activeDoc.inspectingTargets
|
||||
let obj = sels.get_Item(0);
|
||||
var data = genSetting.getComponentSetting(obj.resourceURL)
|
||||
if (data != null) {
|
||||
this.combo.value = data.scriptType
|
||||
this.setScriptName.selected = data.isCustomName
|
||||
this.scriptName.title = data.customName
|
||||
this.scriptAnnotation.title = data.annotation
|
||||
} else {
|
||||
this.combo.value = null;
|
||||
this.setScriptName.selected = false
|
||||
this.scriptName.title = ""
|
||||
this.scriptAnnotation.title = ""
|
||||
}
|
||||
return true; //if everything is ok, return false to hide the inspector
|
||||
}
|
||||
}
|
||||
|
||||
// class MembersGenCodeCustomInspector extends FairyEditor.View.PluginInspector {
|
||||
// private setScriptType: FairyGUI.GButton;
|
||||
// private scriptAnnotation: FairyEditor.Component.TextInput;
|
||||
|
||||
// public constructor() {
|
||||
// super();
|
||||
|
||||
// this.panel = FairyGUI.UIPackage.CreateObject("WhootCustomInspector", "Component2").asCom;
|
||||
// this.setScriptType = this.panel.GetChild("SetScriptType").asButton;
|
||||
// this.scriptAnnotation = this.panel.GetChild("scriptAnnotation") as FairyEditor.Component.TextInput
|
||||
|
||||
// this.setScriptType.onChanged.Add(() => {
|
||||
// this.updateData()
|
||||
// });
|
||||
|
||||
// this.scriptAnnotation.onFocusOut.Add(() => {
|
||||
// this.updateData()
|
||||
// })
|
||||
|
||||
// this.updateAction = () => { return this.updateUI(); };
|
||||
// }
|
||||
|
||||
// private updateData() {
|
||||
// let activeDoc = App.activeDoc
|
||||
// let obj = activeDoc.inspectingTarget
|
||||
// genSetting.changeMemberSetting(activeDoc.packageItem.GetURL(), obj.id, this.setScriptType.selected, obj.name, this.scriptAnnotation.title)
|
||||
// }
|
||||
|
||||
// private updateUI(): boolean {
|
||||
// // let sels = App.activeDoc.inspectingTargets
|
||||
// // let obj = sels.get_Item(0);
|
||||
// let activeDoc = App.activeDoc
|
||||
// let obj = activeDoc.inspectingTarget
|
||||
// let data = genSetting.getMemberSetting(activeDoc.packageItem.GetURL(), obj.id)
|
||||
// if (data != null) {
|
||||
// this.setScriptType.selected = data.useCustomScript
|
||||
// this.scriptAnnotation.title = data.annotation
|
||||
// genSetting.changeMemberSetting(activeDoc.packageItem.GetURL(), obj.id, this.setScriptType.selected, obj.name, this.scriptAnnotation.title)
|
||||
// } else {
|
||||
// this.setScriptType.selected = false
|
||||
// this.scriptAnnotation.title = ""
|
||||
// }
|
||||
|
||||
// //this.setScriptType.selected = obj.customData == "1"
|
||||
|
||||
// return true; //if everything is ok, return false to hide the inspector
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
function runGenCodeCustom() {
|
||||
// //Register a inspector
|
||||
// App.inspectorView.AddInspector(() => new MembersGenCodeCustomInspector(), "MembersGenCodeCustomInspectorJS", "成员脚本生成设置");
|
||||
// //Condition to show it
|
||||
// App.docFactory.ConnectInspector("MembersGenCodeCustomInspectorJS", "component", false, false);
|
||||
|
||||
//Register a inspector
|
||||
App.inspectorView.AddInspector(() => new GenCodeCustomInspector(), "GenCodeCustomInspectorJS", "组件脚本生成设置");
|
||||
//Condition to show it
|
||||
App.docFactory.ConnectInspector("GenCodeCustomInspectorJS", "component", true, false);
|
||||
|
||||
// "none", "graph", "image", "text", "richtext", "inputtext",
|
||||
// "movieclip", "swf", "loader", "group", "list", "loader3D",
|
||||
// "component", "Button", "Label", "Slider", "ProgressBar", "ScrollBar", "ComboBox", "mixed"
|
||||
|
||||
//FairyEditor.FPackageItem(context.data)
|
||||
}
|
||||
|
||||
|
||||
export { runGenCodeCustom };
|
||||
210
FGUIProject/plugins/nbc-puerts-plugins/GenCodeSettings.js
Normal file
210
FGUIProject/plugins/nbc-puerts-plugins/GenCodeSettings.js
Normal file
@@ -0,0 +1,210 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GenCodeSettings = exports.GenCodeSettingData = exports.ComponentData = exports.MemberData = void 0;
|
||||
var FairyEditor = CS.FairyEditor;
|
||||
var System = CS.System;
|
||||
const App = FairyEditor.App;
|
||||
const File = System.IO.File;
|
||||
const Directory = System.IO.Directory;
|
||||
class MemberData {
|
||||
id;
|
||||
name;
|
||||
/** 使用自定义脚本 **/
|
||||
useCustomScript;
|
||||
annotation = "";
|
||||
}
|
||||
exports.MemberData = MemberData;
|
||||
class ComponentData {
|
||||
constructor() {
|
||||
this.member = {};
|
||||
}
|
||||
url;
|
||||
name;
|
||||
scriptType = "";
|
||||
isCustomName = false;
|
||||
customName = "";
|
||||
annotation = "";
|
||||
member = {};
|
||||
}
|
||||
exports.ComponentData = ComponentData;
|
||||
class GenCodeSettingData {
|
||||
constructor() {
|
||||
this.components = {};
|
||||
}
|
||||
components = {};
|
||||
}
|
||||
exports.GenCodeSettingData = GenCodeSettingData;
|
||||
class GenCodeSettings {
|
||||
static instance;
|
||||
static getInstance() {
|
||||
if (!this.instance) {
|
||||
this.instance = new GenCodeSettings();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
settingPath = "";
|
||||
componentsSettingBasePath = "";
|
||||
settingData;
|
||||
constructor() {
|
||||
this.settingPath = App.project.settingsPath + "/WhootGencodeSetting.json";
|
||||
this.componentsSettingBasePath = App.project.settingsPath + "/whoot";
|
||||
if (!System.IO.Directory.Exists(this.componentsSettingBasePath)) {
|
||||
console.log("whoot配置文件目录不存在,创建");
|
||||
System.IO.Directory.CreateDirectory(this.componentsSettingBasePath);
|
||||
}
|
||||
this.readAll();
|
||||
}
|
||||
/**
|
||||
* 清理已经失效的url
|
||||
*/
|
||||
clearFailureConfig() {
|
||||
console.log("清理全部已经失效的资源");
|
||||
}
|
||||
test() {
|
||||
console.log("hahah");
|
||||
}
|
||||
getComponentSetting(url) {
|
||||
if (this.settingData.components != null && this.settingData.components.hasOwnProperty(url)) {
|
||||
return this.settingData.components[url];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
changeComponentSetting(url, type, name, isCuston = false, customName = "", annotation = "") {
|
||||
let com = null;
|
||||
if (!this.settingData.components.hasOwnProperty(url)) {
|
||||
com = new ComponentData();
|
||||
//新建
|
||||
this.settingData.components[url] = com;
|
||||
}
|
||||
else {
|
||||
com = this.settingData.components[url];
|
||||
}
|
||||
com.url = url;
|
||||
com.scriptType = type;
|
||||
com.isCustomName = isCuston;
|
||||
com.customName = customName;
|
||||
com.name = name;
|
||||
com.annotation = annotation;
|
||||
this.save(url);
|
||||
}
|
||||
packageItemChange(context) {
|
||||
var item = context.data;
|
||||
if (item != null && item.isDisposed) {
|
||||
console.log("包的文件改变了,有文件被删除", this.settingData);
|
||||
if (this.settingData != null && this.settingData.components != null) {
|
||||
let url = item.GetURL();
|
||||
console.log("删除了的url=" + url);
|
||||
this.delete(url);
|
||||
delete this.settingData.components[url];
|
||||
}
|
||||
}
|
||||
else if (item != null) {
|
||||
console.log("包的文件改变了。文件增加");
|
||||
}
|
||||
}
|
||||
// public getMemberSettingByName(baseUrl: string, name: string) {
|
||||
// var baseData: ComponentData = this.getComponentSetting(baseUrl);
|
||||
// if (baseData != null) {
|
||||
// if (baseData.member != null) {
|
||||
// for (let key in baseData.member) {
|
||||
// let item: MemberData = baseData.member[key]
|
||||
// if (item.name == name) {
|
||||
// return baseData.member[item.id]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
// public getMemberSetting(baseUrl: string, id: string) {
|
||||
// var baseData: ComponentData = this.getComponentSetting(baseUrl);
|
||||
// if (baseData != null) {
|
||||
// if (baseData.member != null && baseData.member.hasOwnProperty(id)) {
|
||||
// return baseData.member[id]
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
// public changeMemberSetting(baseUrl: string, id: string, state: boolean, name: string = "", annotation: string = "") {
|
||||
// if (this.settingData.components == null || !this.settingData.components.hasOwnProperty(baseUrl)) {
|
||||
// console.error("父节点未设置参数,设置退出 baseUrl=" + baseUrl)
|
||||
// return
|
||||
// }
|
||||
// let isChange = false
|
||||
// let com: ComponentData = this.settingData.components[baseUrl]
|
||||
// let mem: MemberData = null
|
||||
// if (!com.member.hasOwnProperty(id)) {
|
||||
// mem = new MemberData();
|
||||
// //新建
|
||||
// com.member[id] = mem;
|
||||
// isChange = true
|
||||
// } else {
|
||||
// mem = com.member[id]
|
||||
// if (mem.name != name || mem.useCustomScript != state || mem.annotation != annotation) {
|
||||
// isChange = true
|
||||
// }
|
||||
// }
|
||||
// if (isChange) {
|
||||
// mem.id = id
|
||||
// mem.name = name
|
||||
// mem.useCustomScript = state
|
||||
// mem.annotation = annotation
|
||||
// this.save(baseUrl)
|
||||
// }
|
||||
// }
|
||||
//获取所有的文件的路径
|
||||
getAllDirector(path, list) {
|
||||
let files = Directory.GetFiles(path, "*.json");
|
||||
console.log("开始读取所有配置=", path);
|
||||
for (let f = 0; f < files.Length; f++) {
|
||||
list.push(files.get_Item(f));
|
||||
}
|
||||
}
|
||||
readAll() {
|
||||
try {
|
||||
let list = [];
|
||||
this.getAllDirector(this.componentsSettingBasePath, list);
|
||||
console.log("初始化所有配置,count=", list.length);
|
||||
this.settingData = new GenCodeSettingData();
|
||||
this.settingData.components = {};
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
let p = list[index];
|
||||
if (p === undefined)
|
||||
continue;
|
||||
let jsonStr = File.ReadAllText(p);
|
||||
let data = JSON.parse(jsonStr);
|
||||
let url = data.url;
|
||||
this.settingData.components[url] = data;
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.error("读取配置文件失败=", err);
|
||||
}
|
||||
}
|
||||
delete(url) {
|
||||
let path = this.componentsSettingBasePath + "/" + this.urlDecode(url) + ".json";
|
||||
File.Delete(url);
|
||||
}
|
||||
save(url) {
|
||||
try {
|
||||
if (this.settingData.components != null && this.settingData.components.hasOwnProperty(url)) {
|
||||
let path = this.componentsSettingBasePath + "/" + this.urlDecode(url) + ".json";
|
||||
let data = this.settingData.components[url];
|
||||
let jsonStr = JSON.stringify(data);
|
||||
File.WriteAllText(path, jsonStr);
|
||||
console.log("配置文件更新:" + url);
|
||||
}
|
||||
else {
|
||||
console.error("要保存的配置不存在:" + url);
|
||||
}
|
||||
}
|
||||
catch {
|
||||
console.error("保存配置文件失败");
|
||||
}
|
||||
}
|
||||
urlDecode(url) {
|
||||
return url.replace("ui://", "");
|
||||
}
|
||||
}
|
||||
exports.GenCodeSettings = GenCodeSettings;
|
||||
exports.default = GenCodeSettings.getInstance();
|
||||
224
FGUIProject/plugins/nbc-puerts-plugins/GenCodeSettings.ts
Normal file
224
FGUIProject/plugins/nbc-puerts-plugins/GenCodeSettings.ts
Normal file
@@ -0,0 +1,224 @@
|
||||
import FairyGUI = CS.FairyGUI;
|
||||
import FairyEditor = CS.FairyEditor;
|
||||
import System = CS.System;
|
||||
const App = FairyEditor.App;
|
||||
const File = System.IO.File;
|
||||
const Directory = System.IO.Directory;
|
||||
|
||||
export class MemberData {
|
||||
public id: string
|
||||
public name: string
|
||||
/** 使用自定义脚本 **/
|
||||
public useCustomScript: boolean
|
||||
public annotation: string = "";
|
||||
}
|
||||
|
||||
export class ComponentData {
|
||||
constructor() {
|
||||
this.member = {}
|
||||
}
|
||||
public url: string;
|
||||
public name: string;
|
||||
public scriptType: string = "";
|
||||
public isCustomName: boolean = false
|
||||
public customName: string = "";
|
||||
public annotation: string = "";
|
||||
public member = {}
|
||||
}
|
||||
|
||||
export class GenCodeSettingData {
|
||||
constructor() {
|
||||
this.components = {}
|
||||
}
|
||||
public components = {}
|
||||
}
|
||||
|
||||
|
||||
export class GenCodeSettings {
|
||||
private static instance: GenCodeSettings;
|
||||
static getInstance() {
|
||||
if (!this.instance) {
|
||||
this.instance = new GenCodeSettings();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
public settingPath: string = "";
|
||||
public componentsSettingBasePath: string = "";
|
||||
private settingData: GenCodeSettingData;
|
||||
constructor() {
|
||||
this.settingPath = App.project.settingsPath + "/WhootGencodeSetting.json"
|
||||
this.componentsSettingBasePath = App.project.settingsPath + "/whoot"
|
||||
if (!System.IO.Directory.Exists(this.componentsSettingBasePath)) {
|
||||
console.log("whoot配置文件目录不存在,创建")
|
||||
System.IO.Directory.CreateDirectory(this.componentsSettingBasePath)
|
||||
}
|
||||
this.readAll()
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理已经失效的url
|
||||
*/
|
||||
public clearFailureConfig() {
|
||||
console.log("清理全部已经失效的资源")
|
||||
}
|
||||
|
||||
public test() {
|
||||
console.log("hahah")
|
||||
}
|
||||
|
||||
|
||||
public getComponentSetting(url: string) {
|
||||
if (this.settingData.components != null && this.settingData.components.hasOwnProperty(url)) {
|
||||
return this.settingData.components[url]
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
public changeComponentSetting(url: string, type: string, name: string, isCuston: boolean = false, customName: string = "", annotation: string = "") {
|
||||
let com: ComponentData = null
|
||||
|
||||
if (!this.settingData.components.hasOwnProperty(url)) {
|
||||
com = new ComponentData()
|
||||
//新建
|
||||
this.settingData.components[url] = com;
|
||||
} else {
|
||||
com = this.settingData.components[url]
|
||||
}
|
||||
com.url = url
|
||||
com.scriptType = type
|
||||
com.isCustomName = isCuston
|
||||
com.customName = customName
|
||||
com.name = name
|
||||
com.annotation = annotation
|
||||
|
||||
this.save(url)
|
||||
}
|
||||
|
||||
public packageItemChange(context: FairyGUI.EventContext) {
|
||||
var item = context.data as FairyEditor.FPackageItem
|
||||
if (item != null && item.isDisposed) {
|
||||
console.log("包的文件改变了,有文件被删除", this.settingData)
|
||||
if (this.settingData != null && this.settingData.components != null) {
|
||||
let url = item.GetURL()
|
||||
console.log("删除了的url=" + url)
|
||||
this.delete(url)
|
||||
delete this.settingData.components[url]
|
||||
|
||||
}
|
||||
} else if (item != null) {
|
||||
console.log("包的文件改变了。文件增加")
|
||||
}
|
||||
}
|
||||
|
||||
// public getMemberSettingByName(baseUrl: string, name: string) {
|
||||
// var baseData: ComponentData = this.getComponentSetting(baseUrl);
|
||||
// if (baseData != null) {
|
||||
// if (baseData.member != null) {
|
||||
// for (let key in baseData.member) {
|
||||
// let item: MemberData = baseData.member[key]
|
||||
// if (item.name == name) {
|
||||
// return baseData.member[item.id]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// public getMemberSetting(baseUrl: string, id: string) {
|
||||
// var baseData: ComponentData = this.getComponentSetting(baseUrl);
|
||||
// if (baseData != null) {
|
||||
// if (baseData.member != null && baseData.member.hasOwnProperty(id)) {
|
||||
// return baseData.member[id]
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
// public changeMemberSetting(baseUrl: string, id: string, state: boolean, name: string = "", annotation: string = "") {
|
||||
// if (this.settingData.components == null || !this.settingData.components.hasOwnProperty(baseUrl)) {
|
||||
// console.error("父节点未设置参数,设置退出 baseUrl=" + baseUrl)
|
||||
// return
|
||||
// }
|
||||
// let isChange = false
|
||||
// let com: ComponentData = this.settingData.components[baseUrl]
|
||||
// let mem: MemberData = null
|
||||
// if (!com.member.hasOwnProperty(id)) {
|
||||
// mem = new MemberData();
|
||||
// //新建
|
||||
// com.member[id] = mem;
|
||||
// isChange = true
|
||||
// } else {
|
||||
// mem = com.member[id]
|
||||
// if (mem.name != name || mem.useCustomScript != state || mem.annotation != annotation) {
|
||||
// isChange = true
|
||||
// }
|
||||
// }
|
||||
// if (isChange) {
|
||||
// mem.id = id
|
||||
// mem.name = name
|
||||
// mem.useCustomScript = state
|
||||
// mem.annotation = annotation
|
||||
// this.save(baseUrl)
|
||||
// }
|
||||
// }
|
||||
|
||||
//获取所有的文件的路径
|
||||
public getAllDirector(path: string, list: Array<string>) {
|
||||
let files = Directory.GetFiles(path, "*.json")
|
||||
console.log("开始读取所有配置=", path)
|
||||
for (let f = 0; f < files.Length; f++) {
|
||||
list.push(files.get_Item(f))
|
||||
}
|
||||
}
|
||||
public readAll() {
|
||||
try {
|
||||
let list: Array<string> = []
|
||||
this.getAllDirector(this.componentsSettingBasePath, list)
|
||||
console.log("初始化所有配置,count=", list.length)
|
||||
this.settingData = new GenCodeSettingData();
|
||||
this.settingData.components = {}
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
let p = list[index];
|
||||
if (p === undefined) continue;
|
||||
let jsonStr = File.ReadAllText(p);
|
||||
let data: ComponentData = JSON.parse(jsonStr);
|
||||
let url = data.url
|
||||
this.settingData.components[url] = data
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("读取配置文件失败=", err)
|
||||
}
|
||||
}
|
||||
|
||||
public delete(url: string) {
|
||||
let path = this.componentsSettingBasePath + "/" + this.urlDecode(url) + ".json";
|
||||
File.Delete(url)
|
||||
}
|
||||
|
||||
public save(url: string) {
|
||||
try {
|
||||
if (this.settingData.components != null && this.settingData.components.hasOwnProperty(url)) {
|
||||
let path = this.componentsSettingBasePath + "/" + this.urlDecode(url) + ".json";
|
||||
let data = this.settingData.components[url]
|
||||
let jsonStr = JSON.stringify(data);
|
||||
File.WriteAllText(path, jsonStr)
|
||||
console.log("配置文件更新:" + url)
|
||||
} else {
|
||||
console.error("要保存的配置不存在:" + url)
|
||||
}
|
||||
} catch {
|
||||
console.error("保存配置文件失败")
|
||||
}
|
||||
}
|
||||
|
||||
public urlDecode(url: string) {
|
||||
return url.replace("ui://", "")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default GenCodeSettings.getInstance();
|
||||
|
||||
568
FGUIProject/plugins/nbc-puerts-plugins/GenCode_CSharp.js
Normal file
568
FGUIProject/plugins/nbc-puerts-plugins/GenCode_CSharp.js
Normal file
@@ -0,0 +1,568 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.genCSCode = genCSCode;
|
||||
var FairyEditor = CS.FairyEditor;
|
||||
var System = CS.System;
|
||||
const CodeWriter_1 = require("./CodeWriter");
|
||||
const GenCodeSettings_1 = require("./GenCodeSettings");
|
||||
const LanguageSettings_1 = require("./LanguageSettings");
|
||||
const tweenSetting = (function () {
|
||||
try {
|
||||
return require('../whoot-tween/TweenSettings').default || require('../whoot-tween/TweenSettings');
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
const File = System.IO.File;
|
||||
const Directory = System.IO.Directory;
|
||||
const App = FairyEditor.App;
|
||||
var allSuperClassNameByUrl = {};
|
||||
var allCustomNameByUrl = {};
|
||||
var namespaceName = "";
|
||||
var setNamespaceName = false;
|
||||
var exportCodePath = "";
|
||||
var existScriptPaths = {};
|
||||
var packageName = '';
|
||||
//获取所有的文件的路径
|
||||
function getAllDirector(path, list) {
|
||||
let dirs = Directory.GetDirectories(path);
|
||||
for (let index = 0; index < dirs.Length; index++) {
|
||||
let dir = dirs.get_Item(index);
|
||||
getAllFile(dir, list);
|
||||
let dirs2 = Directory.GetDirectories(dir);
|
||||
if (dirs2.Length > 0) {
|
||||
getAllDirector(dir, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
function getAllFile(dir, list) {
|
||||
let files = Directory.GetFiles(dir, "*.cs");
|
||||
for (let f = 0; f < files.Length; f++) {
|
||||
list.push(files.get_Item(f));
|
||||
}
|
||||
}
|
||||
class WhootCodeWriterConfig {
|
||||
blockStart;
|
||||
blockEnd;
|
||||
blockFromNewLine;
|
||||
usingTabs;
|
||||
endOfLine;
|
||||
fileMark;
|
||||
}
|
||||
function genCSCode(handler) {
|
||||
console.log("gencode==========--------------========");
|
||||
let settings = handler.project.GetSettings("Publish").codeGeneration;
|
||||
let codePkgName = handler.ToFilename(handler.pkg.name);
|
||||
exportCodePath = handler.exportCodePath; // + '/' + codePkgName;
|
||||
console.log("exportCodePath=", exportCodePath);
|
||||
let pkgId = handler.pkg.id;
|
||||
packageName = handler.pkg.name;
|
||||
existScriptPaths = {};
|
||||
let list = [];
|
||||
getAllFile(exportCodePath, list);
|
||||
//开始前,先遍历整个生成目录。找寻所有文件。用以判断生成的文件存放地址
|
||||
getAllDirector(exportCodePath, list);
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
let path = list[index];
|
||||
var newPath = path.replace(/\\/g, '/');
|
||||
let arrs = newPath.split('/');
|
||||
let key = arrs[arrs.length - 1];
|
||||
existScriptPaths[key] = path;
|
||||
}
|
||||
namespaceName = "";
|
||||
setNamespaceName = false;
|
||||
if (settings.packageName) {
|
||||
namespaceName = settings.packageName;
|
||||
setNamespaceName = true;
|
||||
}
|
||||
let classes = handler.CollectClasses(settings.ignoreNoname, settings.ignoreNoname, null);
|
||||
let getMemberByName = true; //默认使用名称获取对象//settings.getMemberByName;
|
||||
console.log(codePkgName, namespaceName, getMemberByName);
|
||||
let classCnt = classes.Count;
|
||||
allCustomNameByUrl = {};
|
||||
allSuperClassNameByUrl = {};
|
||||
let dependPackages = [];
|
||||
//因为没有文档,同时返回内容限制,先保存子类基类关系。用于后续判断是否使用自定义类
|
||||
for (let i = 0; i < classCnt; i++) {
|
||||
let classInfo = classes.get_Item(i);
|
||||
let url = classInfo.res.GetURL();
|
||||
allSuperClassNameByUrl[url] = classInfo.superClassName;
|
||||
let config = GenCodeSettings_1.default.getComponentSetting(url);
|
||||
if (config != null) {
|
||||
if (config.isCustomName) {
|
||||
allCustomNameByUrl[url] = settings.classNamePrefix + config.customName;
|
||||
}
|
||||
}
|
||||
//获取依赖的包
|
||||
for (let index = 0; index < classInfo.members.Count; index++) {
|
||||
let element = classInfo.members.get_Item(index);
|
||||
if (element.res != null && element.res.owner != null) {
|
||||
let pname = element.res.owner.name;
|
||||
if (dependPackages.indexOf(pname) < 0 && pname != codePkgName) {
|
||||
dependPackages.push(pname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let componentClassNameArr = [];
|
||||
for (let i = 0; i < classCnt; i++) {
|
||||
let classInfo = classes.get_Item(i);
|
||||
let url = classInfo.res.GetURL();
|
||||
let config = GenCodeSettings_1.default.getComponentSetting(url);
|
||||
if (config != null) {
|
||||
console.log(config.name, config.scriptType);
|
||||
if (config.scriptType == "panel") {
|
||||
genPanelCode(classInfo, config, codePkgName, pkgId, dependPackages);
|
||||
}
|
||||
else if (config.scriptType == "component") {
|
||||
let ComponentClassName = genComponentCode(classInfo, config, codePkgName, pkgId);
|
||||
componentClassNameArr.push(ComponentClassName);
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log(classInfo.resName + "未配置导出,忽略");
|
||||
}
|
||||
}
|
||||
console.log("生成Binder,count=" + componentClassNameArr.length);
|
||||
genBinder(codePkgName, componentClassNameArr);
|
||||
genLanguage();
|
||||
// 生成动效配置
|
||||
genTween();
|
||||
}
|
||||
function getScriptName(className, comUrl) {
|
||||
if (allCustomNameByUrl.hasOwnProperty(comUrl)) {
|
||||
className = allCustomNameByUrl[comUrl];
|
||||
}
|
||||
return className;
|
||||
}
|
||||
function genPanelCode(classInfo, config, codePkgName, pkgId, dependPackages) {
|
||||
let codeConfig = new WhootCodeWriterConfig();
|
||||
codeConfig.fileMark = "/**本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/";
|
||||
let comUrl = classInfo.res.GetURL();
|
||||
//先生成 .Designer部分
|
||||
let writer = new CodeWriter_1.default(codeConfig);
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln('using FairyGUI.Utils;');
|
||||
writer.writeln('using NBC;');
|
||||
writer.writeln('using System.Collections.Generic;');
|
||||
writer.writeln();
|
||||
let className = getScriptName(classInfo.className, comUrl);
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
writer.writeln("/// <summary> %s </summary>", config.annotation);
|
||||
writer.writeln('public partial class %s', className);
|
||||
writer.startBlock();
|
||||
}
|
||||
else {
|
||||
writer.writeln("/// <summary> %s </summary>", config.annotation);
|
||||
writer.writeln('public partial class %s', className);
|
||||
writer.startBlock();
|
||||
}
|
||||
writer.writeln("public GObject this[string aKey] => ContentPane.GetChild(aKey);");
|
||||
writer.writeln('public override string UIPackName => "%s";', codePkgName);
|
||||
writer.writeln('public override string UIResName => "%s";', classInfo.res.name);
|
||||
writer.writeln();
|
||||
let members = classInfo.members;
|
||||
let memberCnt = members.Count;
|
||||
for (let j = 0; j < memberCnt; j++) {
|
||||
let memberInfo = members.get_Item(j);
|
||||
if (memberInfo.res != null) {
|
||||
let superClassName = getComponentUseClassName(memberInfo, comUrl);
|
||||
writer.writeln('[AutoFind(Name = "%s")]', memberInfo.name);
|
||||
//判断配置,是否需要使用生成的类
|
||||
writer.writeln('public %s %s;', superClassName, memberInfo.varName);
|
||||
}
|
||||
else {
|
||||
writer.writeln('[AutoFind(Name = "%s")]', memberInfo.name);
|
||||
writer.writeln('public %s %s;', memberInfo.type, memberInfo.varName);
|
||||
}
|
||||
}
|
||||
let url = `ui://${pkgId}${classInfo.resId}`;
|
||||
if (dependPackages != null) {
|
||||
let str = "";
|
||||
let len = dependPackages.length - 1;
|
||||
for (let index = 0; index <= len; index++) {
|
||||
let pname = dependPackages[index];
|
||||
str += `"${pname}"`;
|
||||
if (index < len) {
|
||||
str += ",";
|
||||
}
|
||||
}
|
||||
writer.writeln(`public override string[] GetDependPackages(){ return new string[] {${str}}; }`);
|
||||
writer.writeln();
|
||||
}
|
||||
writer.writeln(`public static void Show(object param = null){ UI.Inst.OpenUI<${className}>(param); }`);
|
||||
writer.writeln();
|
||||
writer.writeln(`public static void Hide(){ UI.Inst.HideUI<${className}>(); }`);
|
||||
writer.writeln();
|
||||
writer.writeln(`public static void Del(){ UI.Inst.DestroyUI<${className}>(); }`);
|
||||
writer.writeln();
|
||||
writer.endBlock();
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock();
|
||||
}
|
||||
let fileName = className + ".Designer" + '.cs';
|
||||
let savePath = exportCodePath + '/' + fileName;
|
||||
if (existScriptPaths.hasOwnProperty(fileName)) {
|
||||
console.log("脚本已经有同名的,替换地址=", fileName, existScriptPaths[fileName]);
|
||||
savePath = existScriptPaths[fileName];
|
||||
}
|
||||
writer.save(savePath);
|
||||
// 判断模块脚本是否存在。如果不存在,创建默认模板脚本
|
||||
let defFileName = className + '.cs';
|
||||
if (!existScriptPaths.hasOwnProperty(defFileName)) {
|
||||
let mainSavePath = exportCodePath + '/' + defFileName;
|
||||
console.log("Panel的主脚本不存在,生成默认=", mainSavePath);
|
||||
writer.reset();
|
||||
codeConfig.fileMark = "// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖";
|
||||
writer = new CodeWriter_1.default(codeConfig);
|
||||
writer.writeln('using UnityEngine;');
|
||||
writer.writeln('using NBC;');
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
writer.writeln('public partial class %s : UIPanel', className);
|
||||
writer.startBlock();
|
||||
}
|
||||
else {
|
||||
writer.writeln('public partial class %s : UIPanel', className);
|
||||
writer.startBlock();
|
||||
}
|
||||
// writer.writeln('protected override void OnInit()');
|
||||
// writer.startBlock();
|
||||
// writer.writeln('base.OnInit();');
|
||||
// writer.endBlock();
|
||||
// writer.writeln();
|
||||
// writer.writeln('protected override void OnShow()');
|
||||
// writer.startBlock();
|
||||
// writer.writeln('base.OnShow();');
|
||||
// writer.endBlock();
|
||||
// writer.writeln();
|
||||
// writer.writeln('protected override void OnHide()');
|
||||
// writer.startBlock();
|
||||
// writer.writeln('base.OnHide();');
|
||||
// writer.endBlock();
|
||||
// writer.writeln();
|
||||
// writer.writeln('protected override void OnDestroy()');
|
||||
// writer.startBlock();
|
||||
// writer.writeln('base.OnDestroy();');
|
||||
// writer.endBlock();
|
||||
writer.endBlock();
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock();
|
||||
}
|
||||
writer.save(mainSavePath);
|
||||
}
|
||||
}
|
||||
function getComponentUseClassName(memberInfo, comUrl) {
|
||||
let name = memberInfo.type;
|
||||
let useCustomScript = false;
|
||||
if (memberInfo.res != null) {
|
||||
let comUrl = memberInfo.res.GetURL();
|
||||
//是自定义组件,改为使用原生,不适用自定义
|
||||
let superClassName = allSuperClassNameByUrl[comUrl];
|
||||
let config = GenCodeSettings_1.default.getComponentSetting(comUrl);
|
||||
if (config != null && config.scriptType == "component") {
|
||||
superClassName = memberInfo.res.name;
|
||||
useCustomScript = true;
|
||||
}
|
||||
if (superClassName == null || superClassName == undefined) {
|
||||
superClassName = memberInfo.type;
|
||||
}
|
||||
name = superClassName;
|
||||
}
|
||||
return name; //{ name: name, useCustomScript: useCustomScript }
|
||||
}
|
||||
function genComponentCode(classInfo, config, codePkgName, pkgId) {
|
||||
let codeConfig = new WhootCodeWriterConfig();
|
||||
codeConfig.fileMark = "/**本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/";
|
||||
let comUrl = classInfo.res.GetURL();
|
||||
let className = getScriptName(classInfo.className, comUrl);
|
||||
let writer = new CodeWriter_1.default(codeConfig);
|
||||
writer.writeln();
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln('using FairyGUI.Utils;');
|
||||
writer.writeln('using NBC;');
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
writer.writeln('public partial class %s', className);
|
||||
writer.startBlock();
|
||||
}
|
||||
else {
|
||||
writer.writeln('public partial class %s', className);
|
||||
writer.startBlock();
|
||||
}
|
||||
writer.writeln('public const string URL = "ui://%s%s";', pkgId, classInfo.resId);
|
||||
writer.writeln();
|
||||
//生成成员变量
|
||||
let members = classInfo.members;
|
||||
let memberCnt = members.Count;
|
||||
for (let j = 0; j < memberCnt; j++) {
|
||||
let memberInfo = members.get_Item(j);
|
||||
if (memberInfo.res != null) {
|
||||
let superClassName = getComponentUseClassName(memberInfo, comUrl);
|
||||
writer.writeln('public %s %s;', superClassName, memberInfo.varName);
|
||||
}
|
||||
else {
|
||||
writer.writeln('public %s %s;', memberInfo.type, memberInfo.varName);
|
||||
}
|
||||
}
|
||||
writer.writeln();
|
||||
writer.writeln('public override void ConstructFromXML(XML xml)');
|
||||
writer.startBlock();
|
||||
writer.writeln('base.ConstructFromXML(xml);');
|
||||
writer.writeln();
|
||||
for (let j = 0; j < memberCnt; j++) {
|
||||
let memberInfo = members.get_Item(j);
|
||||
if (memberInfo.group == 0) {
|
||||
let superClassName = memberInfo.type;
|
||||
let useExtend = false;
|
||||
if (memberInfo.res != null) {
|
||||
superClassName = getComponentUseClassName(memberInfo, comUrl);
|
||||
}
|
||||
writer.writeln('%s = (%s)GetChild("%s");', memberInfo.varName, superClassName, memberInfo.name);
|
||||
}
|
||||
else if (memberInfo.group == 1) {
|
||||
writer.writeln('%s = GetController("%s");', memberInfo.varName, memberInfo.name);
|
||||
}
|
||||
else {
|
||||
writer.writeln('%s = GetTransition("%s");', memberInfo.varName, memberInfo.name);
|
||||
}
|
||||
}
|
||||
writer.writeln('OnInited();');
|
||||
writer.writeln('UILanguage.TrySetComponentLanguage(this);');
|
||||
writer.endBlock();
|
||||
writer.endBlock();
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock();
|
||||
}
|
||||
let fileName = className + ".Designer" + '.cs';
|
||||
let savePath = exportCodePath + '/' + fileName;
|
||||
if (existScriptPaths.hasOwnProperty(fileName)) {
|
||||
console.log("脚本已经有同名的,替换地址=", fileName, existScriptPaths[fileName]);
|
||||
savePath = existScriptPaths[fileName];
|
||||
}
|
||||
writer.save(savePath);
|
||||
// 判断模块脚本是否存在。如果不存在,创建默认模板脚本
|
||||
let defFileName = className + '.cs';
|
||||
if (!existScriptPaths.hasOwnProperty(defFileName)) {
|
||||
let mainSavePath = exportCodePath + '/' + defFileName;
|
||||
console.log("Component的主脚本不存在,生成默认");
|
||||
writer.reset();
|
||||
codeConfig.fileMark = "// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖 ";
|
||||
writer = new CodeWriter_1.default(codeConfig);
|
||||
writer.writeln('using UnityEngine;');
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln('using NBC;');
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
writer.writeln('public partial class %s : %s', className, classInfo.superClassName);
|
||||
writer.startBlock();
|
||||
}
|
||||
else {
|
||||
writer.writeln('public partial class %s : %s', className, classInfo.superClassName);
|
||||
writer.startBlock();
|
||||
}
|
||||
writer.writeln('private void OnInited()');
|
||||
writer.startBlock();
|
||||
writer.endBlock();
|
||||
writer.endBlock();
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock();
|
||||
}
|
||||
writer.save(mainSavePath);
|
||||
}
|
||||
return className;
|
||||
}
|
||||
/**
|
||||
* 生成自定义脚本绑定关系
|
||||
* @param codePkgName
|
||||
* @param componentClassNameArr
|
||||
*/
|
||||
function genBinder(codePkgName, componentClassNameArr) {
|
||||
let binderName = codePkgName + 'Binder';
|
||||
let codeConfig = new WhootCodeWriterConfig();
|
||||
codeConfig.fileMark = "/**注册组件绑定关系。本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/";
|
||||
let writer = new CodeWriter_1.default(codeConfig);
|
||||
writer.reset();
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
}
|
||||
writer.writeln('public static class %s', binderName);
|
||||
writer.startBlock();
|
||||
writer.writeln('[UIExtensionAutoBind]');
|
||||
writer.writeln('public static void BindAll()');
|
||||
writer.startBlock();
|
||||
for (let i = 0; i < componentClassNameArr.length; i++) {
|
||||
//let classInfo = classes.get_Item(i);
|
||||
let name = componentClassNameArr[i];
|
||||
writer.writeln('UIObjectFactory.SetPackageItemExtension(%s.URL, typeof(%s));', name, name);
|
||||
}
|
||||
writer.endBlock(); //bindall
|
||||
writer.endBlock(); //class
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock(); //namespace
|
||||
}
|
||||
let fileName = binderName + '.cs';
|
||||
let savePath = exportCodePath + '/' + fileName;
|
||||
console.log("生成binder 1=", fileName);
|
||||
if (existScriptPaths.hasOwnProperty(fileName)) {
|
||||
savePath = existScriptPaths[fileName];
|
||||
}
|
||||
writer.save(savePath);
|
||||
}
|
||||
/**
|
||||
* 生成多语言
|
||||
*/
|
||||
function genLanguage() {
|
||||
let binderName = 'UILangeageConfig';
|
||||
let languageMap = LanguageSettings_1.default.getAllPackage();
|
||||
//getPackage
|
||||
let codeConfig = new WhootCodeWriterConfig();
|
||||
codeConfig.fileMark = "/**注册组件多语言绑定。本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/";
|
||||
let writer = new CodeWriter_1.default(codeConfig);
|
||||
writer.reset();
|
||||
writer.writeln('using System.Collections.Generic;');
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln('using NBC;');
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
}
|
||||
writer.writeln('public class %s : UIComponentLanguagePack', binderName);
|
||||
writer.startBlock();
|
||||
writer.writeln('public UILangeageConfig()');
|
||||
writer.startBlock();
|
||||
writer.writeln('AddData();');
|
||||
writer.endBlock();
|
||||
writer.writeln('private void AddData()');
|
||||
writer.startBlock();
|
||||
let keys = languageMap.keys();
|
||||
for (let key of keys) {
|
||||
let pack = languageMap.get(key);
|
||||
let languageData = pack.components;
|
||||
for (let comUrl in languageData) {
|
||||
let comObj = languageData[comUrl];
|
||||
if (comObj == undefined)
|
||||
continue;
|
||||
writer.writeln('Add("%s", new UIComponentLanguage()', comUrl);
|
||||
writer.startBlock();
|
||||
for (let key2 in comObj) {
|
||||
var cfg = comObj[key2];
|
||||
let useable = cfg['useable'];
|
||||
let languageKey = cfg["key"];
|
||||
if (useable != 1)
|
||||
continue;
|
||||
writer.writeln('{ "%s", "%s" },', key2, languageKey);
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.writeln(');');
|
||||
}
|
||||
writer.writeln();
|
||||
}
|
||||
// for (let comUrl in languageData) {
|
||||
// let comObj = languageData[comUrl];
|
||||
// if (comObj != undefined) {
|
||||
// for (let key in comObj) {
|
||||
// var cfg = comObj[key]
|
||||
// let useable = cfg['useable']
|
||||
// let languageKey = cfg["key"]
|
||||
// if (useable == 1) {
|
||||
// console.log("comurl:" + comUrl + " key:" + key + " lan:" + languageKey)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
writer.endBlock(); //bindall
|
||||
writer.endBlock(); //class
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock(); //namespace
|
||||
}
|
||||
let fileName = binderName + '.cs';
|
||||
let savePath = exportCodePath + '/' + fileName;
|
||||
console.log("生成 language=", fileName);
|
||||
if (existScriptPaths.hasOwnProperty(fileName)) {
|
||||
savePath = existScriptPaths[fileName];
|
||||
}
|
||||
writer.save(savePath);
|
||||
}
|
||||
/**
|
||||
* 生成动效配置
|
||||
* 结构参考多语言生成:按包 -> 组件URL -> 子项id,写入 C# 配置类
|
||||
*/
|
||||
function genTween() {
|
||||
let binderName = 'UITweenConfig';
|
||||
if (!tweenSetting || !tweenSetting.getAllPackage) {
|
||||
console.warn('UITweenConfig 生成被跳过:未找到 ../whoot-tween/TweenSettings.js 或接口不完整');
|
||||
return;
|
||||
}
|
||||
let tweenMap = tweenSetting.getAllPackage();
|
||||
let codeConfig = new WhootCodeWriterConfig();
|
||||
codeConfig.fileMark = "/**注册组件动效绑定。本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/";
|
||||
let writer = new CodeWriter_1.default(codeConfig);
|
||||
writer.reset();
|
||||
writer.writeln('using System.Collections.Generic;');
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln('using NBC;');
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
}
|
||||
writer.writeln('public class %s : UIComponentTweenPack', binderName);
|
||||
writer.startBlock();
|
||||
writer.writeln('public %s()', binderName);
|
||||
writer.startBlock();
|
||||
writer.writeln('AddData();');
|
||||
writer.endBlock();
|
||||
writer.writeln();
|
||||
writer.writeln('private void AddData()');
|
||||
writer.startBlock();
|
||||
let keys = tweenMap.keys();
|
||||
for (let key of keys) {
|
||||
let pack = tweenMap.get(key);
|
||||
let tweenData = pack.components;
|
||||
for (let comUrl in tweenData) {
|
||||
let comObj = tweenData[comUrl];
|
||||
if (comObj == undefined)
|
||||
continue;
|
||||
writer.writeln('// %s', key);
|
||||
writer.writeln('Add("%s", new UIComponentTween()', comUrl);
|
||||
writer.startBlock();
|
||||
for (let childId in comObj) {
|
||||
var cfg = comObj[childId];
|
||||
let useable = cfg['useable'];
|
||||
let tweenKey = cfg['key'];
|
||||
if (useable != 1)
|
||||
continue;
|
||||
writer.writeln('{ "%s", "%s" },', childId, tweenKey);
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.writeln(');');
|
||||
}
|
||||
writer.writeln();
|
||||
}
|
||||
writer.endBlock(); // AddData
|
||||
writer.endBlock(); // class
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock(); // namespace
|
||||
}
|
||||
let fileName = binderName + '.cs';
|
||||
let savePath = exportCodePath + '/' + fileName;
|
||||
console.log("生成 tween=", fileName);
|
||||
if (existScriptPaths.hasOwnProperty(fileName)) {
|
||||
savePath = existScriptPaths[fileName];
|
||||
}
|
||||
writer.save(savePath);
|
||||
}
|
||||
683
FGUIProject/plugins/nbc-puerts-plugins/GenCode_CSharp.ts
Normal file
683
FGUIProject/plugins/nbc-puerts-plugins/GenCode_CSharp.ts
Normal file
@@ -0,0 +1,683 @@
|
||||
import FairyGUI = CS.FairyGUI;
|
||||
import FairyEditor = CS.FairyEditor;
|
||||
import System = CS.System;
|
||||
import CodeWriter, { ICodeWriterConfig } from './CodeWriter';
|
||||
import genSetting, { ComponentData, MemberData } from './GenCodeSettings'
|
||||
import languageSetting, { LanguageComponentChildData } from './LanguageSettings'
|
||||
|
||||
// Tween 使用运行时 require,避免跨项目编译输出位置错乱;本地定义最小类型接口
|
||||
interface TweenComponentChildData { id: string; key: string; useable: number }
|
||||
// 注意:运行时从相对路径加载已编译的 JS(CustomAttributer/TweenSettings.js)
|
||||
declare const require: any;
|
||||
const tweenSetting: any = (function(){
|
||||
try { return require('../whoot-tween/TweenSettings').default || require('../whoot-tween/TweenSettings'); } catch { return null; }
|
||||
})();
|
||||
|
||||
const File = System.IO.File;
|
||||
const Directory = System.IO.Directory;
|
||||
const App = FairyEditor.App;
|
||||
|
||||
var allSuperClassNameByUrl = {}
|
||||
var allCustomNameByUrl = {}
|
||||
|
||||
var namespaceName = "";
|
||||
var setNamespaceName = false
|
||||
var exportCodePath = ""
|
||||
var existScriptPaths = {};
|
||||
var packageName = ''
|
||||
|
||||
//获取所有的文件的路径
|
||||
function getAllDirector(path: string, list: Array<string>) {
|
||||
let dirs = Directory.GetDirectories(path)
|
||||
for (let index = 0; index < dirs.Length; index++) {
|
||||
let dir = dirs.get_Item(index);
|
||||
getAllFile(dir, list)
|
||||
let dirs2 = Directory.GetDirectories(dir)
|
||||
if (dirs2.Length > 0) {
|
||||
getAllDirector(dir, list)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getAllFile(dir: string, list: Array<string>) {
|
||||
let files = Directory.GetFiles(dir, "*.cs")
|
||||
for (let f = 0; f < files.Length; f++) {
|
||||
list.push(files.get_Item(f))
|
||||
}
|
||||
}
|
||||
|
||||
class WhootCodeWriterConfig implements ICodeWriterConfig {
|
||||
blockStart?: string;
|
||||
blockEnd?: string;
|
||||
blockFromNewLine?: boolean;
|
||||
usingTabs?: boolean;
|
||||
endOfLine?: string;
|
||||
fileMark?: string;
|
||||
}
|
||||
|
||||
|
||||
function genCSCode(handler: FairyEditor.PublishHandler) {
|
||||
console.log("gencode==========--------------========")
|
||||
|
||||
let settings = (<FairyEditor.GlobalPublishSettings>handler.project.GetSettings("Publish")).codeGeneration;
|
||||
let codePkgName = handler.ToFilename(handler.pkg.name);
|
||||
exportCodePath = handler.exportCodePath // + '/' + codePkgName;
|
||||
console.log("exportCodePath=", exportCodePath)
|
||||
|
||||
let pkgId = handler.pkg.id;
|
||||
packageName = handler.pkg.name
|
||||
existScriptPaths = {};
|
||||
|
||||
let list: Array<string> = []
|
||||
getAllFile(exportCodePath, list)
|
||||
//开始前,先遍历整个生成目录。找寻所有文件。用以判断生成的文件存放地址
|
||||
getAllDirector(exportCodePath, list);
|
||||
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
let path = list[index];
|
||||
|
||||
var newPath = path.replace(/\\/g, '/');
|
||||
let arrs = newPath.split('/')
|
||||
let key = arrs[arrs.length - 1]
|
||||
existScriptPaths[key] = path
|
||||
}
|
||||
|
||||
|
||||
namespaceName = "";
|
||||
setNamespaceName = false
|
||||
if (settings.packageName) {
|
||||
namespaceName = settings.packageName
|
||||
setNamespaceName = true
|
||||
}
|
||||
let classes = handler.CollectClasses(settings.ignoreNoname, settings.ignoreNoname, null);
|
||||
let getMemberByName = true;//默认使用名称获取对象//settings.getMemberByName;
|
||||
console.log(codePkgName, namespaceName, getMemberByName)
|
||||
let classCnt = classes.Count;
|
||||
|
||||
allCustomNameByUrl = {}
|
||||
allSuperClassNameByUrl = {}
|
||||
let dependPackages: Array<string> = []
|
||||
|
||||
//因为没有文档,同时返回内容限制,先保存子类基类关系。用于后续判断是否使用自定义类
|
||||
for (let i: number = 0; i < classCnt; i++) {
|
||||
let classInfo = classes.get_Item(i);
|
||||
let url = classInfo.res.GetURL();
|
||||
allSuperClassNameByUrl[url] = classInfo.superClassName
|
||||
let config: ComponentData = genSetting.getComponentSetting(url)
|
||||
if (config != null) {
|
||||
if (config.isCustomName) {
|
||||
allCustomNameByUrl[url] = settings.classNamePrefix + config.customName
|
||||
}
|
||||
}
|
||||
|
||||
//获取依赖的包
|
||||
for (let index = 0; index < classInfo.members.Count; index++) {
|
||||
let element = classInfo.members.get_Item(index);
|
||||
if (element.res != null && element.res.owner != null) {
|
||||
let pname = element.res.owner.name;
|
||||
if (dependPackages.indexOf(pname) < 0 && pname != codePkgName) {
|
||||
dependPackages.push(pname)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let componentClassNameArr: Array<string> = []
|
||||
|
||||
for (let i: number = 0; i < classCnt; i++) {
|
||||
let classInfo = classes.get_Item(i);
|
||||
let url = classInfo.res.GetURL();
|
||||
let config: ComponentData = genSetting.getComponentSetting(url)
|
||||
if (config != null) {
|
||||
console.log(config.name, config.scriptType)
|
||||
if (config.scriptType == "panel") {
|
||||
genPanelCode(classInfo, config, codePkgName, pkgId, dependPackages);
|
||||
} else if (config.scriptType == "component") {
|
||||
let ComponentClassName = genComponentCode(classInfo, config, codePkgName, pkgId)
|
||||
componentClassNameArr.push(ComponentClassName)
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log(classInfo.resName + "未配置导出,忽略")
|
||||
}
|
||||
}
|
||||
console.log("生成Binder,count="+componentClassNameArr.length)
|
||||
genBinder(codePkgName, componentClassNameArr);
|
||||
genLanguage();
|
||||
// 生成动效配置
|
||||
genTween();
|
||||
}
|
||||
|
||||
function getScriptName(className: string, comUrl: string) {
|
||||
if (allCustomNameByUrl.hasOwnProperty(comUrl)) {
|
||||
className = allCustomNameByUrl[comUrl]
|
||||
}
|
||||
return className
|
||||
}
|
||||
|
||||
|
||||
function genPanelCode(classInfo: FairyEditor.PublishHandler.ClassInfo, config: ComponentData, codePkgName: string, pkgId: string, dependPackages?: Array<string>) {
|
||||
let codeConfig: WhootCodeWriterConfig = new WhootCodeWriterConfig();
|
||||
codeConfig.fileMark = "/**本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/"
|
||||
|
||||
let comUrl = classInfo.res.GetURL();
|
||||
//先生成 .Designer部分
|
||||
let writer = new CodeWriter(codeConfig);
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln('using FairyGUI.Utils;');
|
||||
writer.writeln('using NBC;');
|
||||
writer.writeln('using System.Collections.Generic;');
|
||||
|
||||
writer.writeln();
|
||||
let className = getScriptName(classInfo.className, comUrl)
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
writer.writeln("/// <summary> %s </summary>", config.annotation);
|
||||
writer.writeln('public partial class %s', className);
|
||||
writer.startBlock();
|
||||
} else {
|
||||
writer.writeln("/// <summary> %s </summary>", config.annotation);
|
||||
writer.writeln('public partial class %s', className);
|
||||
writer.startBlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
writer.writeln("public GObject this[string aKey] => ContentPane.GetChild(aKey);");
|
||||
|
||||
writer.writeln('public override string UIPackName => "%s";', codePkgName);
|
||||
writer.writeln('public override string UIResName => "%s";', classInfo.res.name);
|
||||
writer.writeln();
|
||||
|
||||
let members = classInfo.members;
|
||||
let memberCnt = members.Count
|
||||
for (let j: number = 0; j < memberCnt; j++) {
|
||||
let memberInfo = members.get_Item(j);
|
||||
|
||||
if (memberInfo.res != null) {
|
||||
|
||||
let superClassName = getComponentUseClassName(memberInfo, comUrl)
|
||||
|
||||
writer.writeln('[AutoFind(Name = "%s")]', memberInfo.name)
|
||||
//判断配置,是否需要使用生成的类
|
||||
writer.writeln('public %s %s;', superClassName, memberInfo.varName);
|
||||
} else {
|
||||
writer.writeln('[AutoFind(Name = "%s")]', memberInfo.name)
|
||||
writer.writeln('public %s %s;', memberInfo.type, memberInfo.varName);
|
||||
}
|
||||
}
|
||||
|
||||
let url = `ui://${pkgId}${classInfo.resId}`
|
||||
|
||||
if (dependPackages != null) {
|
||||
let str = "";
|
||||
let len = dependPackages.length - 1;
|
||||
for (let index = 0; index <= len; index++) {
|
||||
let pname = dependPackages[index];
|
||||
str += `"${pname}"`;
|
||||
if (index < len) {
|
||||
str += ",";
|
||||
}
|
||||
}
|
||||
writer.writeln(`public override string[] GetDependPackages(){ return new string[] {${str}}; }`)
|
||||
writer.writeln();
|
||||
}
|
||||
|
||||
writer.writeln(`public static void Show(object param = null){ UI.Inst.OpenUI<${className}>(param); }`)
|
||||
writer.writeln();
|
||||
|
||||
writer.writeln(`public static void Hide(){ UI.Inst.HideUI<${className}>(); }`)
|
||||
writer.writeln();
|
||||
|
||||
writer.writeln(`public static void Del(){ UI.Inst.DestroyUI<${className}>(); }`)
|
||||
writer.writeln();
|
||||
|
||||
|
||||
writer.endBlock();
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock();
|
||||
}
|
||||
|
||||
let fileName = className + ".Designer" + '.cs'
|
||||
let savePath = exportCodePath + '/' + fileName
|
||||
if (existScriptPaths.hasOwnProperty(fileName)) {
|
||||
console.log("脚本已经有同名的,替换地址=", fileName, existScriptPaths[fileName])
|
||||
savePath = existScriptPaths[fileName]
|
||||
}
|
||||
|
||||
writer.save(savePath);
|
||||
|
||||
// 判断模块脚本是否存在。如果不存在,创建默认模板脚本
|
||||
let defFileName = className + '.cs'
|
||||
if (!existScriptPaths.hasOwnProperty(defFileName)) {
|
||||
let mainSavePath = exportCodePath + '/' + defFileName
|
||||
console.log("Panel的主脚本不存在,生成默认=", mainSavePath)
|
||||
writer.reset();
|
||||
codeConfig.fileMark = "// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖"
|
||||
writer = new CodeWriter(codeConfig);
|
||||
writer.writeln('using UnityEngine;');
|
||||
writer.writeln('using NBC;');
|
||||
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
writer.writeln('public partial class %s : UIPanel', className);
|
||||
writer.startBlock();
|
||||
} else {
|
||||
writer.writeln('public partial class %s : UIPanel', className);
|
||||
writer.startBlock();
|
||||
}
|
||||
|
||||
// writer.writeln('protected override void OnInit()');
|
||||
// writer.startBlock();
|
||||
// writer.writeln('base.OnInit();');
|
||||
// writer.endBlock();
|
||||
// writer.writeln();
|
||||
|
||||
// writer.writeln('protected override void OnShow()');
|
||||
// writer.startBlock();
|
||||
// writer.writeln('base.OnShow();');
|
||||
// writer.endBlock();
|
||||
// writer.writeln();
|
||||
|
||||
// writer.writeln('protected override void OnHide()');
|
||||
// writer.startBlock();
|
||||
// writer.writeln('base.OnHide();');
|
||||
// writer.endBlock();
|
||||
|
||||
// writer.writeln();
|
||||
// writer.writeln('protected override void OnDestroy()');
|
||||
// writer.startBlock();
|
||||
// writer.writeln('base.OnDestroy();');
|
||||
// writer.endBlock();
|
||||
|
||||
|
||||
writer.endBlock();
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock();
|
||||
}
|
||||
|
||||
writer.save(mainSavePath);
|
||||
}
|
||||
}
|
||||
|
||||
function getComponentUseClassName(memberInfo: FairyEditor.PublishHandler.MemberInfo, comUrl: string) {
|
||||
let name = memberInfo.type
|
||||
let useCustomScript = false
|
||||
if (memberInfo.res != null) {
|
||||
let comUrl = memberInfo.res.GetURL();
|
||||
//是自定义组件,改为使用原生,不适用自定义
|
||||
let superClassName = allSuperClassNameByUrl[comUrl]
|
||||
|
||||
let config: ComponentData = genSetting.getComponentSetting(comUrl)
|
||||
if (config != null && config.scriptType == "component") {
|
||||
superClassName = memberInfo.res.name
|
||||
useCustomScript = true
|
||||
}
|
||||
|
||||
if (superClassName == null || superClassName == undefined) {
|
||||
superClassName = memberInfo.type
|
||||
}
|
||||
name = superClassName
|
||||
}
|
||||
return name;//{ name: name, useCustomScript: useCustomScript }
|
||||
}
|
||||
|
||||
function genComponentCode(classInfo: FairyEditor.PublishHandler.ClassInfo, config: ComponentData, codePkgName: string, pkgId: string) {
|
||||
let codeConfig: WhootCodeWriterConfig = new WhootCodeWriterConfig();
|
||||
codeConfig.fileMark = "/**本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/"
|
||||
let comUrl = classInfo.res.GetURL();
|
||||
let className = getScriptName(classInfo.className, comUrl)
|
||||
|
||||
let writer = new CodeWriter(codeConfig);
|
||||
|
||||
writer.writeln();
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln('using FairyGUI.Utils;');
|
||||
writer.writeln('using NBC;');
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
writer.writeln('public partial class %s', className);
|
||||
writer.startBlock();
|
||||
} else {
|
||||
writer.writeln('public partial class %s', className);
|
||||
writer.startBlock();
|
||||
}
|
||||
|
||||
writer.writeln('public const string URL = "ui://%s%s";', pkgId, classInfo.resId);
|
||||
writer.writeln();
|
||||
//生成成员变量
|
||||
let members = classInfo.members;
|
||||
let memberCnt = members.Count
|
||||
for (let j: number = 0; j < memberCnt; j++) {
|
||||
let memberInfo = members.get_Item(j);
|
||||
if (memberInfo.res != null) {
|
||||
let superClassName = getComponentUseClassName(memberInfo, comUrl)
|
||||
writer.writeln('public %s %s;', superClassName, memberInfo.varName);
|
||||
} else {
|
||||
writer.writeln('public %s %s;', memberInfo.type, memberInfo.varName);
|
||||
}
|
||||
}
|
||||
writer.writeln();
|
||||
writer.writeln('public override void ConstructFromXML(XML xml)');
|
||||
writer.startBlock();
|
||||
writer.writeln('base.ConstructFromXML(xml);');
|
||||
writer.writeln();
|
||||
|
||||
for (let j: number = 0; j < memberCnt; j++) {
|
||||
let memberInfo = members.get_Item(j);
|
||||
if (memberInfo.group == 0) {
|
||||
let superClassName = memberInfo.type
|
||||
let useExtend = false
|
||||
|
||||
if (memberInfo.res != null) {
|
||||
superClassName = getComponentUseClassName(memberInfo, comUrl)
|
||||
}
|
||||
writer.writeln('%s = (%s)GetChild("%s");', memberInfo.varName, superClassName, memberInfo.name);
|
||||
}
|
||||
else if (memberInfo.group == 1) {
|
||||
writer.writeln('%s = GetController("%s");', memberInfo.varName, memberInfo.name);
|
||||
}
|
||||
else {
|
||||
writer.writeln('%s = GetTransition("%s");', memberInfo.varName, memberInfo.name);
|
||||
}
|
||||
}
|
||||
writer.writeln('OnInited();');
|
||||
writer.writeln('UILanguage.TrySetComponentLanguage(this);');
|
||||
writer.endBlock();
|
||||
|
||||
writer.endBlock();
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock();
|
||||
}
|
||||
|
||||
let fileName = className + ".Designer" + '.cs'
|
||||
let savePath = exportCodePath + '/' + fileName
|
||||
if (existScriptPaths.hasOwnProperty(fileName)) {
|
||||
console.log("脚本已经有同名的,替换地址=", fileName, existScriptPaths[fileName])
|
||||
savePath = existScriptPaths[fileName]
|
||||
}
|
||||
|
||||
writer.save(savePath);
|
||||
|
||||
|
||||
// 判断模块脚本是否存在。如果不存在,创建默认模板脚本
|
||||
let defFileName = className + '.cs'
|
||||
if (!existScriptPaths.hasOwnProperty(defFileName)) {
|
||||
let mainSavePath = exportCodePath + '/' + defFileName
|
||||
|
||||
console.log("Component的主脚本不存在,生成默认")
|
||||
writer.reset();
|
||||
codeConfig.fileMark = "// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖 "
|
||||
writer = new CodeWriter(codeConfig);
|
||||
writer.writeln('using UnityEngine;');
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln('using NBC;');
|
||||
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
writer.writeln('public partial class %s : %s', className, classInfo.superClassName);
|
||||
writer.startBlock();
|
||||
} else {
|
||||
writer.writeln('public partial class %s : %s', className, classInfo.superClassName);
|
||||
writer.startBlock();
|
||||
}
|
||||
|
||||
|
||||
writer.writeln('private void OnInited()');
|
||||
writer.startBlock();
|
||||
writer.endBlock();
|
||||
|
||||
writer.endBlock();
|
||||
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock();
|
||||
}
|
||||
|
||||
writer.save(mainSavePath);
|
||||
}
|
||||
|
||||
return className
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成自定义脚本绑定关系
|
||||
* @param codePkgName
|
||||
* @param componentClassNameArr
|
||||
*/
|
||||
function genBinder(codePkgName: string, componentClassNameArr: Array<string>) {
|
||||
|
||||
let binderName = codePkgName + 'Binder';
|
||||
|
||||
|
||||
let codeConfig: WhootCodeWriterConfig = new WhootCodeWriterConfig();
|
||||
codeConfig.fileMark = "/**注册组件绑定关系。本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/"
|
||||
|
||||
let writer = new CodeWriter(codeConfig);
|
||||
writer.reset();
|
||||
|
||||
|
||||
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
}
|
||||
writer.writeln('public static class %s', binderName);
|
||||
writer.startBlock();
|
||||
|
||||
writer.writeln('[UIExtensionAutoBind]');
|
||||
writer.writeln('public static void BindAll()');
|
||||
writer.startBlock();
|
||||
for (let i: number = 0; i < componentClassNameArr.length; i++) {
|
||||
//let classInfo = classes.get_Item(i);
|
||||
let name = componentClassNameArr[i]
|
||||
writer.writeln('UIObjectFactory.SetPackageItemExtension(%s.URL, typeof(%s));', name, name);
|
||||
}
|
||||
writer.endBlock(); //bindall
|
||||
|
||||
writer.endBlock(); //class
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock(); //namespace
|
||||
}
|
||||
|
||||
let fileName = binderName + '.cs'
|
||||
let savePath = exportCodePath + '/' + fileName
|
||||
console.log("生成binder 1=", fileName)
|
||||
if (existScriptPaths.hasOwnProperty(fileName)) {
|
||||
savePath = existScriptPaths[fileName]
|
||||
}
|
||||
|
||||
writer.save(savePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成多语言
|
||||
*/
|
||||
function genLanguage() {
|
||||
let binderName = 'UILangeageConfig';
|
||||
|
||||
let languageMap = languageSetting.getAllPackage()
|
||||
//getPackage
|
||||
|
||||
let codeConfig: WhootCodeWriterConfig = new WhootCodeWriterConfig();
|
||||
codeConfig.fileMark = "/**注册组件多语言绑定。本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/"
|
||||
|
||||
let writer = new CodeWriter(codeConfig);
|
||||
writer.reset();
|
||||
|
||||
writer.writeln('using System.Collections.Generic;');
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln('using NBC;');
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
}
|
||||
writer.writeln('public class %s : UIComponentLanguagePack', binderName);
|
||||
writer.startBlock();
|
||||
|
||||
writer.writeln('public UILangeageConfig()');
|
||||
writer.startBlock();
|
||||
writer.writeln('AddData();');
|
||||
writer.endBlock();
|
||||
|
||||
|
||||
writer.writeln('private void AddData()');
|
||||
writer.startBlock();
|
||||
|
||||
|
||||
let keys = languageMap.keys();
|
||||
|
||||
for (let key of keys) {
|
||||
let pack = languageMap.get(key);
|
||||
let languageData = pack.components;
|
||||
|
||||
|
||||
for (let comUrl in languageData) {
|
||||
let comObj = languageData[comUrl];
|
||||
if (comObj == undefined) continue;
|
||||
|
||||
writer.writeln('Add("%s", new UIComponentLanguage()', comUrl);
|
||||
writer.startBlock();
|
||||
for (let key2 in comObj) {
|
||||
var cfg = comObj[key2]
|
||||
let useable = cfg['useable']
|
||||
let languageKey = cfg["key"]
|
||||
if (useable != 1) continue;
|
||||
writer.writeln('{ "%s", "%s" },', key2, languageKey);
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.writeln(');');
|
||||
}
|
||||
|
||||
writer.writeln();
|
||||
}
|
||||
|
||||
|
||||
// for (let comUrl in languageData) {
|
||||
// let comObj = languageData[comUrl];
|
||||
// if (comObj != undefined) {
|
||||
// for (let key in comObj) {
|
||||
// var cfg = comObj[key]
|
||||
// let useable = cfg['useable']
|
||||
// let languageKey = cfg["key"]
|
||||
// if (useable == 1) {
|
||||
// console.log("comurl:" + comUrl + " key:" + key + " lan:" + languageKey)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
writer.endBlock(); //bindall
|
||||
|
||||
writer.endBlock(); //class
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock(); //namespace
|
||||
}
|
||||
|
||||
|
||||
|
||||
let fileName = binderName + '.cs'
|
||||
let savePath = exportCodePath + '/' + fileName
|
||||
console.log("生成 language=", fileName)
|
||||
if (existScriptPaths.hasOwnProperty(fileName)) {
|
||||
savePath = existScriptPaths[fileName]
|
||||
}
|
||||
|
||||
writer.save(savePath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成动效配置
|
||||
* 结构参考多语言生成:按包 -> 组件URL -> 子项id,写入 C# 配置类
|
||||
*/
|
||||
function genTween() {
|
||||
let binderName = 'UITweenConfig';
|
||||
|
||||
if (!tweenSetting || !tweenSetting.getAllPackage) {
|
||||
console.warn('UITweenConfig 生成被跳过:未找到 ../whoot-tween/TweenSettings.js 或接口不完整');
|
||||
return;
|
||||
}
|
||||
let tweenMap = tweenSetting.getAllPackage();
|
||||
|
||||
let codeConfig: WhootCodeWriterConfig = new WhootCodeWriterConfig();
|
||||
codeConfig.fileMark = "/**注册组件动效绑定。本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/"
|
||||
|
||||
let writer = new CodeWriter(codeConfig);
|
||||
writer.reset();
|
||||
|
||||
writer.writeln('using System.Collections.Generic;');
|
||||
writer.writeln('using FairyGUI;');
|
||||
writer.writeln('using NBC;');
|
||||
writer.writeln();
|
||||
if (setNamespaceName) {
|
||||
writer.writeln('namespace %s', namespaceName);
|
||||
writer.startBlock();
|
||||
}
|
||||
writer.writeln('public class %s : UIComponentTweenPack', binderName);
|
||||
writer.startBlock();
|
||||
|
||||
writer.writeln('public %s()', binderName);
|
||||
writer.startBlock();
|
||||
writer.writeln('AddData();');
|
||||
writer.endBlock();
|
||||
|
||||
writer.writeln();
|
||||
writer.writeln('private void AddData()');
|
||||
writer.startBlock();
|
||||
|
||||
let keys = tweenMap.keys();
|
||||
for (let key of keys) {
|
||||
let pack = tweenMap.get(key);
|
||||
let tweenData = pack.components;
|
||||
|
||||
for (let comUrl in tweenData) {
|
||||
let comObj = tweenData[comUrl];
|
||||
if (comObj == undefined) continue;
|
||||
writer.writeln('// %s', key);
|
||||
writer.writeln('Add("%s", new UIComponentTween()', comUrl);
|
||||
writer.startBlock();
|
||||
for (let childId in comObj) {
|
||||
var cfg = comObj[childId] as TweenComponentChildData | any;
|
||||
let useable = cfg['useable'];
|
||||
let tweenKey = cfg['key'];
|
||||
if (useable != 1) continue;
|
||||
writer.writeln('{ "%s", "%s" },', childId, tweenKey);
|
||||
}
|
||||
writer.endBlock();
|
||||
writer.writeln(');');
|
||||
}
|
||||
|
||||
writer.writeln();
|
||||
}
|
||||
|
||||
writer.endBlock(); // AddData
|
||||
|
||||
writer.endBlock(); // class
|
||||
if (setNamespaceName) {
|
||||
writer.endBlock(); // namespace
|
||||
}
|
||||
|
||||
let fileName = binderName + '.cs'
|
||||
let savePath = exportCodePath + '/' + fileName
|
||||
console.log("生成 tween=", fileName)
|
||||
if (existScriptPaths.hasOwnProperty(fileName)) {
|
||||
savePath = existScriptPaths[fileName]
|
||||
}
|
||||
|
||||
writer.save(savePath);
|
||||
}
|
||||
|
||||
|
||||
export { genCSCode };
|
||||
@@ -0,0 +1,193 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runLanguageCustom = runLanguageCustom;
|
||||
exports.languageDestroy = languageDestroy;
|
||||
var FairyGUI = CS.FairyGUI;
|
||||
var FairyEditor = CS.FairyEditor;
|
||||
var UnityEngine = CS.UnityEngine;
|
||||
const App = FairyEditor.App;
|
||||
const LanguageSettings_1 = require("./LanguageSettings");
|
||||
class MembersLanguageCustomInspector extends FairyEditor.View.PluginInspector {
|
||||
setUseKey;
|
||||
btnRefresh;
|
||||
languageKey;
|
||||
constructor() {
|
||||
super();
|
||||
this.panel = FairyGUI.UIPackage.CreateObject("WhootCustomInspector", "LanguageComponent").asCom;
|
||||
this.setUseKey = this.panel.GetChild("SetUseKey").asButton;
|
||||
this.btnRefresh = this.panel.GetChild("btnRefresh").asButton;
|
||||
this.languageKey = this.panel.GetChild("languageKey");
|
||||
this.btnRefresh.onClick.Add(() => {
|
||||
let sels = App.activeDoc.inspectingTargets;
|
||||
let obj = sels.get_Item(0);
|
||||
LanguageSettings_1.default.updateItemTitle(obj, this.languageKey.title);
|
||||
});
|
||||
this.setUseKey.onChanged.Add(() => {
|
||||
this.updateData();
|
||||
});
|
||||
this.languageKey.onFocusOut.Add(() => {
|
||||
this.updateData();
|
||||
});
|
||||
this.updateAction = () => { return this.updateUI(); };
|
||||
}
|
||||
updateData() {
|
||||
// let activeDoc = App.activeDoc
|
||||
// let obj = activeDoc.inspectingTarget
|
||||
// genSetting.changeMemberSetting(activeDoc.packageItem.GetURL(), obj.id, this.setScriptType.selected, obj.name, this.scriptAnnotation.title)
|
||||
let sels = App.activeDoc.inspectingTargets;
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc;
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id;
|
||||
let useable = this.setUseKey.selected;
|
||||
let change = LanguageSettings_1.default.update(packageName, docUrl, objId, this.languageKey.title, useable);
|
||||
if (change) {
|
||||
//如果key变化了。
|
||||
LanguageSettings_1.default.updateItemTitle(obj, this.languageKey.title);
|
||||
}
|
||||
}
|
||||
updateUI() {
|
||||
let sels = App.activeDoc.inspectingTargets;
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc;
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id;
|
||||
let data = LanguageSettings_1.default.get(packageName, docUrl, objId);
|
||||
if (data != null) {
|
||||
this.setUseKey.selected = data.useable == 1;
|
||||
this.languageKey.title = data.key;
|
||||
}
|
||||
else {
|
||||
this.setUseKey.selected = false;
|
||||
this.languageKey.title = '';
|
||||
}
|
||||
return true; //if everything is ok, return false to hide the inspector
|
||||
}
|
||||
}
|
||||
class LanguageCustomInspector extends FairyEditor.View.PluginInspector {
|
||||
btnRefresh;
|
||||
constructor() {
|
||||
super();
|
||||
this.panel = FairyGUI.UIPackage.CreateObject("WhootCustomInspector", "LanguageComponentRoot").asCom;
|
||||
this.btnRefresh = this.panel.GetChild("btnRefresh").asButton;
|
||||
this.btnRefresh.onClick.Add(() => {
|
||||
this.updateAll();
|
||||
});
|
||||
this.updateAction = () => { return this.updateUI(); };
|
||||
}
|
||||
updateAll() {
|
||||
console.log("");
|
||||
let activeDoc = App.activeDoc;
|
||||
// activeDoc.content
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let count = activeDoc.content.numChildren;
|
||||
for (let index = 0; index < count; index++) {
|
||||
const obj = activeDoc.content.GetChildAt(index);
|
||||
if (obj == null)
|
||||
continue;
|
||||
let data = LanguageSettings_1.default.get(packageName, docUrl, obj.id);
|
||||
if (data != null && data.useable == 1) {
|
||||
LanguageSettings_1.default.updateItemTitle(obj, data.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
updateUI() {
|
||||
return true; //if everything is ok, return false to hide the inspector
|
||||
}
|
||||
}
|
||||
class LanguageImageCustomInspector extends FairyEditor.View.PluginInspector {
|
||||
setUseKey;
|
||||
ImageKey;
|
||||
constructor() {
|
||||
super();
|
||||
this.panel = FairyGUI.UIPackage.CreateObject("WhootCustomInspector", "LanguageImageComponent").asCom;
|
||||
this.setUseKey = this.panel.GetChild("SetUseKey").asButton;
|
||||
this.ImageKey = this.panel.GetChild("ImageKey");
|
||||
this.setUseKey.onChanged.Add(() => {
|
||||
this.updateData();
|
||||
});
|
||||
this.ImageKey.onFocusOut.Add(() => {
|
||||
this.updateData();
|
||||
});
|
||||
this.updateAction = () => { return this.updateUI(); };
|
||||
}
|
||||
updateData() {
|
||||
let sels = App.activeDoc.inspectingTargets;
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc;
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id;
|
||||
let useable = this.setUseKey.selected;
|
||||
let change = LanguageSettings_1.default.update(packageName, docUrl, objId, this.ImageKey.title, useable);
|
||||
if (change && useable) {
|
||||
obj.clearOnPublish = true;
|
||||
App.inspectorView.GetInspector("loader").UpdateUI();
|
||||
}
|
||||
}
|
||||
updateUI() {
|
||||
let sels = App.activeDoc.inspectingTargets;
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc;
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id;
|
||||
let data = LanguageSettings_1.default.get(packageName, docUrl, objId);
|
||||
if (data != null) {
|
||||
this.setUseKey.selected = data.useable == 1;
|
||||
this.ImageKey.title = data.key;
|
||||
if (data.useable == 1 && obj instanceof FairyEditor.FLoader) {
|
||||
if (!obj.clearOnPublish) {
|
||||
obj.clearOnPublish = true;
|
||||
App.activeDoc.SetModified(true);
|
||||
App.inspectorView.GetInspector("loader").UpdateUI();
|
||||
App.Alert("多语言图片装载器必须勾选发布后清除,避免将图片打进包。");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.setUseKey.selected = false;
|
||||
this.ImageKey.title = '';
|
||||
}
|
||||
return true; //if everything is ok, return false to hide the inspector
|
||||
}
|
||||
}
|
||||
function runLanguageCustom() {
|
||||
//Register a inspector
|
||||
App.inspectorView.AddInspector(() => new MembersLanguageCustomInspector(), "MembersLanguageCustomInspectorJS", "多语言设置");
|
||||
//Condition to show it
|
||||
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "Button", false, false);
|
||||
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "Label", false, false);
|
||||
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "text", false, false);
|
||||
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "richtext", false, false);
|
||||
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "inputtext", false, false);
|
||||
// App.libView.tooltips.
|
||||
console.log("多语言设置===");
|
||||
// //Register a inspector
|
||||
App.inspectorView.AddInspector(() => new LanguageCustomInspector(), "LanguageCustomInspectorJS", "多语言设置");
|
||||
//Condition to show it
|
||||
App.docFactory.ConnectInspector("LanguageCustomInspectorJS", "component", true, false);
|
||||
//Register a inspector
|
||||
App.inspectorView.AddInspector(() => new LanguageImageCustomInspector(), "LanguageImageCustomInspectorJS", "多语言图片设置");
|
||||
//Condition to show it
|
||||
App.docFactory.ConnectInspector("LanguageImageCustomInspectorJS", "loader", false, false);
|
||||
// App.workspaceSettings.
|
||||
let helpMenu = App.menu.GetSubMenu("help");
|
||||
helpMenu.AddItem("Whoot框架帮助", "WhootHelp", () => {
|
||||
console.log("点击菜单===");
|
||||
UnityEngine.Application.OpenURL("http://172.16.0.149/");
|
||||
});
|
||||
// let keys = App.preferences.hotkeys.Keys
|
||||
// let nmsl = App.preferences.hotkeys.get_Item("languagePath")
|
||||
// console.log("nmslnmsl=", nmsl)
|
||||
// "none", "graph", "image", "text", "richtext", "inputtext",
|
||||
// "movieclip", "swf", "loader", "group", "list", "loader3D",
|
||||
// "component", "Button", "Label", "Slider", "ProgressBar", "ScrollBar", "ComboBox", "mixed"
|
||||
}
|
||||
function languageDestroy() {
|
||||
let helpMenu = App.menu.GetSubMenu("help");
|
||||
helpMenu.RemoveItem("WhootHelp");
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
import FairyGUI = CS.FairyGUI;
|
||||
import FairyEditor = CS.FairyEditor;
|
||||
import UnityEngine = CS.UnityEngine;
|
||||
const App = FairyEditor.App;
|
||||
import languageSetting from './LanguageSettings'
|
||||
|
||||
|
||||
|
||||
class MembersLanguageCustomInspector extends FairyEditor.View.PluginInspector {
|
||||
private setUseKey: FairyGUI.GButton;
|
||||
private btnRefresh: FairyGUI.GButton;
|
||||
private languageKey: FairyEditor.Component.TextInput;
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
|
||||
this.panel = FairyGUI.UIPackage.CreateObject("WhootCustomInspector", "LanguageComponent").asCom;
|
||||
this.setUseKey = this.panel.GetChild("SetUseKey").asButton;
|
||||
this.btnRefresh = this.panel.GetChild("btnRefresh").asButton;
|
||||
this.languageKey = this.panel.GetChild("languageKey") as FairyEditor.Component.TextInput
|
||||
|
||||
this.btnRefresh.onClick.Add(() => {
|
||||
let sels = App.activeDoc.inspectingTargets
|
||||
let obj = sels.get_Item(0);
|
||||
languageSetting.updateItemTitle(obj, this.languageKey.title)
|
||||
})
|
||||
this.setUseKey.onChanged.Add(() => {
|
||||
this.updateData()
|
||||
});
|
||||
|
||||
this.languageKey.onFocusOut.Add(() => {
|
||||
this.updateData()
|
||||
})
|
||||
|
||||
|
||||
this.updateAction = () => { return this.updateUI(); };
|
||||
}
|
||||
|
||||
private updateData() {
|
||||
// let activeDoc = App.activeDoc
|
||||
// let obj = activeDoc.inspectingTarget
|
||||
// genSetting.changeMemberSetting(activeDoc.packageItem.GetURL(), obj.id, this.setScriptType.selected, obj.name, this.scriptAnnotation.title)
|
||||
let sels = App.activeDoc.inspectingTargets
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id
|
||||
|
||||
let useable = this.setUseKey.selected
|
||||
let change = languageSetting.update(packageName, docUrl, objId, this.languageKey.title, useable)
|
||||
if (change) {
|
||||
//如果key变化了。
|
||||
languageSetting.updateItemTitle(obj, this.languageKey.title)
|
||||
}
|
||||
}
|
||||
|
||||
private updateUI(): boolean {
|
||||
|
||||
let sels = App.activeDoc.inspectingTargets
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id
|
||||
|
||||
let data = languageSetting.get(packageName, docUrl, objId)
|
||||
if (data != null) {
|
||||
this.setUseKey.selected = data.useable == 1
|
||||
this.languageKey.title = data.key
|
||||
} else {
|
||||
this.setUseKey.selected = false
|
||||
this.languageKey.title = ''
|
||||
}
|
||||
|
||||
return true; //if everything is ok, return false to hide the inspector
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class LanguageCustomInspector extends FairyEditor.View.PluginInspector {
|
||||
|
||||
private btnRefresh: FairyGUI.GButton;
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
|
||||
this.panel = FairyGUI.UIPackage.CreateObject("WhootCustomInspector", "LanguageComponentRoot").asCom;
|
||||
this.btnRefresh = this.panel.GetChild("btnRefresh").asButton;
|
||||
|
||||
this.btnRefresh.onClick.Add(() => {
|
||||
this.updateAll()
|
||||
})
|
||||
|
||||
this.updateAction = () => { return this.updateUI(); };
|
||||
}
|
||||
|
||||
private updateAll() {
|
||||
console.log("")
|
||||
let activeDoc = App.activeDoc
|
||||
// activeDoc.content
|
||||
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
|
||||
let count = activeDoc.content.numChildren;
|
||||
for (let index = 0; index < count; index++) {
|
||||
const obj = activeDoc.content.GetChildAt(index)
|
||||
if (obj == null) continue
|
||||
let data = languageSetting.get(packageName, docUrl, obj.id)
|
||||
if (data != null && data.useable == 1) {
|
||||
languageSetting.updateItemTitle(obj, data.key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private updateUI(): boolean {
|
||||
return true; //if everything is ok, return false to hide the inspector
|
||||
}
|
||||
}
|
||||
|
||||
class LanguageImageCustomInspector extends FairyEditor.View.PluginInspector {
|
||||
private setUseKey: FairyGUI.GButton;
|
||||
private ImageKey: FairyEditor.Component.TextInput;
|
||||
|
||||
public constructor() {
|
||||
super();
|
||||
|
||||
this.panel = FairyGUI.UIPackage.CreateObject("WhootCustomInspector", "LanguageImageComponent").asCom;
|
||||
this.setUseKey = this.panel.GetChild("SetUseKey").asButton;
|
||||
this.ImageKey = this.panel.GetChild("ImageKey") as FairyEditor.Component.TextInput
|
||||
|
||||
this.setUseKey.onChanged.Add(() => {
|
||||
this.updateData()
|
||||
});
|
||||
|
||||
this.ImageKey.onFocusOut.Add(() => {
|
||||
this.updateData()
|
||||
})
|
||||
|
||||
|
||||
this.updateAction = () => { return this.updateUI(); };
|
||||
}
|
||||
|
||||
private updateData() {
|
||||
let sels = App.activeDoc.inspectingTargets
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id
|
||||
|
||||
let useable = this.setUseKey.selected
|
||||
let change = languageSetting.update(packageName, docUrl, objId, this.ImageKey.title, useable)
|
||||
if (change && useable) {
|
||||
(obj as FairyEditor.FLoader).clearOnPublish = true;
|
||||
App.inspectorView.GetInspector("loader").UpdateUI();
|
||||
}
|
||||
}
|
||||
|
||||
private updateUI(): boolean {
|
||||
let sels = App.activeDoc.inspectingTargets
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id
|
||||
|
||||
let data = languageSetting.get(packageName, docUrl, objId)
|
||||
if (data != null) {
|
||||
this.setUseKey.selected = data.useable == 1
|
||||
this.ImageKey.title = data.key
|
||||
if (data.useable == 1 && obj instanceof FairyEditor.FLoader) {
|
||||
if (!obj.clearOnPublish) {
|
||||
obj.clearOnPublish = true;
|
||||
App.activeDoc.SetModified(true);
|
||||
App.inspectorView.GetInspector("loader").UpdateUI();
|
||||
App.Alert("多语言图片装载器必须勾选发布后清除,避免将图片打进包。");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.setUseKey.selected = false
|
||||
this.ImageKey.title = ''
|
||||
}
|
||||
|
||||
return true; //if everything is ok, return false to hide the inspector
|
||||
}
|
||||
}
|
||||
|
||||
function runLanguageCustom() {
|
||||
//Register a inspector
|
||||
App.inspectorView.AddInspector(() => new MembersLanguageCustomInspector(), "MembersLanguageCustomInspectorJS", "多语言设置");
|
||||
//Condition to show it
|
||||
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "Button", false, false);
|
||||
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "Label", false, false);
|
||||
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "text", false, false);
|
||||
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "richtext", false, false);
|
||||
App.docFactory.ConnectInspector("MembersLanguageCustomInspectorJS", "inputtext", false, false);
|
||||
|
||||
|
||||
// App.libView.tooltips.
|
||||
console.log("多语言设置===")
|
||||
|
||||
// //Register a inspector
|
||||
App.inspectorView.AddInspector(() => new LanguageCustomInspector(), "LanguageCustomInspectorJS", "多语言设置");
|
||||
//Condition to show it
|
||||
App.docFactory.ConnectInspector("LanguageCustomInspectorJS", "component", true, false);
|
||||
|
||||
//Register a inspector
|
||||
App.inspectorView.AddInspector(() => new LanguageImageCustomInspector(), "LanguageImageCustomInspectorJS", "多语言图片设置");
|
||||
//Condition to show it
|
||||
App.docFactory.ConnectInspector("LanguageImageCustomInspectorJS", "loader", false, false);
|
||||
|
||||
// App.workspaceSettings.
|
||||
|
||||
let helpMenu = App.menu.GetSubMenu("help")
|
||||
helpMenu.AddItem("Whoot框架帮助", "WhootHelp", () => {
|
||||
console.log("点击菜单===")
|
||||
UnityEngine.Application.OpenURL("http://172.16.0.149/")
|
||||
})
|
||||
// let keys = App.preferences.hotkeys.Keys
|
||||
// let nmsl = App.preferences.hotkeys.get_Item("languagePath")
|
||||
// console.log("nmslnmsl=", nmsl)
|
||||
|
||||
// "none", "graph", "image", "text", "richtext", "inputtext",
|
||||
// "movieclip", "swf", "loader", "group", "list", "loader3D",
|
||||
// "component", "Button", "Label", "Slider", "ProgressBar", "ScrollBar", "ComboBox", "mixed"
|
||||
|
||||
}
|
||||
|
||||
function languageDestroy() {
|
||||
let helpMenu = App.menu.GetSubMenu("help")
|
||||
helpMenu.RemoveItem("WhootHelp")
|
||||
}
|
||||
|
||||
export { runLanguageCustom, languageDestroy };
|
||||
246
FGUIProject/plugins/nbc-puerts-plugins/LanguageSettings.js
Normal file
246
FGUIProject/plugins/nbc-puerts-plugins/LanguageSettings.js
Normal file
@@ -0,0 +1,246 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LanguageSettings = exports.LanguagePackageData = exports.LanguageComponentChildData = void 0;
|
||||
var FairyEditor = CS.FairyEditor;
|
||||
var System = CS.System;
|
||||
const App = FairyEditor.App;
|
||||
const File = System.IO.File;
|
||||
const Directory = System.IO.Directory;
|
||||
class LanguageComponentChildData {
|
||||
id;
|
||||
key;
|
||||
useable;
|
||||
}
|
||||
exports.LanguageComponentChildData = LanguageComponentChildData;
|
||||
// class LanguageComponentData {
|
||||
// url: string;
|
||||
// childs: object = {};
|
||||
// }
|
||||
class LanguagePackageData {
|
||||
name;
|
||||
components = {};
|
||||
}
|
||||
exports.LanguagePackageData = LanguagePackageData;
|
||||
class LanguageSettings {
|
||||
static instance;
|
||||
static getInstance() {
|
||||
if (!this.instance) {
|
||||
this.instance = new LanguageSettings();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
componentsSettingBasePath = "";
|
||||
_languageMap = new Map();
|
||||
_languageKeyValues = {};
|
||||
constructor() {
|
||||
this.init();
|
||||
// this._languageKeyValues['k1'] = "hahha1"
|
||||
// this._languageKeyValues['k2'] = "hahha2"
|
||||
// this._languageKeyValues['k3'] = "hahha3"
|
||||
//'CustomProperties'
|
||||
let path = App.project.settingsPath + "/CustomProperties.json";
|
||||
if (File.Exists(path)) {
|
||||
let jsonStr = File.ReadAllText(path);
|
||||
let settings = JSON.parse(jsonStr);
|
||||
if (settings.hasOwnProperty("languagePath")) {
|
||||
let languagePath = App.project.basePath + "/" + settings['languagePath'];
|
||||
console.log("多语言路径=", languagePath);
|
||||
if (File.Exists(languagePath)) {
|
||||
let languageStr = File.ReadAllText(languagePath);
|
||||
let datas = JSON.parse(languageStr);
|
||||
if (datas != null && datas.length > 0) {
|
||||
for (const data of datas) {
|
||||
this._languageKeyValues[data['key']] = data['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
init() {
|
||||
console.log("初始化加载多语言配置===");
|
||||
this.componentsSettingBasePath = App.project.settingsPath + "/whootLanguage";
|
||||
if (!System.IO.Directory.Exists(this.componentsSettingBasePath)) {
|
||||
console.log("whoot配置文件目录不存在,创建");
|
||||
System.IO.Directory.CreateDirectory(this.componentsSettingBasePath);
|
||||
}
|
||||
this.readAll();
|
||||
}
|
||||
/**
|
||||
* 清理无效的配置
|
||||
*/
|
||||
clearFailureConfig() {
|
||||
// App.d
|
||||
}
|
||||
getLanguage(key) {
|
||||
let value = this._languageKeyValues[key];
|
||||
if (value == null) {
|
||||
return key;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* 获取所有多语言包配置
|
||||
* @returns
|
||||
*/
|
||||
getAllPackage() {
|
||||
return this._languageMap;
|
||||
}
|
||||
/**
|
||||
* 获取一个多语言配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @param componentId
|
||||
*/
|
||||
get(packageName, docUrl, componentId) {
|
||||
let pack = this._languageMap.get(packageName);
|
||||
if (pack != null) {
|
||||
let doc = pack.components[docUrl];
|
||||
if (doc != null) {
|
||||
let child = doc[componentId];
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 获取一个组件的多语言配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @returns
|
||||
*/
|
||||
getDoc(packageName, docUrl) {
|
||||
let pack = this._languageMap.get(packageName);
|
||||
if (pack != null) {
|
||||
let doc = pack.components[docUrl];
|
||||
if (doc != null) {
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 获取一个包的多语言配置
|
||||
* @param packageName
|
||||
*/
|
||||
getPackage(packageName) {
|
||||
let pack = this._languageMap.get(packageName);
|
||||
if (pack) {
|
||||
return pack.components;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
/**
|
||||
* 更新一个多语言配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @param componentId
|
||||
* @param languageKey
|
||||
* @param useable 是否可用的
|
||||
*/
|
||||
update(packageName, docUrl, componentId, languageKey, useable = true) {
|
||||
let chang = false;
|
||||
let pack = this._languageMap.get(packageName);
|
||||
if (pack == null) {
|
||||
pack = new LanguagePackageData();
|
||||
pack.name = packageName;
|
||||
this._languageMap.set(packageName, pack);
|
||||
chang = true;
|
||||
}
|
||||
let doc = pack.components[docUrl];
|
||||
if (doc == null) {
|
||||
doc = {};
|
||||
pack.components[docUrl] = doc; //.set(docUrl, doc)
|
||||
chang = true;
|
||||
}
|
||||
let child = doc[componentId];
|
||||
if (child == null) {
|
||||
child = new LanguageComponentChildData();
|
||||
child.id = componentId;
|
||||
doc[componentId] = child; //.set(componentId, child)
|
||||
}
|
||||
let u = useable ? 1 : 0;
|
||||
if (child.key != languageKey || child.useable != u) {
|
||||
child.key = languageKey;
|
||||
child.useable = u;
|
||||
chang = true;
|
||||
}
|
||||
if (chang) {
|
||||
//有数据变化,变更文件
|
||||
this.saveFile(packageName);
|
||||
}
|
||||
return chang;
|
||||
}
|
||||
//region 工具方法
|
||||
updateItemTitle(obj, key) {
|
||||
// console.log("obj类型=", obj.GetType())
|
||||
if (obj instanceof FairyEditor.FTextInput) {
|
||||
let textInput = obj;
|
||||
textInput.promptText = this.getLanguage(key);
|
||||
}
|
||||
else if (obj instanceof FairyEditor.FButton) {
|
||||
let button = obj;
|
||||
button.title = this.getLanguage(key);
|
||||
}
|
||||
else if (obj instanceof FairyEditor.FLabel) {
|
||||
let lable = obj;
|
||||
lable.title = this.getLanguage(key);
|
||||
}
|
||||
else {
|
||||
obj.text = this.getLanguage(key);
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
//region file
|
||||
//获取所有的文件的路径
|
||||
getAllDirector(path, list) {
|
||||
console.log("开始读取所有配置=", path);
|
||||
let files = Directory.GetFiles(path, "*.json");
|
||||
for (let f = 0; f < files.Length; f++) {
|
||||
list.push(files.get_Item(f));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 读取全部
|
||||
*/
|
||||
readAll() {
|
||||
try {
|
||||
let list = [];
|
||||
this.getAllDirector(this.componentsSettingBasePath, list);
|
||||
this._languageMap.clear();
|
||||
console.log("初始化所有多语言配置");
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
let p = list[index];
|
||||
let jsonStr = File.ReadAllText(p);
|
||||
let data = JSON.parse(jsonStr);
|
||||
this._languageMap.set(data.name, data);
|
||||
}
|
||||
}
|
||||
catch {
|
||||
console.error("读取多语言配置文件失败");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 将所有配置保存成配置文件
|
||||
*/
|
||||
saveAllFile() {
|
||||
let keys = this._languageMap.keys();
|
||||
for (const key of keys) {
|
||||
this.saveFile(key);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 保存json文件
|
||||
* @param packageName
|
||||
*/
|
||||
saveFile(packageName) {
|
||||
let path = this.componentsSettingBasePath + "/" + packageName + ".json";
|
||||
let data = this._languageMap.get(packageName);
|
||||
if (data != null) {
|
||||
let jsonStr = JSON.stringify(data);
|
||||
File.WriteAllText(path, jsonStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.LanguageSettings = LanguageSettings;
|
||||
exports.default = LanguageSettings.getInstance();
|
||||
266
FGUIProject/plugins/nbc-puerts-plugins/LanguageSettings.ts
Normal file
266
FGUIProject/plugins/nbc-puerts-plugins/LanguageSettings.ts
Normal file
@@ -0,0 +1,266 @@
|
||||
import FairyGUI = CS.FairyGUI;
|
||||
import FairyEditor = CS.FairyEditor;
|
||||
import System = CS.System;
|
||||
const App = FairyEditor.App;
|
||||
const File = System.IO.File;
|
||||
const Directory = System.IO.Directory;
|
||||
|
||||
export class LanguageComponentChildData {
|
||||
id: string;
|
||||
key: string;
|
||||
useable: number;
|
||||
}
|
||||
|
||||
// class LanguageComponentData {
|
||||
// url: string;
|
||||
// childs: object = {};
|
||||
// }
|
||||
|
||||
export class LanguagePackageData {
|
||||
name: string;
|
||||
components: object = {};
|
||||
}
|
||||
|
||||
export class LanguageSettings {
|
||||
private static instance: LanguageSettings;
|
||||
static getInstance() {
|
||||
if (!this.instance) {
|
||||
this.instance = new LanguageSettings();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
|
||||
public componentsSettingBasePath: string = "";
|
||||
private readonly _languageMap: Map<string, LanguagePackageData> = new Map<string, LanguagePackageData>();
|
||||
private readonly _languageKeyValues: object = {};
|
||||
|
||||
constructor() {
|
||||
this.init()
|
||||
// this._languageKeyValues['k1'] = "hahha1"
|
||||
// this._languageKeyValues['k2'] = "hahha2"
|
||||
// this._languageKeyValues['k3'] = "hahha3"
|
||||
//'CustomProperties'
|
||||
let path = App.project.settingsPath + "/CustomProperties.json"
|
||||
if (File.Exists(path)) {
|
||||
let jsonStr = File.ReadAllText(path);
|
||||
let settings = JSON.parse(jsonStr) as object
|
||||
if (settings.hasOwnProperty("languagePath")) {
|
||||
let languagePath = App.project.basePath + "/" + settings['languagePath']
|
||||
console.log("多语言路径=", languagePath)
|
||||
if (File.Exists(languagePath)) {
|
||||
let languageStr = File.ReadAllText(languagePath);
|
||||
let datas = JSON.parse(languageStr) as Array<object>
|
||||
if (datas != null && datas.length > 0) {
|
||||
for (const data of datas) {
|
||||
this._languageKeyValues[data['key']] = data['value']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private init() {
|
||||
console.log("初始化加载多语言配置===")
|
||||
|
||||
this.componentsSettingBasePath = App.project.settingsPath + "/whootLanguage"
|
||||
if (!System.IO.Directory.Exists(this.componentsSettingBasePath)) {
|
||||
console.log("whoot配置文件目录不存在,创建")
|
||||
System.IO.Directory.CreateDirectory(this.componentsSettingBasePath)
|
||||
}
|
||||
this.readAll()
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理无效的配置
|
||||
*/
|
||||
clearFailureConfig() {
|
||||
// App.d
|
||||
}
|
||||
|
||||
getLanguage(key: string): string {
|
||||
let value = this._languageKeyValues[key]
|
||||
if (value == null) {
|
||||
return key
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有多语言包配置
|
||||
* @returns
|
||||
*/
|
||||
getAllPackage(): Map<string, LanguagePackageData> {
|
||||
return this._languageMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个多语言配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @param componentId
|
||||
*/
|
||||
get(packageName, docUrl, componentId): LanguageComponentChildData {
|
||||
let pack = this._languageMap.get(packageName)
|
||||
if (pack != null) {
|
||||
let doc = pack.components[docUrl]
|
||||
if (doc != null) {
|
||||
let child = doc[componentId]
|
||||
return child as LanguageComponentChildData
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个组件的多语言配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @returns
|
||||
*/
|
||||
getDoc(packageName, docUrl): object {
|
||||
let pack = this._languageMap.get(packageName)
|
||||
if (pack != null) {
|
||||
let doc = pack.components[docUrl]
|
||||
if (doc != null) {
|
||||
return doc as object
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个包的多语言配置
|
||||
* @param packageName
|
||||
*/
|
||||
getPackage(packageName): object {
|
||||
let pack = this._languageMap.get(packageName)
|
||||
if (pack) {
|
||||
return pack.components;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新一个多语言配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @param componentId
|
||||
* @param languageKey
|
||||
* @param useable 是否可用的
|
||||
*/
|
||||
update(packageName, docUrl, componentId, languageKey, useable: boolean = true): boolean {
|
||||
let chang = false
|
||||
let pack = this._languageMap.get(packageName)
|
||||
if (pack == null) {
|
||||
pack = new LanguagePackageData()
|
||||
pack.name = packageName
|
||||
this._languageMap.set(packageName, pack)
|
||||
chang = true
|
||||
}
|
||||
let doc = pack.components[docUrl]
|
||||
if (doc == null) {
|
||||
doc = {};
|
||||
pack.components[docUrl] = doc;//.set(docUrl, doc)
|
||||
chang = true
|
||||
}
|
||||
let child = doc[componentId]
|
||||
if (child == null) {
|
||||
child = new LanguageComponentChildData();
|
||||
child.id = componentId
|
||||
doc[componentId] = child//.set(componentId, child)
|
||||
}
|
||||
let u = useable ? 1 : 0
|
||||
if (child.key != languageKey || child.useable != u) {
|
||||
child.key = languageKey
|
||||
child.useable = u
|
||||
chang = true
|
||||
}
|
||||
|
||||
if (chang) {
|
||||
//有数据变化,变更文件
|
||||
this.saveFile(packageName)
|
||||
}
|
||||
return chang
|
||||
}
|
||||
|
||||
|
||||
//region 工具方法
|
||||
updateItemTitle(obj: FairyEditor.FObject, key: string) {
|
||||
// console.log("obj类型=", obj.GetType())
|
||||
if (obj instanceof FairyEditor.FTextInput) {
|
||||
let textInput = obj as FairyEditor.FTextInput
|
||||
textInput.promptText = this.getLanguage(key)
|
||||
} else if (obj instanceof FairyEditor.FButton) {
|
||||
let button = obj as FairyEditor.FButton
|
||||
button.title = this.getLanguage(key)
|
||||
} else if (obj instanceof FairyEditor.FLabel) {
|
||||
let lable = obj as FairyEditor.FLabel
|
||||
lable.title = this.getLanguage(key)
|
||||
} else {
|
||||
obj.text = this.getLanguage(key)
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
|
||||
//region file
|
||||
//获取所有的文件的路径
|
||||
private getAllDirector(path: string, list: Array<string>) {
|
||||
console.log("开始读取所有配置=", path)
|
||||
let files = Directory.GetFiles(path, "*.json")
|
||||
for (let f = 0; f < files.Length; f++) {
|
||||
list.push(files.get_Item(f))
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 读取全部
|
||||
*/
|
||||
private readAll() {
|
||||
try {
|
||||
let list: Array<string> = []
|
||||
this.getAllDirector(this.componentsSettingBasePath, list)
|
||||
this._languageMap.clear()
|
||||
console.log("初始化所有多语言配置")
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
let p = list[index];
|
||||
let jsonStr = File.ReadAllText(p);
|
||||
let data: LanguagePackageData = JSON.parse(jsonStr);
|
||||
this._languageMap.set(data.name, data)
|
||||
}
|
||||
} catch {
|
||||
console.error("读取多语言配置文件失败")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将所有配置保存成配置文件
|
||||
*/
|
||||
private saveAllFile() {
|
||||
let keys = this._languageMap.keys()
|
||||
for (const key of keys) {
|
||||
this.saveFile(key)
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 保存json文件
|
||||
* @param packageName
|
||||
*/
|
||||
private saveFile(packageName: string) {
|
||||
let path = this.componentsSettingBasePath + "/" + packageName + ".json";
|
||||
let data = this._languageMap.get(packageName)
|
||||
if (data != null) {
|
||||
let jsonStr = JSON.stringify(data);
|
||||
File.WriteAllText(path, jsonStr)
|
||||
}
|
||||
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
|
||||
export default LanguageSettings.getInstance();
|
||||
Binary file not shown.
21749
FGUIProject/plugins/nbc-puerts-plugins/editor.d.ts
vendored
Normal file
21749
FGUIProject/plugins/nbc-puerts-plugins/editor.d.ts
vendored
Normal file
File diff suppressed because one or more lines are too long
35
FGUIProject/plugins/nbc-puerts-plugins/main.js
Normal file
35
FGUIProject/plugins/nbc-puerts-plugins/main.js
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
// //FYI: https://github.com/Tencent/puerts/blob/master/doc/unity/manual.md
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.onPublish = onPublish;
|
||||
exports.onDestroy = onDestroy;
|
||||
var FairyEditor = CS.FairyEditor;
|
||||
var System = CS.System;
|
||||
// import { genCode } from './GenCode_CSharp';
|
||||
const GenCode_CSharp_1 = require("./GenCode_CSharp");
|
||||
const GenCodeCustomInspector_1 = require("./GenCodeCustomInspector");
|
||||
const LanguageCustomInspector_1 = require("./LanguageCustomInspector");
|
||||
const GenCodeSettings_1 = require("./GenCodeSettings");
|
||||
const App = FairyEditor.App;
|
||||
const File = System.IO.File;
|
||||
// console.log(App.project.settingsPath+"/Adaptation.json");
|
||||
// console.log(System.IO.File.ReadAllText(App.project.settingsPath+"/Adaptation.json"))
|
||||
(0, GenCodeCustomInspector_1.runGenCodeCustom)();
|
||||
(0, LanguageCustomInspector_1.runLanguageCustom)();
|
||||
function onPublish(handler) {
|
||||
if (!handler.genCode)
|
||||
return;
|
||||
handler.genCode = false; //prevent default output
|
||||
console.log('Handling gen code in plugin 1');
|
||||
(0, GenCode_CSharp_1.genCSCode)(handler);
|
||||
}
|
||||
var callBack = context => {
|
||||
GenCodeSettings_1.default.packageItemChange(context);
|
||||
};
|
||||
function onDestroy() {
|
||||
(0, LanguageCustomInspector_1.languageDestroy)();
|
||||
//do cleanup here
|
||||
//App.project.
|
||||
//console.error("坑爹的ts没法注销事件,刷新后请重启fgui")
|
||||
//App.Off(FairyEditor.EditorEvents.PackageItemChanged, callBack)
|
||||
}
|
||||
46
FGUIProject/plugins/nbc-puerts-plugins/main.ts
Normal file
46
FGUIProject/plugins/nbc-puerts-plugins/main.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
// //FYI: https://github.com/Tencent/puerts/blob/master/doc/unity/manual.md
|
||||
|
||||
import FairyGUI = CS.FairyGUI;
|
||||
import FairyEditor = CS.FairyEditor;
|
||||
import System = CS.System;
|
||||
// import { genCode } from './GenCode_CSharp';
|
||||
import { genCSCode } from './GenCode_CSharp';
|
||||
import { runGenCodeCustom } from './GenCodeCustomInspector';
|
||||
import { runLanguageCustom, languageDestroy } from './LanguageCustomInspector';
|
||||
import genSetting from './GenCodeSettings'
|
||||
const App = FairyEditor.App;
|
||||
const File = System.IO.File;
|
||||
// console.log(App.project.settingsPath+"/Adaptation.json");
|
||||
// console.log(System.IO.File.ReadAllText(App.project.settingsPath+"/Adaptation.json"))
|
||||
|
||||
runGenCodeCustom()
|
||||
runLanguageCustom()
|
||||
|
||||
function onPublish(handler: FairyEditor.PublishHandler) {
|
||||
if (!handler.genCode) return;
|
||||
handler.genCode = false; //prevent default output
|
||||
|
||||
console.log('Handling gen code in plugin 1');
|
||||
|
||||
genCSCode(handler);
|
||||
}
|
||||
|
||||
var callBack = context => {
|
||||
genSetting.packageItemChange(context);
|
||||
}
|
||||
|
||||
function onDestroy() {
|
||||
languageDestroy()
|
||||
//do cleanup here
|
||||
//App.project.
|
||||
//console.error("坑爹的ts没法注销事件,刷新后请重启fgui")
|
||||
//App.Off(FairyEditor.EditorEvents.PackageItemChanged, callBack)
|
||||
}
|
||||
//App.On(FairyEditor.EditorEvents.PackageItemChanged, callBack)
|
||||
//console.log("packages count=", FairyEditor)
|
||||
|
||||
// for (let index = 0; index < App.project.allPackages.Count; index++) {
|
||||
// let pkg: FairyEditor.FPackage = App.project.allPackages[index];
|
||||
// console.log("package.items=", pkg)
|
||||
// }
|
||||
export { onPublish, onDestroy };
|
||||
16
FGUIProject/plugins/nbc-puerts-plugins/package.json
Normal file
16
FGUIProject/plugins/nbc-puerts-plugins/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "NBCPlugins",
|
||||
"displayName": "NBC unity 支持",
|
||||
"description": "NBC前端框架FGUI扩展插件",
|
||||
"version": "1.0",
|
||||
"author": {
|
||||
"name": "BobSong",
|
||||
"email": "605277374@qq.com",
|
||||
"url": "https://bobsong.cn"
|
||||
},
|
||||
"icon": "",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "tsc -w"
|
||||
}
|
||||
}
|
||||
39
FGUIProject/plugins/nbc-puerts-plugins/puerts.d.ts
vendored
Normal file
39
FGUIProject/plugins/nbc-puerts-plugins/puerts.d.ts
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
declare enum __Puerts_CSharpEnum { }
|
||||
|
||||
declare namespace puer {
|
||||
function $ref<T>(x?: T): CS.$Ref<T>;
|
||||
|
||||
function $unref<T>(x: CS.$Ref<T>): T;
|
||||
|
||||
function $set<T>(x: CS.$Ref<T>, val: T): void;
|
||||
|
||||
function $promise<T>(x: CS.$Task<T>): Promise<T>;
|
||||
|
||||
function $generic<T extends new (...args: any[]) => any>(genericType: T, ...genericArguments: (typeof __Puerts_CSharpEnum | (new (...args: any[]) => any))[]): T;
|
||||
|
||||
function $genericMethod(genericType: new (...args: any[]) => any, methodName: string, ...genericArguments: (typeof __Puerts_CSharpEnum | (new (...args: any[]) => any))[]): (...args: any[]) => any;
|
||||
|
||||
function $typeof(x: new (...args: any[]) => any): CS.System.Type;
|
||||
|
||||
function $extension(c: Function, e: Function): void;
|
||||
|
||||
function on(eventType: string, listener: Function, prepend?: boolean): void;
|
||||
|
||||
function off(eventType: string, listener: Function): void;
|
||||
|
||||
function emit(eventType: string, ...args: any[]): boolean;
|
||||
|
||||
function loadFile(name: string): { content: string, debugpath: string };
|
||||
|
||||
function evalScript(name: string): void;
|
||||
|
||||
function require(name: string): any;
|
||||
}
|
||||
|
||||
import puerts = puer;
|
||||
|
||||
// compat 1.4- version
|
||||
// 兼容1.4-版本,不需要可以注释掉
|
||||
declare module "puerts" {
|
||||
export = puerts;
|
||||
}
|
||||
13
FGUIProject/plugins/nbc-puerts-plugins/tsconfig.json
Normal file
13
FGUIProject/plugins/nbc-puerts-plugins/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "commonjs",
|
||||
"sourceMap": false,
|
||||
"typeRoots": [
|
||||
"./node_modules/@types"
|
||||
],
|
||||
"outDir": "./"
|
||||
},
|
||||
"include": ["./*"],
|
||||
"exclude": ["./node_modules/**/*"]
|
||||
}
|
||||
28
FGUIProject/plugins/whoot-tween/CodeWriter.d.ts
vendored
Normal file
28
FGUIProject/plugins/whoot-tween/CodeWriter.d.ts
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
interface ICodeWriterConfig {
|
||||
blockStart?: string;
|
||||
blockEnd?: string;
|
||||
blockFromNewLine?: boolean;
|
||||
usingTabs?: boolean;
|
||||
endOfLine?: string;
|
||||
fileMark?: string;
|
||||
}
|
||||
export default class CodeWriter {
|
||||
private blockStart;
|
||||
private blockEnd;
|
||||
private blockFromNewLine;
|
||||
private indentStr;
|
||||
private endOfLine;
|
||||
private lines;
|
||||
private indent;
|
||||
private fileMark;
|
||||
constructor(config?: ICodeWriterConfig);
|
||||
writeMark(): void;
|
||||
writeln(fmt?: string, ...args: any[]): CodeWriter;
|
||||
startBlock(): CodeWriter;
|
||||
endBlock(): CodeWriter;
|
||||
incIndent(): CodeWriter;
|
||||
decIndent(): CodeWriter;
|
||||
reset(): void;
|
||||
toString(): string;
|
||||
save(filePath: string): void;
|
||||
}
|
||||
BIN
FGUIProject/plugins/whoot-tween/TweenAttributer_fui.bytes
Normal file
BIN
FGUIProject/plugins/whoot-tween/TweenAttributer_fui.bytes
Normal file
Binary file not shown.
460
FGUIProject/plugins/whoot-tween/TweenCoustomInspector.js
Normal file
460
FGUIProject/plugins/whoot-tween/TweenCoustomInspector.js
Normal file
@@ -0,0 +1,460 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CustomAttributer = void 0;
|
||||
const csharp_1 = require("csharp");
|
||||
const puerts_1 = require("puerts");
|
||||
const index_1 = require("./index");
|
||||
const App = csharp_1.FairyEditor.App;
|
||||
// 动效设置(参考 LanguageSettings 的存储方式)
|
||||
const TweenSettings_1 = require("./TweenSettings");
|
||||
class CustomAttributer extends csharp_1.FairyEditor.View.PluginInspector {
|
||||
list;
|
||||
components = [];
|
||||
pattern = "*";
|
||||
parent = false;
|
||||
textMode;
|
||||
mode = index_1.EMode.WRITE;
|
||||
modeCtr;
|
||||
// private btn_save: FairyGUI.GButton;
|
||||
// private btn_reset: FairyGUI.GButton;
|
||||
customData = "";
|
||||
customDataObj = {};
|
||||
constructor(data) {
|
||||
super();
|
||||
this.panel = csharp_1.FairyGUI.UIPackage.CreateObject("TweenAttributer", "Main").asCom;
|
||||
// this.panel.GetChild("btn_save").asButton.visible = false;
|
||||
// this.panel.GetChild("btn_reset").asButton.visible = false;
|
||||
// this.panel.GetChild("btn_copy").asButton.visible = false;
|
||||
let { components, mode, pattern, parent } = data;
|
||||
this.components = components;
|
||||
this.pattern = pattern;
|
||||
this.parent = parent;
|
||||
this.list = this.panel.GetChild("list_components").asList;
|
||||
//this.textMode = this.panel.GetChild("text_mode").asTextField;
|
||||
this.mode = mode || index_1.EMode.WRITE; // todo
|
||||
if (this.components.length > 0) {
|
||||
this.list.numItems = 0;
|
||||
}
|
||||
this.modeCtr = this.panel.GetController("op");
|
||||
// this.btn_save = this.panel.GetChild("btn_save").asButton;
|
||||
// this.btn_save.onClick.Add(() => {
|
||||
// this.setCustomData();
|
||||
// })
|
||||
// this.btn_reset = this.panel.GetChild("btn_reset").asButton;
|
||||
// this.btn_reset.onClick.Add(() => {
|
||||
// this.showList(true);
|
||||
// })
|
||||
this.updateAction = () => { return this.updateUI(); };
|
||||
}
|
||||
lastSelectedComponent = "";
|
||||
lastData = "";
|
||||
updateUI() {
|
||||
let curDoc = App.activeDoc;
|
||||
let { inspectingTarget } = curDoc;
|
||||
let id = this.parent ? curDoc.docURL : inspectingTarget.id;
|
||||
// 实时获取自定义数据
|
||||
let propName = this.parent ? "remark" : "customData";
|
||||
this.customData = inspectingTarget.GetProperty(propName);
|
||||
try {
|
||||
this.customDataObj = JSON.parse(this.customData) || {};
|
||||
}
|
||||
catch (e) {
|
||||
// console.log("自定义数据异常或没有发现自定义数据,无法渲染列表");
|
||||
this.customDataObj = {};
|
||||
}
|
||||
// 根据匹配规则验证是否显示inspector
|
||||
// 正则 & 字符串 通配符
|
||||
let name = this.parent ? curDoc.displayTitle : inspectingTarget.name;
|
||||
let pattern = isMatch(name, this.pattern);
|
||||
if ((pattern && this.lastSelectedComponent != id) || this.customData !== this.lastData) { // 判断是否满足条件的组件以及是上一次选中的组件或者数据是否被修改
|
||||
this.showList();
|
||||
}
|
||||
this.lastData = this.customData;
|
||||
this.lastSelectedComponent = id;
|
||||
return pattern;
|
||||
}
|
||||
showList(reset = false) {
|
||||
this.list.numItems = 0;
|
||||
// todo
|
||||
// if (this.mode == EMode.WRITE) {
|
||||
// this.textMode.SetVar("mode", "设置").FlushVars();
|
||||
// this.modeCtr.SetSelectedPage("write");
|
||||
// } else {
|
||||
// this.textMode.SetVar("mode", "读取").FlushVars();
|
||||
// this.modeCtr.SetSelectedPage("read");
|
||||
// }
|
||||
// 根据自定义属性和配置文件混合比较【以自定义属性为主】渲染列表数据
|
||||
for (let item of this.components) {
|
||||
let { type, name, id, key } = item;
|
||||
let com = getComponent(type);
|
||||
if (!key) {
|
||||
console.log("未定义唯一keyID:", id);
|
||||
return;
|
||||
}
|
||||
if (!com) {
|
||||
console.log("发现未定义扩展组件,ID:", id);
|
||||
}
|
||||
com.title = name || key;
|
||||
const component = com.GetChild("component");
|
||||
com.name = key;
|
||||
this.renderItem(component, item, reset);
|
||||
// 监听组件变更并保存到 json(参考 LanguageCustomInspector 的做法)
|
||||
this.bindPersistEvents(component, item);
|
||||
this.list.AddChild(com);
|
||||
}
|
||||
this.list.ResizeToFit();
|
||||
// 更新关联关系
|
||||
for (let item of this.components) {
|
||||
let { associate, key } = item;
|
||||
// 找到关联组件
|
||||
let associateCom, curCom;
|
||||
for (let i = 0; i < this.list.numChildren; i++) {
|
||||
let com = this.list.GetChildAt(i);
|
||||
if (com.name == associate) {
|
||||
associateCom = com;
|
||||
}
|
||||
if (com.name == key) {
|
||||
curCom = com;
|
||||
}
|
||||
}
|
||||
if (associateCom && !associateCom.GetChild("component").selected && curCom) {
|
||||
this.list.RemoveChild(curCom);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 给渲染出来的控件绑定事件:
|
||||
* -(已暂时停用)更新自定义属性(SetProperty)
|
||||
* - 将动效设置保存到项目设置目录下的 json(whootTween/<package>.json)
|
||||
*/
|
||||
bindPersistEvents(component, item) {
|
||||
const persist = () => {
|
||||
// 暂时不写回到自定义数据,仅保存到 json
|
||||
// this.setCustomData();
|
||||
// 将与动效相关的设置保存到 json
|
||||
this.trySaveTweenSetting(item, component);
|
||||
};
|
||||
// 根据控件类型选择合适的触发时机
|
||||
if (component instanceof csharp_1.FairyGUI.GComboBox) {
|
||||
component.onChanged.Add(persist);
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyEditor.Component.NumericInput) {
|
||||
// 数字输入使用失焦触发
|
||||
component.onFocusOut.Add(persist);
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyGUI.GSlider) {
|
||||
component.onChanged.Add(persist);
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyGUI.GButton) { // SWITCH / RADIOBOX
|
||||
component.onChanged.Add(persist);
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyEditor.Component.ColorInput) {
|
||||
component.onChanged.Add(persist);
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyGUI.GLabel) { // 文本输入类:失焦时保存
|
||||
component.onFocusOut.Add(persist);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 将与动效相关的设置保存到 json 文件。
|
||||
* 规则:
|
||||
* - 仅对下拉框(ComboBox)做持久化(其 value 代表动效 key)
|
||||
* - 当选中值为 "null" 视为未启用(useable=false),否则为启用
|
||||
*/
|
||||
trySaveTweenSetting(item, component) {
|
||||
try {
|
||||
if (!(component instanceof csharp_1.FairyGUI.GComboBox))
|
||||
return;
|
||||
// 读取当前对象与文档信息
|
||||
let sels = App.activeDoc.inspectingTargets;
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc;
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id;
|
||||
// 父级组件通常没有有效的 id,这里为父级使用文档级占位 id
|
||||
if ((!objId || objId === "") && this.parent) {
|
||||
objId = "__root__";
|
||||
}
|
||||
// 当前选择的动效 key
|
||||
const selectedIndex = component.selectedIndex;
|
||||
const selectedValue = component.values?.get_Item(selectedIndex);
|
||||
// 条件:无(值为"null")或组件ID为空(非父级场景),不记录
|
||||
if ((!objId || objId === "") && !this.parent)
|
||||
return;
|
||||
if (selectedValue == null)
|
||||
return;
|
||||
if (selectedValue === "null") {
|
||||
// 选择“无”时,删除已存在的记录
|
||||
TweenSettings_1.default.remove(packageName, docUrl, objId);
|
||||
return;
|
||||
}
|
||||
const useable = true; // 只有有效选择才记录,直接标记为可用
|
||||
// 保存到 whootTween/<package>.json
|
||||
TweenSettings_1.default.update(packageName, docUrl, objId, selectedValue, useable);
|
||||
// 保存后做一次清理:把已删除的组件从 json 中移除
|
||||
this.cleanupDeletedComponents(packageName, docUrl);
|
||||
}
|
||||
catch (e) {
|
||||
console.error("保存动效设置到 json 失败:", e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 收集当前文档中仍然存在的组件ID(递归)并触发清理
|
||||
*/
|
||||
cleanupDeletedComponents(packageName, docUrl) {
|
||||
try {
|
||||
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 activeDoc = App.activeDoc;
|
||||
if (activeDoc && activeDoc.content) {
|
||||
collect(activeDoc.content);
|
||||
}
|
||||
// 仅当有 id 列表时尝试清理(保留 __root__)
|
||||
TweenSettings_1.default.cleanupDoc(packageName, docUrl, ids);
|
||||
}
|
||||
catch (err) {
|
||||
console.error('清理已删除组件记录失败', err);
|
||||
}
|
||||
}
|
||||
renderItem(component, item, reset) {
|
||||
let { value, key } = item;
|
||||
if (!reset) {
|
||||
let defaultVal = this.getValueByName(key);
|
||||
value = defaultVal != undefined ? defaultVal : value;
|
||||
}
|
||||
// 下拉框
|
||||
if (component instanceof csharp_1.FairyGUI.GComboBox && item.type == index_1.EComponent.COMBOBOX) {
|
||||
let data = item.data;
|
||||
let valueArr = csharp_1.System.Array.CreateInstance((0, puerts_1.$typeof)(csharp_1.System.String), data.values.length);
|
||||
for (let i = 0; i < data.values.length; i++) {
|
||||
let v = data.values[i];
|
||||
valueArr.set_Item(i, v);
|
||||
}
|
||||
let itemArr = csharp_1.System.Array.CreateInstance((0, puerts_1.$typeof)(csharp_1.System.String), data.items.length);
|
||||
for (let i = 0; i < data.items.length; i++) {
|
||||
let v = data.items[i];
|
||||
itemArr.set_Item(i, v);
|
||||
}
|
||||
component.items = itemArr;
|
||||
component.values = valueArr;
|
||||
// 优先使用外部配置(TweenSettings)进行回填
|
||||
const extVal = this.getExternalTweenKey();
|
||||
if (extVal && data.values.indexOf(extVal) >= 0) {
|
||||
component.value = extVal;
|
||||
}
|
||||
else {
|
||||
// 兼容:customData 可能保存的是值字符串或索引
|
||||
if (typeof value === 'string' && data.values.indexOf(value) >= 0) {
|
||||
component.value = value;
|
||||
}
|
||||
else {
|
||||
const idx = Number(value);
|
||||
const finalIdx = isNaN(idx) ? 0 : idx;
|
||||
component.value = data.values[finalIdx] ?? data.values[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyGUI.GLabel &&
|
||||
(item.type == index_1.EComponent.TEXTINPUT ||
|
||||
item.type == index_1.EComponent.TEXTAREA ||
|
||||
item.type == index_1.EComponent.RESOURCEINPUT)) { // 文本输入框
|
||||
component.title = value + "" || "";
|
||||
}
|
||||
else if (item.type == index_1.EComponent.COLORINPUT && component instanceof csharp_1.FairyEditor.Component.ColorInput) { // 颜色输入框
|
||||
let colorValue = value + "" || "#000000";
|
||||
component.colorValue = csharp_1.FairyEditor.ColorUtil.FromHexString(colorValue);
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyGUI.GSlider && item.type == index_1.EComponent.SLIDER) { // 滑动块
|
||||
let data = item.data;
|
||||
component.min = +data.min || 0;
|
||||
component.max = +data.max || 100;
|
||||
component.value = +value || 0;
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyEditor.Component.NumericInput && item.type == index_1.EComponent.NUMBERINPUT) { // 数字输入框
|
||||
let data = item.data;
|
||||
component.min = +data.min || 0;
|
||||
component.max = +data.max || 100;
|
||||
component.step = +data.step || 0;
|
||||
component.value = +value || 0;
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyGUI.GButton && item.type == index_1.EComponent.SWITCH) { // 切换器
|
||||
component.selected = Boolean(value);
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyGUI.GButton && item.type == index_1.EComponent.RADIOBOX) { // 单选框
|
||||
let data = item.data;
|
||||
component.GetChildAt(0).text = data.items[0];
|
||||
component.GetChildAt(1).text = data.items[1];
|
||||
component.selected = Boolean(value);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 读取当前对象在 TweenSettings 中的外部配置 key
|
||||
*/
|
||||
getExternalTweenKey() {
|
||||
try {
|
||||
let sels = App.activeDoc.inspectingTargets;
|
||||
// puerts 映射的 IList$1 没有 Count 属性,这里直接尝试取第 0 项
|
||||
if (!sels)
|
||||
return null;
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc;
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id;
|
||||
if ((!objId || objId === "") && this.parent) {
|
||||
objId = "__root__";
|
||||
}
|
||||
let data = TweenSettings_1.default.get(packageName, docUrl, objId);
|
||||
if (data && data.useable == 1 && data.key) {
|
||||
return data.key;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('读取 TweenSettings 外部配置失败', e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
getListItemVal() {
|
||||
for (let i = 0; i < this.list.numChildren; i++) {
|
||||
let item = this.list.GetChildAt(i);
|
||||
let component = item.GetChild("component");
|
||||
let value = component.title;
|
||||
if (component instanceof csharp_1.FairyEditor.Component.ColorInput) {
|
||||
value = csharp_1.FairyEditor.ColorUtil.ToHexString(component.colorValue);
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyGUI.GComboBox) {
|
||||
// value = component.selectedIndex;
|
||||
value = component.values.get_Item(component.selectedIndex);
|
||||
}
|
||||
else if (component instanceof csharp_1.FairyEditor.Component.NumericInput) {
|
||||
value = component.value;
|
||||
}
|
||||
else if (this.components[i].type == index_1.EComponent.SWITCH) {
|
||||
value = component.selected;
|
||||
}
|
||||
else if (this.components[i].type == index_1.EComponent.RADIOBOX) {
|
||||
value = component.selected ? 1 : 0;
|
||||
}
|
||||
else if (this.components[i].type == index_1.EComponent.SLIDER) {
|
||||
value = component.value;
|
||||
}
|
||||
let key = this.components[i].key;
|
||||
if (this.customDataObj) {
|
||||
this.customDataObj[key] = value;
|
||||
}
|
||||
}
|
||||
return JSON.stringify(this.customDataObj) || "";
|
||||
}
|
||||
getValueByName(name) {
|
||||
// let value = "";
|
||||
// if (this.customDataObj?.[name]) {
|
||||
// value = this.customDataObj[name];
|
||||
// }
|
||||
// return value;
|
||||
return this.customDataObj[name];
|
||||
}
|
||||
setCustomData() {
|
||||
let propName = this.parent ? "remark" : "customData";
|
||||
let data = this.getListItemVal();
|
||||
App.activeDoc.inspectingTarget.docElement.SetProperty(propName, data);
|
||||
}
|
||||
}
|
||||
exports.CustomAttributer = CustomAttributer;
|
||||
let isCharacterMatch = (s, p) => {
|
||||
let dp = [];
|
||||
for (let i = 0; i <= s.length; i++) {
|
||||
let child = [];
|
||||
for (let j = 0; j <= p.length; j++) {
|
||||
child.push(false);
|
||||
}
|
||||
dp.push(child);
|
||||
}
|
||||
dp[s.length][p.length] = true;
|
||||
for (let i = p.length - 1; i >= 0; i--) {
|
||||
if (p[i] != "*")
|
||||
break;
|
||||
else
|
||||
dp[s.length][i] = true;
|
||||
}
|
||||
for (let i = s.length - 1; i >= 0; i--) {
|
||||
for (let j = p.length - 1; j >= 0; j--) {
|
||||
if (s[i] == p[j] || p[j] == "?") {
|
||||
dp[i][j] = dp[i + 1][j + 1];
|
||||
}
|
||||
else if (p[j] == "*") {
|
||||
dp[i][j] = dp[i + 1][j] || dp[i][j + 1];
|
||||
}
|
||||
else {
|
||||
dp[i][j] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dp[0][0];
|
||||
};
|
||||
let isRegMatch = (source, pattern) => {
|
||||
const patt = new RegExp(pattern);
|
||||
return patt.test(source);
|
||||
};
|
||||
let isMatch = (source, pattern) => {
|
||||
if (pattern.includes("*") || pattern.includes("?")) {
|
||||
return isCharacterMatch(source, pattern);
|
||||
}
|
||||
else if (pattern.includes("/")) {
|
||||
return isRegMatch(source, pattern);
|
||||
}
|
||||
else {
|
||||
return source.includes(pattern);
|
||||
}
|
||||
};
|
||||
let getComponent = (componentType) => {
|
||||
let component;
|
||||
switch (componentType) {
|
||||
case index_1.EComponent.TEXTINPUT:
|
||||
component = csharp_1.FairyGUI.UIPackage.CreateObject("TweenAttributer", index_1.EComponent.TEXTINPUT).asCom;
|
||||
break;
|
||||
case index_1.EComponent.TEXTAREA:
|
||||
component = csharp_1.FairyGUI.UIPackage.CreateObject("TweenAttributer", index_1.EComponent.TEXTAREA).asCom;
|
||||
break;
|
||||
case index_1.EComponent.COMBOBOX:
|
||||
component = csharp_1.FairyGUI.UIPackage.CreateObject("TweenAttributer", index_1.EComponent.COMBOBOX).asCom;
|
||||
break;
|
||||
case index_1.EComponent.COLORINPUT:
|
||||
component = csharp_1.FairyGUI.UIPackage.CreateObject("TweenAttributer", index_1.EComponent.COLORINPUT).asCom;
|
||||
break;
|
||||
case index_1.EComponent.NUMBERINPUT:
|
||||
component = csharp_1.FairyGUI.UIPackage.CreateObject("TweenAttributer", index_1.EComponent.NUMBERINPUT).asCom;
|
||||
break;
|
||||
case index_1.EComponent.RESOURCEINPUT:
|
||||
component = csharp_1.FairyGUI.UIPackage.CreateObject("TweenAttributer", index_1.EComponent.RESOURCEINPUT).asCom;
|
||||
break;
|
||||
case index_1.EComponent.SLIDER:
|
||||
component = csharp_1.FairyGUI.UIPackage.CreateObject("TweenAttributer", index_1.EComponent.SLIDER).asCom;
|
||||
break;
|
||||
case index_1.EComponent.RADIOBOX:
|
||||
component = csharp_1.FairyGUI.UIPackage.CreateObject("TweenAttributer", index_1.EComponent.RADIOBOX).asCom;
|
||||
break;
|
||||
case index_1.EComponent.SWITCH:
|
||||
component = csharp_1.FairyGUI.UIPackage.CreateObject("TweenAttributer", index_1.EComponent.SWITCH).asCom;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return component;
|
||||
};
|
||||
475
FGUIProject/plugins/whoot-tween/TweenCoustomInspector.ts
Normal file
475
FGUIProject/plugins/whoot-tween/TweenCoustomInspector.ts
Normal file
@@ -0,0 +1,475 @@
|
||||
import { FairyGUI, FairyEditor, System } from 'csharp';
|
||||
import { $generic, $typeof } from 'puerts';
|
||||
import { IConfig, IComponent, EComponent, EMode, IInspector } from './index';
|
||||
|
||||
const App = FairyEditor.App;
|
||||
// 动效设置(参考 LanguageSettings 的存储方式)
|
||||
const TweenSettings_1 = require("./TweenSettings");
|
||||
|
||||
class CustomAttributer extends FairyEditor.View.PluginInspector {
|
||||
private list: FairyGUI.GList;
|
||||
private components: IComponent[] = [];
|
||||
private pattern: string = "*";
|
||||
private parent: boolean = false;
|
||||
private textMode: FairyGUI.GTextField;
|
||||
private mode: EMode = EMode.WRITE;
|
||||
private modeCtr: FairyGUI.Controller;
|
||||
// private btn_save: FairyGUI.GButton;
|
||||
// private btn_reset: FairyGUI.GButton;
|
||||
private customData: string = "";
|
||||
private customDataObj: {} = {};
|
||||
|
||||
public constructor(data: IInspector) {
|
||||
super();
|
||||
|
||||
this.panel = FairyGUI.UIPackage.CreateObject("TweenAttributer", "Main").asCom;
|
||||
// this.panel.GetChild("btn_save").asButton.visible = false;
|
||||
// this.panel.GetChild("btn_reset").asButton.visible = false;
|
||||
// this.panel.GetChild("btn_copy").asButton.visible = false;
|
||||
let { components, mode, pattern, parent } = data;
|
||||
this.components = components;
|
||||
this.pattern = pattern;
|
||||
this.parent = parent;
|
||||
this.list = this.panel.GetChild("list_components").asList;
|
||||
//this.textMode = this.panel.GetChild("text_mode").asTextField;
|
||||
this.mode = mode || EMode.WRITE; // todo
|
||||
if (this.components.length > 0) {
|
||||
this.list.numItems = 0;
|
||||
}
|
||||
this.modeCtr = this.panel.GetController("op");
|
||||
|
||||
// this.btn_save = this.panel.GetChild("btn_save").asButton;
|
||||
// this.btn_save.onClick.Add(() => {
|
||||
// this.setCustomData();
|
||||
// })
|
||||
|
||||
// this.btn_reset = this.panel.GetChild("btn_reset").asButton;
|
||||
// this.btn_reset.onClick.Add(() => {
|
||||
// this.showList(true);
|
||||
// })
|
||||
|
||||
this.updateAction = () => { return this.updateUI(); };
|
||||
}
|
||||
|
||||
private lastSelectedComponent: string = "";
|
||||
private lastData: string = "";
|
||||
private updateUI(): boolean {
|
||||
let curDoc = App.activeDoc;
|
||||
let { inspectingTarget } = curDoc;
|
||||
let id = this.parent ? curDoc.docURL : inspectingTarget.id;
|
||||
// 实时获取自定义数据
|
||||
let propName = this.parent ? "remark" : "customData";
|
||||
this.customData = inspectingTarget.GetProperty(propName);
|
||||
try {
|
||||
this.customDataObj = JSON.parse(this.customData) || {};
|
||||
} catch (e) {
|
||||
// console.log("自定义数据异常或没有发现自定义数据,无法渲染列表");
|
||||
this.customDataObj = {};
|
||||
}
|
||||
|
||||
// 根据匹配规则验证是否显示inspector
|
||||
// 正则 & 字符串 通配符
|
||||
let name = this.parent ? curDoc.displayTitle : inspectingTarget.name;
|
||||
let pattern = isMatch(name, this.pattern);
|
||||
if ((pattern && this.lastSelectedComponent != id) || this.customData !== this.lastData) { // 判断是否满足条件的组件以及是上一次选中的组件或者数据是否被修改
|
||||
this.showList();
|
||||
}
|
||||
|
||||
this.lastData = this.customData;
|
||||
this.lastSelectedComponent = id;
|
||||
return pattern;
|
||||
}
|
||||
|
||||
private showList(reset: boolean = false) {
|
||||
this.list.numItems = 0;
|
||||
// todo
|
||||
// if (this.mode == EMode.WRITE) {
|
||||
// this.textMode.SetVar("mode", "设置").FlushVars();
|
||||
// this.modeCtr.SetSelectedPage("write");
|
||||
// } else {
|
||||
// this.textMode.SetVar("mode", "读取").FlushVars();
|
||||
// this.modeCtr.SetSelectedPage("read");
|
||||
// }
|
||||
|
||||
// 根据自定义属性和配置文件混合比较【以自定义属性为主】渲染列表数据
|
||||
for (let item of this.components) {
|
||||
let { type, name, id, key } = item;
|
||||
let com = getComponent(type);
|
||||
if (!key) {
|
||||
console.log("未定义唯一keyID:", id);
|
||||
return
|
||||
}
|
||||
if (!com) {
|
||||
console.log("发现未定义扩展组件,ID:", id);
|
||||
}
|
||||
|
||||
(<FairyGUI.GButton>com).title = name || key;
|
||||
const component = com.GetChild("component");
|
||||
com.name = key;
|
||||
this.renderItem(component, item, reset);
|
||||
|
||||
// 监听组件变更并保存到 json(参考 LanguageCustomInspector 的做法)
|
||||
this.bindPersistEvents(component, item);
|
||||
|
||||
this.list.AddChild(com);
|
||||
}
|
||||
this.list.ResizeToFit();
|
||||
|
||||
// 更新关联关系
|
||||
for (let item of this.components) {
|
||||
let { associate, key } = item;
|
||||
// 找到关联组件
|
||||
let associateCom,curCom;
|
||||
for(let i = 0;i<this.list.numChildren;i++){
|
||||
let com = this.list.GetChildAt(i);
|
||||
if(com.name == associate){
|
||||
associateCom = com;
|
||||
}
|
||||
if(com.name == key){
|
||||
curCom = com;
|
||||
}
|
||||
}
|
||||
if(associateCom && !associateCom.GetChild("component").selected && curCom){
|
||||
this.list.RemoveChild(curCom);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 给渲染出来的控件绑定事件:
|
||||
* -(已暂时停用)更新自定义属性(SetProperty)
|
||||
* - 将动效设置保存到项目设置目录下的 json(whootTween/<package>.json)
|
||||
*/
|
||||
private bindPersistEvents(component: FairyGUI.GObject, item: IComponent) {
|
||||
const persist = () => {
|
||||
// 暂时不写回到自定义数据,仅保存到 json
|
||||
// this.setCustomData();
|
||||
|
||||
// 将与动效相关的设置保存到 json
|
||||
this.trySaveTweenSetting(item, component);
|
||||
};
|
||||
|
||||
// 根据控件类型选择合适的触发时机
|
||||
if (component instanceof FairyGUI.GComboBox) {
|
||||
component.onChanged.Add(persist);
|
||||
} else if (component instanceof FairyEditor.Component.NumericInput) {
|
||||
// 数字输入使用失焦触发
|
||||
(component as FairyEditor.Component.NumericInput).onFocusOut.Add(persist);
|
||||
} else if (component instanceof FairyGUI.GSlider) {
|
||||
component.onChanged.Add(persist);
|
||||
} else if (component instanceof FairyGUI.GButton) { // SWITCH / RADIOBOX
|
||||
component.onChanged.Add(persist);
|
||||
} else if (component instanceof FairyEditor.Component.ColorInput) {
|
||||
component.onChanged.Add(persist);
|
||||
} else if (component instanceof FairyGUI.GLabel) { // 文本输入类:失焦时保存
|
||||
(component as FairyGUI.GLabel).onFocusOut.Add(persist);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将与动效相关的设置保存到 json 文件。
|
||||
* 规则:
|
||||
* - 仅对下拉框(ComboBox)做持久化(其 value 代表动效 key)
|
||||
* - 当选中值为 "null" 视为未启用(useable=false),否则为启用
|
||||
*/
|
||||
private trySaveTweenSetting(item: IComponent, component: any) {
|
||||
try {
|
||||
if (!(component instanceof FairyGUI.GComboBox)) return;
|
||||
|
||||
// 读取当前对象与文档信息
|
||||
let sels = App.activeDoc.inspectingTargets;
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc;
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id;
|
||||
// 父级组件通常没有有效的 id,这里为父级使用文档级占位 id
|
||||
if ((!objId || objId === "") && this.parent) {
|
||||
objId = "__root__";
|
||||
}
|
||||
|
||||
// 当前选择的动效 key
|
||||
const selectedIndex = component.selectedIndex;
|
||||
const selectedValue = component.values?.get_Item(selectedIndex);
|
||||
|
||||
// 条件:无(值为"null")或组件ID为空(非父级场景),不记录
|
||||
if ((!objId || objId === "") && !this.parent) return;
|
||||
if (selectedValue == null) return;
|
||||
if (selectedValue === "null") {
|
||||
// 选择“无”时,删除已存在的记录
|
||||
TweenSettings_1.default.remove(packageName, docUrl, objId);
|
||||
return;
|
||||
}
|
||||
|
||||
const useable = true; // 只有有效选择才记录,直接标记为可用
|
||||
// 保存到 whootTween/<package>.json
|
||||
TweenSettings_1.default.update(packageName, docUrl, objId, selectedValue, useable);
|
||||
|
||||
// 保存后做一次清理:把已删除的组件从 json 中移除
|
||||
this.cleanupDeletedComponents(packageName, docUrl);
|
||||
} catch (e) {
|
||||
console.error("保存动效设置到 json 失败:", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集当前文档中仍然存在的组件ID(递归)并触发清理
|
||||
*/
|
||||
private cleanupDeletedComponents(packageName: string, docUrl: string) {
|
||||
try {
|
||||
const ids: string[] = [];
|
||||
const visited: { [k: string]: boolean } = {};
|
||||
|
||||
const collect = (node: FairyEditor.FObject) => {
|
||||
if (!node) return;
|
||||
const nid = (node as any).id as string;
|
||||
if (nid && !visited[nid]) {
|
||||
visited[nid] = true;
|
||||
ids.push(nid);
|
||||
}
|
||||
if (node instanceof FairyEditor.FComponent) {
|
||||
const cnt = (node as FairyEditor.FComponent).numChildren;
|
||||
for (let i = 0; i < cnt; i++) {
|
||||
const child = (node as FairyEditor.FComponent).GetChildAt(i);
|
||||
collect(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const activeDoc = App.activeDoc;
|
||||
if (activeDoc && activeDoc.content) {
|
||||
collect(activeDoc.content);
|
||||
}
|
||||
|
||||
// 仅当有 id 列表时尝试清理(保留 __root__)
|
||||
TweenSettings_1.default.cleanupDoc(packageName, docUrl, ids);
|
||||
} catch (err) {
|
||||
console.error('清理已删除组件记录失败', err);
|
||||
}
|
||||
}
|
||||
|
||||
private renderItem(component: FairyGUI.GObject, item: IComponent, reset: boolean) {
|
||||
let { value, key } = item;
|
||||
if (!reset) {
|
||||
let defaultVal = this.getValueByName(key);
|
||||
value = defaultVal != undefined ? defaultVal : value;
|
||||
}
|
||||
// 下拉框
|
||||
if (component instanceof FairyGUI.GComboBox && item.type == EComponent.COMBOBOX) {
|
||||
let data = item.data;
|
||||
let valueArr = System.Array.CreateInstance($typeof(System.String), data.values.length) as System.Array$1<string>;
|
||||
for (let i = 0; i < data.values.length; i++) {
|
||||
let v = data.values[i];
|
||||
valueArr.set_Item(i, v);
|
||||
}
|
||||
|
||||
let itemArr = System.Array.CreateInstance($typeof(System.String), data.items.length) as System.Array$1<string>;
|
||||
for (let i = 0; i < data.items.length; i++) {
|
||||
let v = data.items[i];
|
||||
itemArr.set_Item(i, v);
|
||||
}
|
||||
|
||||
component.items = itemArr;
|
||||
component.values = valueArr;
|
||||
|
||||
// 优先使用外部配置(TweenSettings)进行回填
|
||||
const extVal = this.getExternalTweenKey();
|
||||
if (extVal && (data.values as string[]).indexOf(extVal) >= 0) {
|
||||
component.value = extVal;
|
||||
} else {
|
||||
// 兼容:customData 可能保存的是值字符串或索引
|
||||
if (typeof value === 'string' && (data.values as string[]).indexOf(value) >= 0) {
|
||||
component.value = value as string;
|
||||
} else {
|
||||
const idx = Number(value);
|
||||
const finalIdx = isNaN(idx) ? 0 : idx;
|
||||
component.value = data.values[finalIdx] ?? data.values[0];
|
||||
}
|
||||
}
|
||||
|
||||
} else if (component instanceof FairyGUI.GLabel &&
|
||||
(
|
||||
item.type == EComponent.TEXTINPUT ||
|
||||
item.type == EComponent.TEXTAREA ||
|
||||
item.type == EComponent.RESOURCEINPUT
|
||||
)) { // 文本输入框
|
||||
component.title = value + "" || "";
|
||||
} else if (item.type == EComponent.COLORINPUT && component instanceof FairyEditor.Component.ColorInput) { // 颜色输入框
|
||||
let colorValue = value + "" || "#000000";
|
||||
component.colorValue = FairyEditor.ColorUtil.FromHexString(colorValue);
|
||||
} else if (component instanceof FairyGUI.GSlider && item.type == EComponent.SLIDER) { // 滑动块
|
||||
let data = item.data;
|
||||
component.min = +data.min || 0;
|
||||
component.max = +data.max || 100;
|
||||
component.value = +value || 0;
|
||||
} else if (component instanceof FairyEditor.Component.NumericInput && item.type == EComponent.NUMBERINPUT) { // 数字输入框
|
||||
let data = item.data;
|
||||
component.min = +data.min || 0;
|
||||
component.max = +data.max || 100;
|
||||
component.step = +data.step || 0;
|
||||
component.value = +value || 0;
|
||||
} else if (component instanceof FairyGUI.GButton && item.type == EComponent.SWITCH) { // 切换器
|
||||
component.selected = Boolean(value);
|
||||
} else if (component instanceof FairyGUI.GButton && item.type == EComponent.RADIOBOX) { // 单选框
|
||||
let data = item.data;
|
||||
component.GetChildAt(0).text = data.items[0];
|
||||
component.GetChildAt(1).text = data.items[1];
|
||||
component.selected = Boolean(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取当前对象在 TweenSettings 中的外部配置 key
|
||||
*/
|
||||
private getExternalTweenKey(): string | null {
|
||||
try {
|
||||
let sels = App.activeDoc.inspectingTargets;
|
||||
// puerts 映射的 IList$1 没有 Count 属性,这里直接尝试取第 0 项
|
||||
if (!sels) return null;
|
||||
let obj = sels.get_Item(0);
|
||||
let activeDoc = App.activeDoc;
|
||||
let packageName = activeDoc.packageItem.owner.name;
|
||||
let docUrl = activeDoc.docURL;
|
||||
let objId = obj.id;
|
||||
if ((!objId || objId === "") && this.parent) {
|
||||
objId = "__root__";
|
||||
}
|
||||
let data = TweenSettings_1.default.get(packageName, docUrl, objId);
|
||||
if (data && data.useable == 1 && data.key) {
|
||||
return data.key as string;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('读取 TweenSettings 外部配置失败', e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private getListItemVal(): string {
|
||||
for (let i = 0; i < this.list.numChildren; i++) {
|
||||
let item = this.list.GetChildAt(i) as FairyGUI.GComponent;
|
||||
let component = item.GetChild("component") as any;
|
||||
|
||||
let value = component.title;
|
||||
if (component instanceof FairyEditor.Component.ColorInput) {
|
||||
value = FairyEditor.ColorUtil.ToHexString(component.colorValue);
|
||||
} else if (component instanceof FairyGUI.GComboBox) {
|
||||
// value = component.selectedIndex;
|
||||
value = component.values.get_Item(component.selectedIndex);
|
||||
} else if (component instanceof FairyEditor.Component.NumericInput) {
|
||||
value = component.value;
|
||||
} else if (this.components[i].type == EComponent.SWITCH) {
|
||||
value = (component as FairyGUI.GButton).selected;
|
||||
} else if (this.components[i].type == EComponent.RADIOBOX) {
|
||||
value = (component as FairyGUI.GButton).selected ? 1 : 0;
|
||||
} else if (this.components[i].type == EComponent.SLIDER) {
|
||||
value = (component as FairyGUI.GSlider).value;
|
||||
}
|
||||
|
||||
let key = this.components[i].key;
|
||||
if (this.customDataObj) {
|
||||
this.customDataObj[key] = value;
|
||||
}
|
||||
|
||||
}
|
||||
return JSON.stringify(this.customDataObj) || "";
|
||||
}
|
||||
|
||||
private getValueByName(name: string): string {
|
||||
// let value = "";
|
||||
// if (this.customDataObj?.[name]) {
|
||||
// value = this.customDataObj[name];
|
||||
// }
|
||||
// return value;
|
||||
return this.customDataObj[name];
|
||||
}
|
||||
|
||||
private setCustomData() {
|
||||
let propName = this.parent ? "remark" : "customData";
|
||||
let data = this.getListItemVal();
|
||||
App.activeDoc.inspectingTarget.docElement.SetProperty(propName, data);
|
||||
}
|
||||
}
|
||||
|
||||
let isCharacterMatch = (s: string, p: string): boolean => {
|
||||
let dp = [];
|
||||
for (let i = 0; i <= s.length; i++) {
|
||||
let child = [];
|
||||
for (let j = 0; j <= p.length; j++) {
|
||||
child.push(false);
|
||||
}
|
||||
dp.push(child);
|
||||
}
|
||||
dp[s.length][p.length] = true;
|
||||
|
||||
for (let i = p.length - 1; i >= 0; i--) {
|
||||
if (p[i] != "*") break;
|
||||
else dp[s.length][i] = true;
|
||||
}
|
||||
|
||||
for (let i = s.length - 1; i >= 0; i--) {
|
||||
for (let j = p.length - 1; j >= 0; j--) {
|
||||
if (s[i] == p[j] || p[j] == "?") {
|
||||
dp[i][j] = dp[i + 1][j + 1];
|
||||
} else if (p[j] == "*") {
|
||||
dp[i][j] = dp[i + 1][j] || dp[i][j + 1];
|
||||
} else {
|
||||
dp[i][j] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dp[0][0];
|
||||
};
|
||||
|
||||
let isRegMatch = (source: string, pattern: string): boolean => {
|
||||
const patt = new RegExp(pattern);
|
||||
return patt.test(source);
|
||||
}
|
||||
|
||||
let isMatch = (source: string, pattern: string): boolean => {
|
||||
if (pattern.includes("*") || pattern.includes("?")) {
|
||||
return isCharacterMatch(source, pattern);
|
||||
} else if (pattern.includes("/")) {
|
||||
return isRegMatch(source, pattern);
|
||||
} else {
|
||||
return source.includes(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
let getComponent = (componentType: EComponent): FairyGUI.GComponent => {
|
||||
let component: FairyGUI.GComponent;
|
||||
switch (componentType) {
|
||||
case EComponent.TEXTINPUT:
|
||||
component = FairyGUI.UIPackage.CreateObject("TweenAttributer", EComponent.TEXTINPUT).asCom;
|
||||
break;
|
||||
case EComponent.TEXTAREA:
|
||||
component = FairyGUI.UIPackage.CreateObject("TweenAttributer", EComponent.TEXTAREA).asCom;
|
||||
break;
|
||||
case EComponent.COMBOBOX:
|
||||
component = FairyGUI.UIPackage.CreateObject("TweenAttributer", EComponent.COMBOBOX).asCom;
|
||||
break;
|
||||
case EComponent.COLORINPUT:
|
||||
component = FairyGUI.UIPackage.CreateObject("TweenAttributer", EComponent.COLORINPUT).asCom;
|
||||
break;
|
||||
case EComponent.NUMBERINPUT:
|
||||
component = FairyGUI.UIPackage.CreateObject("TweenAttributer", EComponent.NUMBERINPUT).asCom;
|
||||
break;
|
||||
case EComponent.RESOURCEINPUT:
|
||||
component = FairyGUI.UIPackage.CreateObject("TweenAttributer", EComponent.RESOURCEINPUT).asCom;
|
||||
break;
|
||||
case EComponent.SLIDER:
|
||||
component = FairyGUI.UIPackage.CreateObject("TweenAttributer", EComponent.SLIDER).asCom;
|
||||
break;
|
||||
case EComponent.RADIOBOX:
|
||||
component = FairyGUI.UIPackage.CreateObject("TweenAttributer", EComponent.RADIOBOX).asCom;
|
||||
break;
|
||||
case EComponent.SWITCH:
|
||||
component = FairyGUI.UIPackage.CreateObject("TweenAttributer", EComponent.SWITCH).asCom;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
export { CustomAttributer };
|
||||
326
FGUIProject/plugins/whoot-tween/TweenSettings.js
Normal file
326
FGUIProject/plugins/whoot-tween/TweenSettings.js
Normal file
@@ -0,0 +1,326 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TweenSettings = exports.TweenPackageData = exports.TweenComponentChildData = void 0;
|
||||
const csharp_1 = require("csharp");
|
||||
const App = csharp_1.FairyEditor.App;
|
||||
const File = csharp_1.System.IO.File;
|
||||
const Directory = csharp_1.System.IO.Directory;
|
||||
class TweenComponentChildData {
|
||||
id;
|
||||
key;
|
||||
useable;
|
||||
}
|
||||
exports.TweenComponentChildData = TweenComponentChildData;
|
||||
// class TweenComponentData {
|
||||
// url: string;
|
||||
// childs: object = {};
|
||||
// }
|
||||
class TweenPackageData {
|
||||
name;
|
||||
components = {};
|
||||
}
|
||||
exports.TweenPackageData = TweenPackageData;
|
||||
class TweenSettings {
|
||||
static instance;
|
||||
static getInstance() {
|
||||
if (!this.instance) {
|
||||
this.instance = new TweenSettings();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
componentsSettingBasePath = "";
|
||||
_TweenMap = new Map();
|
||||
_TweenKeyValues = {};
|
||||
constructor() {
|
||||
this.init();
|
||||
// this._TweenKeyValues['k1'] = "hahha1"
|
||||
// this._TweenKeyValues['k2'] = "hahha2"
|
||||
// this._TweenKeyValues['k3'] = "hahha3"
|
||||
//'CustomProperties'
|
||||
let path = App.project.settingsPath + "/CustomProperties.json";
|
||||
if (File.Exists(path)) {
|
||||
let jsonStr = File.ReadAllText(path);
|
||||
let settings = JSON.parse(jsonStr);
|
||||
let TweenKey = "en";
|
||||
if (settings.hasOwnProperty("TweenKey")) {
|
||||
TweenKey = settings['TweenKey'];
|
||||
}
|
||||
if (settings.hasOwnProperty("TweenPath")) {
|
||||
let TweenPath = App.project.basePath + "/" + settings['TweenPath'];
|
||||
console.log("动效路径=", TweenPath);
|
||||
if (File.Exists(TweenPath)) {
|
||||
let TweenStr = File.ReadAllText(TweenPath);
|
||||
let datas = JSON.parse(TweenStr);
|
||||
if (datas != null && datas.length > 0) {
|
||||
for (const data of datas) {
|
||||
this._TweenKeyValues[data['key']] = data[TweenKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
init() {
|
||||
console.log("初始化加载动效配置===");
|
||||
this.componentsSettingBasePath = App.project.settingsPath + "/whootTween";
|
||||
if (!csharp_1.System.IO.Directory.Exists(this.componentsSettingBasePath)) {
|
||||
console.log("whoot配置文件目录不存在,创建");
|
||||
csharp_1.System.IO.Directory.CreateDirectory(this.componentsSettingBasePath);
|
||||
}
|
||||
this.readAll();
|
||||
}
|
||||
/**
|
||||
* 清理无效的配置
|
||||
*/
|
||||
clearFailureConfig() {
|
||||
// App.d
|
||||
}
|
||||
getTween(key) {
|
||||
let value = this._TweenKeyValues[key];
|
||||
if (value == null) {
|
||||
return key;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* 获取所有动效配置
|
||||
* @returns
|
||||
*/
|
||||
getAllPackage() {
|
||||
return this._TweenMap;
|
||||
}
|
||||
/**
|
||||
* 获取一个动效配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @param componentId
|
||||
*/
|
||||
get(packageName, docUrl, componentId) {
|
||||
let pack = this._TweenMap.get(packageName);
|
||||
if (pack != null) {
|
||||
let doc = pack.components[docUrl];
|
||||
if (doc != null) {
|
||||
let child = doc[componentId];
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 获取一个组件的动效配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @returns
|
||||
*/
|
||||
getDoc(packageName, docUrl) {
|
||||
let pack = this._TweenMap.get(packageName);
|
||||
if (pack != null) {
|
||||
let doc = pack.components[docUrl];
|
||||
if (doc != null) {
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 获取一个包的动效配置
|
||||
* @param packageName
|
||||
*/
|
||||
getPackage(packageName) {
|
||||
let pack = this._TweenMap.get(packageName);
|
||||
if (pack) {
|
||||
return pack.components;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
/**
|
||||
* 更新一个动效配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @param componentId
|
||||
* @param TweenKey
|
||||
* @param useable 是否可用的
|
||||
*/
|
||||
update(packageName, docUrl, componentId, TweenKey, useable = true) {
|
||||
let chang = false;
|
||||
let pack = this._TweenMap.get(packageName);
|
||||
if (pack == null) {
|
||||
pack = new TweenPackageData();
|
||||
pack.name = packageName;
|
||||
this._TweenMap.set(packageName, pack);
|
||||
chang = true;
|
||||
}
|
||||
let doc = pack.components[docUrl];
|
||||
if (doc == null) {
|
||||
doc = {};
|
||||
pack.components[docUrl] = doc; //.set(docUrl, doc)
|
||||
chang = true;
|
||||
}
|
||||
let child = doc[componentId];
|
||||
if (child == null) {
|
||||
child = new TweenComponentChildData();
|
||||
child.id = componentId;
|
||||
doc[componentId] = child; //.set(componentId, child)
|
||||
}
|
||||
let u = useable ? 1 : 0;
|
||||
if (child.key != TweenKey || child.useable != u) {
|
||||
child.key = TweenKey;
|
||||
child.useable = u;
|
||||
chang = true;
|
||||
}
|
||||
if (chang) {
|
||||
//有数据变化,变更文件
|
||||
this.saveFile(packageName);
|
||||
}
|
||||
return chang;
|
||||
}
|
||||
/**
|
||||
* 删除一个动效配置(当选择“无”或需清除时)
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @param componentId
|
||||
*/
|
||||
remove(packageName, docUrl, componentId) {
|
||||
let changed = false;
|
||||
const pack = this._TweenMap.get(packageName);
|
||||
if (!pack)
|
||||
return false;
|
||||
const doc = pack.components[docUrl];
|
||||
if (!doc)
|
||||
return false;
|
||||
if (doc.hasOwnProperty(componentId)) {
|
||||
delete doc[componentId];
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
// 若当前文档节点已空,清理条目
|
||||
if (Object.keys(doc).length === 0) {
|
||||
delete pack.components[docUrl];
|
||||
}
|
||||
this.saveFile(packageName);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
//region 工具方法
|
||||
updateItemTitle(obj, key) {
|
||||
// console.log("obj类型=", obj.GetType())
|
||||
if (obj instanceof csharp_1.FairyEditor.FTextInput) {
|
||||
let textInput = obj;
|
||||
textInput.promptText = this.getTween(key);
|
||||
}
|
||||
else if (obj instanceof csharp_1.FairyEditor.FButton) {
|
||||
let button = obj;
|
||||
button.title = this.getTween(key);
|
||||
}
|
||||
else if (obj instanceof csharp_1.FairyEditor.FLabel) {
|
||||
let lable = obj;
|
||||
lable.title = this.getTween(key);
|
||||
}
|
||||
else {
|
||||
obj.text = this.getTween(key);
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
//region file
|
||||
//获取所有的文件的路径
|
||||
getAllDirector(path, list) {
|
||||
console.log("开始读取所有配置=", path);
|
||||
let files = Directory.GetFiles(path, "*.json");
|
||||
for (let f = 0; f < files.Length; f++) {
|
||||
list.push(files.get_Item(f));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 读取全部
|
||||
*/
|
||||
readAll() {
|
||||
try {
|
||||
let list = [];
|
||||
this.getAllDirector(this.componentsSettingBasePath, list);
|
||||
this._TweenMap.clear();
|
||||
console.log("初始化所有动效配置");
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
let p = list[index];
|
||||
let jsonStr = File.ReadAllText(p);
|
||||
let data = JSON.parse(jsonStr);
|
||||
this._TweenMap.set(data.name, data);
|
||||
}
|
||||
}
|
||||
catch {
|
||||
console.error("读取动效配置文件失败");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 将所有配置保存成配置文件
|
||||
*/
|
||||
saveAllFile() {
|
||||
let keys = this._TweenMap.keys();
|
||||
for (const key of keys) {
|
||||
this.saveFile(key);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 清理某个文档下已删除的组件配置
|
||||
* @param packageName 包名
|
||||
* @param docUrl 文档URL
|
||||
* @param existComponentIds 该文档中仍然存在的组件id列表
|
||||
* @returns 是否有变更
|
||||
*/
|
||||
cleanupDoc(packageName, docUrl, existComponentIds) {
|
||||
const pack = this._TweenMap.get(packageName);
|
||||
if (!pack)
|
||||
return false;
|
||||
const doc = pack.components[docUrl];
|
||||
if (!doc)
|
||||
return false;
|
||||
// 归一到 JS 数组
|
||||
let ids = [];
|
||||
if (existComponentIds["Length"] != null) {
|
||||
// System.Array
|
||||
const len = existComponentIds.Length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
ids.push(existComponentIds.get_Item(i));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ids = existComponentIds;
|
||||
}
|
||||
const idSet = {};
|
||||
for (const id of ids) {
|
||||
if (id)
|
||||
idSet[id] = true;
|
||||
}
|
||||
let changed = false;
|
||||
for (const key in doc) {
|
||||
if (!doc.hasOwnProperty(key))
|
||||
continue;
|
||||
if (key === "__root__")
|
||||
continue; // 保留父级占位符
|
||||
if (!idSet[key]) {
|
||||
delete doc[key];
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
if (Object.keys(doc).length === 0) {
|
||||
delete pack.components[docUrl];
|
||||
}
|
||||
this.saveFile(packageName);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
/**
|
||||
* 保存json文件
|
||||
* @param packageName
|
||||
*/
|
||||
saveFile(packageName) {
|
||||
let path = this.componentsSettingBasePath + "/" + packageName + ".json";
|
||||
let data = this._TweenMap.get(packageName);
|
||||
if (data != null) {
|
||||
let jsonStr = JSON.stringify(data);
|
||||
File.WriteAllText(path, jsonStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.TweenSettings = TweenSettings;
|
||||
exports.default = TweenSettings.getInstance();
|
||||
343
FGUIProject/plugins/whoot-tween/TweenSettings.ts
Normal file
343
FGUIProject/plugins/whoot-tween/TweenSettings.ts
Normal file
@@ -0,0 +1,343 @@
|
||||
import { FairyGUI, FairyEditor, System } from 'csharp';
|
||||
|
||||
const App = FairyEditor.App;
|
||||
const File = System.IO.File;
|
||||
const Directory = System.IO.Directory;
|
||||
|
||||
export class TweenComponentChildData {
|
||||
id: string;
|
||||
key: string;
|
||||
useable: number;
|
||||
}
|
||||
|
||||
// class TweenComponentData {
|
||||
// url: string;
|
||||
// childs: object = {};
|
||||
// }
|
||||
|
||||
export class TweenPackageData {
|
||||
name: string;
|
||||
components: object = {};
|
||||
}
|
||||
|
||||
export class TweenSettings {
|
||||
private static instance: TweenSettings;
|
||||
static getInstance() {
|
||||
if (!this.instance) {
|
||||
this.instance = new TweenSettings();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
|
||||
public componentsSettingBasePath: string = "";
|
||||
private readonly _TweenMap: Map<string, TweenPackageData> = new Map<string, TweenPackageData>();
|
||||
private readonly _TweenKeyValues: object = {};
|
||||
|
||||
constructor() {
|
||||
this.init()
|
||||
// this._TweenKeyValues['k1'] = "hahha1"
|
||||
// this._TweenKeyValues['k2'] = "hahha2"
|
||||
// this._TweenKeyValues['k3'] = "hahha3"
|
||||
//'CustomProperties'
|
||||
let path = App.project.settingsPath + "/CustomProperties.json"
|
||||
if (File.Exists(path)) {
|
||||
let jsonStr = File.ReadAllText(path);
|
||||
let settings = JSON.parse(jsonStr) as object
|
||||
let TweenKey = "en"
|
||||
if (settings.hasOwnProperty("TweenKey")) {
|
||||
TweenKey = settings['TweenKey'];
|
||||
}
|
||||
if (settings.hasOwnProperty("TweenPath")) {
|
||||
let TweenPath = App.project.basePath + "/" + settings['TweenPath']
|
||||
console.log("动效路径=", TweenPath)
|
||||
if (File.Exists(TweenPath)) {
|
||||
let TweenStr = File.ReadAllText(TweenPath);
|
||||
let datas = JSON.parse(TweenStr) as Array<object>
|
||||
if (datas != null && datas.length > 0) {
|
||||
for (const data of datas) {
|
||||
this._TweenKeyValues[data['key']] = data[TweenKey]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private init() {
|
||||
console.log("初始化加载动效配置===")
|
||||
|
||||
this.componentsSettingBasePath = App.project.settingsPath + "/whootTween"
|
||||
if (!System.IO.Directory.Exists(this.componentsSettingBasePath)) {
|
||||
console.log("whoot配置文件目录不存在,创建")
|
||||
System.IO.Directory.CreateDirectory(this.componentsSettingBasePath)
|
||||
}
|
||||
this.readAll()
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理无效的配置
|
||||
*/
|
||||
clearFailureConfig() {
|
||||
// App.d
|
||||
}
|
||||
|
||||
getTween(key: string): string {
|
||||
let value = this._TweenKeyValues[key]
|
||||
if (value == null) {
|
||||
return key
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有动效配置
|
||||
* @returns
|
||||
*/
|
||||
getAllPackage(): Map<string, TweenPackageData> {
|
||||
return this._TweenMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个动效配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @param componentId
|
||||
*/
|
||||
get(packageName, docUrl, componentId): TweenComponentChildData {
|
||||
let pack = this._TweenMap.get(packageName)
|
||||
if (pack != null) {
|
||||
let doc = pack.components[docUrl]
|
||||
if (doc != null) {
|
||||
let child = doc[componentId]
|
||||
return child as TweenComponentChildData
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个组件的动效配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @returns
|
||||
*/
|
||||
getDoc(packageName, docUrl): object {
|
||||
let pack = this._TweenMap.get(packageName)
|
||||
if (pack != null) {
|
||||
let doc = pack.components[docUrl]
|
||||
if (doc != null) {
|
||||
return doc as object
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个包的动效配置
|
||||
* @param packageName
|
||||
*/
|
||||
getPackage(packageName): object {
|
||||
let pack = this._TweenMap.get(packageName)
|
||||
if (pack) {
|
||||
return pack.components;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新一个动效配置
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @param componentId
|
||||
* @param TweenKey
|
||||
* @param useable 是否可用的
|
||||
*/
|
||||
update(packageName, docUrl, componentId, TweenKey, useable: boolean = true): boolean {
|
||||
let chang = false
|
||||
let pack = this._TweenMap.get(packageName)
|
||||
if (pack == null) {
|
||||
pack = new TweenPackageData()
|
||||
pack.name = packageName
|
||||
this._TweenMap.set(packageName, pack)
|
||||
chang = true
|
||||
}
|
||||
let doc = pack.components[docUrl]
|
||||
if (doc == null) {
|
||||
doc = {};
|
||||
pack.components[docUrl] = doc;//.set(docUrl, doc)
|
||||
chang = true
|
||||
}
|
||||
let child = doc[componentId]
|
||||
if (child == null) {
|
||||
child = new TweenComponentChildData();
|
||||
child.id = componentId
|
||||
doc[componentId] = child//.set(componentId, child)
|
||||
}
|
||||
let u = useable ? 1 : 0
|
||||
if (child.key != TweenKey || child.useable != u) {
|
||||
child.key = TweenKey
|
||||
child.useable = u
|
||||
chang = true
|
||||
}
|
||||
|
||||
if (chang) {
|
||||
//有数据变化,变更文件
|
||||
this.saveFile(packageName)
|
||||
}
|
||||
return chang
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个动效配置(当选择“无”或需清除时)
|
||||
* @param packageName
|
||||
* @param docUrl
|
||||
* @param componentId
|
||||
*/
|
||||
remove(packageName: string, docUrl: string, componentId: string): boolean {
|
||||
let changed = false;
|
||||
const pack = this._TweenMap.get(packageName);
|
||||
if (!pack) return false;
|
||||
const doc = pack.components[docUrl] as any;
|
||||
if (!doc) return false;
|
||||
if (doc.hasOwnProperty(componentId)) {
|
||||
delete doc[componentId];
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
// 若当前文档节点已空,清理条目
|
||||
if (Object.keys(doc).length === 0) {
|
||||
delete pack.components[docUrl];
|
||||
}
|
||||
this.saveFile(packageName);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
//region 工具方法
|
||||
updateItemTitle(obj: FairyEditor.FObject, key: string) {
|
||||
// console.log("obj类型=", obj.GetType())
|
||||
if (obj instanceof FairyEditor.FTextInput) {
|
||||
let textInput = obj as FairyEditor.FTextInput
|
||||
textInput.promptText = this.getTween(key)
|
||||
} else if (obj instanceof FairyEditor.FButton) {
|
||||
let button = obj as FairyEditor.FButton
|
||||
button.title = this.getTween(key)
|
||||
} else if (obj instanceof FairyEditor.FLabel) {
|
||||
let lable = obj as FairyEditor.FLabel
|
||||
lable.title = this.getTween(key)
|
||||
} else {
|
||||
obj.text = this.getTween(key)
|
||||
}
|
||||
}
|
||||
//endregion
|
||||
|
||||
|
||||
//region file
|
||||
//获取所有的文件的路径
|
||||
private getAllDirector(path: string, list: Array<string>) {
|
||||
console.log("开始读取所有配置=", path)
|
||||
let files = Directory.GetFiles(path, "*.json")
|
||||
for (let f = 0; f < files.Length; f++) {
|
||||
list.push(files.get_Item(f))
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 读取全部
|
||||
*/
|
||||
private readAll() {
|
||||
try {
|
||||
let list: Array<string> = []
|
||||
this.getAllDirector(this.componentsSettingBasePath, list)
|
||||
this._TweenMap.clear()
|
||||
console.log("初始化所有动效配置")
|
||||
for (let index = 0; index < list.length; index++) {
|
||||
let p = list[index];
|
||||
let jsonStr = File.ReadAllText(p);
|
||||
let data: TweenPackageData = JSON.parse(jsonStr);
|
||||
this._TweenMap.set(data.name, data)
|
||||
}
|
||||
} catch {
|
||||
console.error("读取动效配置文件失败")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将所有配置保存成配置文件
|
||||
*/
|
||||
private saveAllFile() {
|
||||
let keys = this._TweenMap.keys()
|
||||
for (const key of keys) {
|
||||
this.saveFile(key)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理某个文档下已删除的组件配置
|
||||
* @param packageName 包名
|
||||
* @param docUrl 文档URL
|
||||
* @param existComponentIds 该文档中仍然存在的组件id列表
|
||||
* @returns 是否有变更
|
||||
*/
|
||||
public cleanupDoc(packageName: string, docUrl: string, existComponentIds: System.Array$1<string> | Array<string>): boolean {
|
||||
const pack = this._TweenMap.get(packageName)
|
||||
if (!pack) return false;
|
||||
const doc = pack.components[docUrl] as any;
|
||||
if (!doc) return false;
|
||||
|
||||
// 归一到 JS 数组
|
||||
let ids: Array<string> = [];
|
||||
if ((existComponentIds as any)["Length"] != null) {
|
||||
// System.Array
|
||||
const len = (existComponentIds as System.Array$1<string>).Length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
ids.push((existComponentIds as any).get_Item(i));
|
||||
}
|
||||
} else {
|
||||
ids = existComponentIds as Array<string>;
|
||||
}
|
||||
const idSet: { [k: string]: boolean } = {};
|
||||
for (const id of ids) {
|
||||
if (id) idSet[id] = true;
|
||||
}
|
||||
|
||||
let changed = false;
|
||||
for (const key in doc) {
|
||||
if (!doc.hasOwnProperty(key)) continue;
|
||||
if (key === "__root__") continue; // 保留父级占位符
|
||||
if (!idSet[key]) {
|
||||
delete doc[key];
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
if (Object.keys(doc).length === 0) {
|
||||
delete pack.components[docUrl];
|
||||
}
|
||||
this.saveFile(packageName);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
/**
|
||||
* 保存json文件
|
||||
* @param packageName
|
||||
*/
|
||||
private saveFile(packageName: string) {
|
||||
let path = this.componentsSettingBasePath + "/" + packageName + ".json";
|
||||
let data = this._TweenMap.get(packageName)
|
||||
if (data != null) {
|
||||
let jsonStr = JSON.stringify(data);
|
||||
File.WriteAllText(path, jsonStr)
|
||||
}
|
||||
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
|
||||
export default TweenSettings.getInstance();
|
||||
92
FGUIProject/plugins/whoot-tween/config.json
Normal file
92
FGUIProject/plugins/whoot-tween/config.json
Normal file
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"remote": "",
|
||||
"inspectors": [
|
||||
{
|
||||
"title": "通用动效【组件】",
|
||||
"parent": false,
|
||||
"pattern": "*",
|
||||
"mode": 1,
|
||||
"components": [
|
||||
{
|
||||
"type": "ComboBox",
|
||||
"id": 1001,
|
||||
"name": "Tween",
|
||||
"key": "ComboBox",
|
||||
"data": {
|
||||
"items": [
|
||||
"无",
|
||||
"渐显",
|
||||
"缩放",
|
||||
"Pop",
|
||||
"滑入(左)",
|
||||
"滑入(右)",
|
||||
"滑入(顶)",
|
||||
"滑入(底)",
|
||||
"跳动",
|
||||
"旋转",
|
||||
"抖动"
|
||||
],
|
||||
"values": [
|
||||
"null",
|
||||
"Fade",
|
||||
"Scale",
|
||||
"Pop",
|
||||
"SlideInL",
|
||||
"SlideInR",
|
||||
"SlideInT",
|
||||
"SlideInB",
|
||||
"Bounce",
|
||||
"Rotate",
|
||||
"Shake"
|
||||
]
|
||||
},
|
||||
"associate":"Switch",
|
||||
"value": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "通用动效【界面】",
|
||||
"parent": true,
|
||||
"pattern": "*",
|
||||
"mode": 1,
|
||||
"components": [
|
||||
{
|
||||
"type": "ComboBox",
|
||||
"id": 1001,
|
||||
"name": "Tween",
|
||||
"key": "ComboBox",
|
||||
"data": {
|
||||
"items": [
|
||||
"无",
|
||||
"渐显",
|
||||
"缩放",
|
||||
"Pop",
|
||||
"滑入(左)",
|
||||
"滑入(右)",
|
||||
"滑入(顶)",
|
||||
"滑入(底)",
|
||||
"跳动",
|
||||
"旋转",
|
||||
"抖动"
|
||||
],
|
||||
"values": [
|
||||
"null",
|
||||
"Fade",
|
||||
"Scale",
|
||||
"Pop",
|
||||
"SlideInL",
|
||||
"SlideInR",
|
||||
"SlideInT",
|
||||
"SlideInB",
|
||||
"Bounce",
|
||||
"Rotate",
|
||||
"Shake"
|
||||
]
|
||||
},
|
||||
"value": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
9903
FGUIProject/plugins/whoot-tween/editor.d.ts
vendored
Normal file
9903
FGUIProject/plugins/whoot-tween/editor.d.ts
vendored
Normal file
File diff suppressed because one or more lines are too long
101
FGUIProject/plugins/whoot-tween/index.d.ts
vendored
Normal file
101
FGUIProject/plugins/whoot-tween/index.d.ts
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
export interface IConfig {
|
||||
remote: boolean, // 远程配置地址
|
||||
inspectors:IInspector[]
|
||||
}
|
||||
|
||||
export interface IInspector{
|
||||
title: string,//inspectorName
|
||||
parent: boolean,// 父级组件
|
||||
pattern?: string,//匹配符
|
||||
mode?: EMode,// 1:设置模式 2:读取模式【暂未实现】
|
||||
components: IComponent[],
|
||||
}
|
||||
|
||||
export type IComponent = IComboBox |IRadioBox| INumberInput | ITextinput | ITextarea | IColorInput | ISwitch | IResourceInput | ISlider;
|
||||
|
||||
export interface IBaseComponent {
|
||||
id?: string,
|
||||
name?: string,
|
||||
key:string, // 唯一值
|
||||
associate?:string //关联组件id
|
||||
// value?: number | string // 默认值,该值为空即使用组件默认值
|
||||
}
|
||||
|
||||
export interface IComboBox extends IBaseComponent {
|
||||
type: EComponent.COMBOBOX,
|
||||
data: {
|
||||
items: string[],
|
||||
values: string[]
|
||||
},
|
||||
value:number
|
||||
|
||||
}
|
||||
|
||||
export interface ITextinput extends IBaseComponent {
|
||||
type: EComponent.TEXTINPUT,
|
||||
value:string
|
||||
}
|
||||
|
||||
export interface ITextarea extends IBaseComponent {
|
||||
type: EComponent.TEXTAREA,
|
||||
value:string
|
||||
}
|
||||
|
||||
export interface IColorInput extends IBaseComponent {
|
||||
type: EComponent.COLORINPUT,
|
||||
value:string
|
||||
}
|
||||
|
||||
export interface ISwitch extends IBaseComponent {
|
||||
type: EComponent.SWITCH,
|
||||
value:boolean
|
||||
}
|
||||
|
||||
export interface IResourceInput extends IBaseComponent {
|
||||
type: EComponent.RESOURCEINPUT,
|
||||
value:string
|
||||
}
|
||||
|
||||
export interface ISlider extends IBaseComponent {
|
||||
type: EComponent.SLIDER,
|
||||
data:{
|
||||
min:number,
|
||||
max:number
|
||||
},
|
||||
value:number
|
||||
}
|
||||
|
||||
export interface INumberInput extends IBaseComponent {
|
||||
type: EComponent.NUMBERINPUT,
|
||||
data: {
|
||||
min:number,
|
||||
max:number,
|
||||
step?:number
|
||||
},
|
||||
value:number
|
||||
}
|
||||
|
||||
export interface IRadioBox extends IBaseComponent {
|
||||
type: EComponent.RADIOBOX,
|
||||
data: {
|
||||
items:string[]
|
||||
},
|
||||
value:number
|
||||
}
|
||||
|
||||
export enum EComponent {
|
||||
TEXTINPUT = "Textinput",
|
||||
TEXTAREA = "Textarea",
|
||||
COMBOBOX = "ComboBox",
|
||||
COLORINPUT = "ColorInput",
|
||||
NUMBERINPUT = "NumberInput",
|
||||
SLIDER = "Slider",
|
||||
RESOURCEINPUT = "ResourceInput",
|
||||
RADIOBOX = "RadioBox",
|
||||
SWITCH = "Switch",
|
||||
}
|
||||
|
||||
export enum EMode {
|
||||
WRITE = 1,
|
||||
READ = 2
|
||||
}
|
||||
20
FGUIProject/plugins/whoot-tween/index.js
Normal file
20
FGUIProject/plugins/whoot-tween/index.js
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EMode = exports.EComponent = void 0;
|
||||
var EComponent;
|
||||
(function (EComponent) {
|
||||
EComponent["TEXTINPUT"] = "Textinput";
|
||||
EComponent["TEXTAREA"] = "Textarea";
|
||||
EComponent["COMBOBOX"] = "ComboBox";
|
||||
EComponent["COLORINPUT"] = "ColorInput";
|
||||
EComponent["NUMBERINPUT"] = "NumberInput";
|
||||
EComponent["SLIDER"] = "Slider";
|
||||
EComponent["RESOURCEINPUT"] = "ResourceInput";
|
||||
EComponent["RADIOBOX"] = "RadioBox";
|
||||
EComponent["SWITCH"] = "Switch";
|
||||
})(EComponent = exports.EComponent || (exports.EComponent = {}));
|
||||
var EMode;
|
||||
(function (EMode) {
|
||||
EMode[EMode["WRITE"] = 1] = "WRITE";
|
||||
EMode[EMode["READ"] = 2] = "READ";
|
||||
})(EMode = exports.EMode || (exports.EMode = {}));
|
||||
83
FGUIProject/plugins/whoot-tween/main.js
Normal file
83
FGUIProject/plugins/whoot-tween/main.js
Normal file
@@ -0,0 +1,83 @@
|
||||
"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);
|
||||
85
FGUIProject/plugins/whoot-tween/main.ts
Normal file
85
FGUIProject/plugins/whoot-tween/main.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { FairyGUI, FairyEditor, System } from 'csharp';
|
||||
import { $generic, $typeof } from 'puerts';
|
||||
import { IConfig, IComponent, EComponent, EMode, IInspector } from './index';
|
||||
import { CustomAttributer } from './TweenCoustomInspector';
|
||||
const TweenSettings = require('./TweenSettings').default as any;
|
||||
|
||||
const App = FairyEditor.App;
|
||||
// 首先读取本地文件配置获取是否本地配置还是远程配置
|
||||
// local
|
||||
let filePath = `${FairyEditor.App.project.basePath}/plugins/whoot-tween/config.json`;
|
||||
let config: IConfig;
|
||||
try {
|
||||
let sw = new 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 = 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 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 CustomAttributer(inspector), title, title);
|
||||
App.docFactory.ConnectInspector(title, "mixed", parent, false);
|
||||
}
|
||||
|
||||
// 当层级结构变化(增删控件)时,自动清理 JSON 中已删除组件的记录
|
||||
const onHierarchyChanged = (_ctx?: any) => {
|
||||
try {
|
||||
const activeDoc = App.activeDoc as FairyEditor.View.IDocument;
|
||||
if (!activeDoc) return;
|
||||
const packageName = activeDoc.packageItem.owner.name;
|
||||
const docUrl = activeDoc.docURL;
|
||||
const ids: string[] = [];
|
||||
const visited: { [k: string]: boolean } = {};
|
||||
|
||||
const collect = (node: FairyEditor.FObject) => {
|
||||
if (!node) return;
|
||||
const nid = (node as any).id as string;
|
||||
if (nid && !visited[nid]) {
|
||||
visited[nid] = true;
|
||||
ids.push(nid);
|
||||
}
|
||||
if (node instanceof FairyEditor.FComponent) {
|
||||
const cnt = (node as FairyEditor.FComponent).numChildren;
|
||||
for (let i = 0; i < cnt; i++) {
|
||||
const child = (node as FairyEditor.FComponent).GetChildAt(i);
|
||||
collect(child);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const docAny = activeDoc as any;
|
||||
if (docAny && docAny.content) collect(docAny.content);
|
||||
TweenSettings.cleanupDoc(packageName, docUrl, ids);
|
||||
} catch (err) {
|
||||
console.error('HierarchyChanged 自动清理失败', err);
|
||||
}
|
||||
};
|
||||
|
||||
// 订阅层级变化事件
|
||||
// @ts-ignore
|
||||
App.On(FairyEditor.EditorEvents.HierarchyChanged, onHierarchyChanged);
|
||||
|
||||
11
FGUIProject/plugins/whoot-tween/package.json
Normal file
11
FGUIProject/plugins/whoot-tween/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "WhootPlugins-Tween",
|
||||
"displayName": "Whoot unity 通用动效",
|
||||
"description": "Whoot前端框架FGUI扩展插件-通用动效",
|
||||
"version": "1.0",
|
||||
"author": {
|
||||
"name": "Tim"
|
||||
},
|
||||
"icon": "",
|
||||
"main": "main.js"
|
||||
}
|
||||
25
FGUIProject/plugins/whoot-tween/puerts.d.ts
vendored
Normal file
25
FGUIProject/plugins/whoot-tween/puerts.d.ts
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
declare module "puerts" {
|
||||
import {$Ref, $Task, System} from "csharp"
|
||||
|
||||
function $ref<T>(x? : T) : $Ref<T>;
|
||||
|
||||
function $unref<T>(x: $Ref<T>) : T;
|
||||
|
||||
function $set<T>(x: $Ref<T>, val:T) : void;
|
||||
|
||||
function $promise<T>(x: $Task<T>) : Promise<T>;
|
||||
|
||||
function $generic<T extends new (...args:any[]) => any> (genericType :T, ...genericArguments: (new (...args:any[]) => any)[]) : T;
|
||||
|
||||
function $typeof(x : new (...args:any[]) => any) : System.Type;
|
||||
|
||||
function $extension(c : Function, e: Function) : void;
|
||||
|
||||
function on(eventType: string, listener: Function, prepend?: boolean) : void;
|
||||
|
||||
function off(eventType: string, listener: Function) : void;
|
||||
|
||||
function emit(eventType: string, ...args:any[]) : boolean;
|
||||
}
|
||||
|
||||
declare function require(name: string): any;
|
||||
130
FGUIProject/plugins/whoot-tween/readme.md
Normal file
130
FGUIProject/plugins/whoot-tween/readme.md
Normal file
@@ -0,0 +1,130 @@
|
||||
## 自定义数据表单生成器[CustomAttributer]
|
||||
|
||||
- 编辑器版本:FairyGUI-Editor_2021.3.0
|
||||
- 一个可配置自定义数据表单生成器,支持组件和父级组件,本地&远程配置,内含9种自定义表单项。
|
||||
|
||||

|
||||
|
||||
### 如何配置表单
|
||||
修改本插件同目录下的config.json文件即可
|
||||
### 内置表单项
|
||||
```
|
||||
TEXTINPUT // 文本输入框
|
||||
TEXTAREA // 文字输入区
|
||||
COMBOBOX // 下拉框
|
||||
COLORINPUT // 颜色输入框
|
||||
NUMBERINPUT // 数字输入框
|
||||
SLIDER // 滑动块
|
||||
RESOURCEINPUT // 资源选择器
|
||||
RADIOBOX // 单选框
|
||||
SWITCH // 切换器
|
||||
```
|
||||
### 表单配置参数参考
|
||||
```
|
||||
{
|
||||
"remote": "", // 自定义远程路径
|
||||
"inspectors":[
|
||||
{
|
||||
"title": "自定义数据表单",
|
||||
"parent": false, // 修改的组件主体类型:true:父级|false:子级
|
||||
"pattern": "*", // 组件名称匹配,支持正则
|
||||
"mode": 1, // 插件模式:1【设置模式】|0【读取模式】(todo)
|
||||
"components": [
|
||||
{
|
||||
"type": "ComboBox",
|
||||
"id": 1001,
|
||||
"name": "属性一",
|
||||
"key":"ComboBox",
|
||||
"data": {
|
||||
"items": [
|
||||
"选项一",
|
||||
"选项二",
|
||||
"选项三"
|
||||
],
|
||||
"values": [
|
||||
"选项一",
|
||||
"选项二",
|
||||
"选项三"
|
||||
]
|
||||
},
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"type": "ColorInput",
|
||||
"name": "属性二",
|
||||
"key":"ColorInput",
|
||||
"id": 1002,
|
||||
"values": "#ffffff"
|
||||
},
|
||||
{
|
||||
"type": "Slider",
|
||||
"name": "属性三",
|
||||
"id": 1003,
|
||||
"key":"Slider",
|
||||
"value": 50,
|
||||
"data":{
|
||||
"min":0,
|
||||
"max":100
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "NumberInput",
|
||||
"name": "属性四",
|
||||
"key":"NumberInput",
|
||||
"id": 1004,
|
||||
"value": 50,
|
||||
"data":{
|
||||
"min":0,
|
||||
"max":100,
|
||||
"step":1
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ResourceInput",
|
||||
"name": "属性五",
|
||||
"key":"ResourceInput",
|
||||
"id": 1005,
|
||||
"value": ""
|
||||
},
|
||||
{
|
||||
"type": "RadioBox",
|
||||
"name": "属性六",
|
||||
"key":"RadioBox",
|
||||
"id": 1006,
|
||||
"value": 0,
|
||||
"data":{
|
||||
"items":["选项A","选项B"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Switch",
|
||||
"name": "属性七",
|
||||
"key":"Switch",
|
||||
"id": 1007,
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"type": "Textinput",
|
||||
"name": "属性八",
|
||||
"key":"Textinput",
|
||||
"id": 1008,
|
||||
"value": "默认内容"
|
||||
},
|
||||
{
|
||||
"type": "Textarea",
|
||||
"name": "属性九",
|
||||
"key":"Textarea",
|
||||
"id": 1009,
|
||||
"value": "默认内容"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### todo
|
||||
- [x] 多组件配置
|
||||
- [ ] 表单子项关联显隐
|
||||
- [ ] 【读取模式】一键复制组件属性
|
||||
13
FGUIProject/plugins/whoot-tween/tsconfig.json
Normal file
13
FGUIProject/plugins/whoot-tween/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "commonjs",
|
||||
"sourceMap": false,
|
||||
"typeRoots": [
|
||||
"./node_modules/@types"
|
||||
],
|
||||
"outDir": "./"
|
||||
},
|
||||
"include": ["./*"],
|
||||
"exclude": ["./node_modules/**/*"]
|
||||
}
|
||||
Reference in New Issue
Block a user