首次提交
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;
|
||||
}
|
||||
115
FGUIProject/plugins/nbc-puerts-plugins/GenCodeCustomInspector.js
Normal file
115
FGUIProject/plugins/nbc-puerts-plugins/GenCodeCustomInspector.js
Normal file
@@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runGenCodeCustom = void 0;
|
||||
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)
|
||||
}
|
||||
exports.runGenCodeCustom = runGenCodeCustom;
|
||||
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();
|
||||
|
||||
483
FGUIProject/plugins/nbc-puerts-plugins/GenCode_CSharp.js
Normal file
483
FGUIProject/plugins/nbc-puerts-plugins/GenCode_CSharp.js
Normal file
@@ -0,0 +1,483 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.genCSCode = void 0;
|
||||
var FairyEditor = CS.FairyEditor;
|
||||
var System = CS.System;
|
||||
const CodeWriter_1 = require("./CodeWriter");
|
||||
const GenCodeSettings_1 = require("./GenCodeSettings");
|
||||
const LanguageSettings_1 = require("./LanguageSettings");
|
||||
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 + "未配置导出,忽略");
|
||||
}
|
||||
}
|
||||
genBinder(codePkgName, componentClassNameArr);
|
||||
genLanguage();
|
||||
}
|
||||
exports.genCSCode = genCSCode;
|
||||
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);");
|
||||
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();
|
||||
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('public override string UIPackName => "%s";', codePkgName);
|
||||
writer.writeln('public override string UIResName => "%s";', classInfo.res.name);
|
||||
writer.writeln();
|
||||
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 class %s', binderName);
|
||||
writer.startBlock();
|
||||
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);
|
||||
}
|
||||
581
FGUIProject/plugins/nbc-puerts-plugins/GenCode_CSharp.ts
Normal file
581
FGUIProject/plugins/nbc-puerts-plugins/GenCode_CSharp.ts
Normal file
@@ -0,0 +1,581 @@
|
||||
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'
|
||||
|
||||
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 + "未配置导出,忽略")
|
||||
}
|
||||
}
|
||||
|
||||
genBinder(codePkgName, componentClassNameArr);
|
||||
genLanguage();
|
||||
}
|
||||
|
||||
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);");
|
||||
|
||||
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();
|
||||
|
||||
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('public override string UIPackName => "%s";', codePkgName);
|
||||
writer.writeln('public override string UIResName => "%s";', classInfo.res.name);
|
||||
writer.writeln();
|
||||
|
||||
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 class %s', binderName);
|
||||
writer.startBlock();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
export { genCSCode };
|
||||
@@ -0,0 +1,194 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.languageDestroy = exports.runLanguageCustom = void 0;
|
||||
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"
|
||||
}
|
||||
exports.runLanguageCustom = runLanguageCustom;
|
||||
function languageDestroy() {
|
||||
let helpMenu = App.menu.GetSubMenu("help");
|
||||
helpMenu.RemoveItem("WhootHelp");
|
||||
}
|
||||
exports.languageDestroy = languageDestroy;
|
||||
@@ -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
36
FGUIProject/plugins/nbc-puerts-plugins/main.js
Normal file
36
FGUIProject/plugins/nbc-puerts-plugins/main.js
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
// //FYI: https://github.com/Tencent/puerts/blob/master/doc/unity/manual.md
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.onDestroy = exports.onPublish = void 0;
|
||||
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);
|
||||
}
|
||||
exports.onPublish = onPublish;
|
||||
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)
|
||||
}
|
||||
exports.onDestroy = onDestroy;
|
||||
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/**/*"]
|
||||
}
|
||||
Reference in New Issue
Block a user