代码拉取完成,页面将自动刷新
import { FairyGUI, FairyEditor, System, UnityEngine } from 'csharp';
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("NBCCustomInspector", "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 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("NBCCustomInspector", "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
}
}
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);
// App.workspaceSettings.
let helpMenu = App.menu.GetSubMenu("help")
helpMenu.AddItem("NBC框架帮助", "NBCHelp", () => {
console.log("点击菜单===")
UnityEngine.Application.OpenURL("https://nobug.cn/")
})
// 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("NBCHelp")
}
export { runLanguageCustom, languageDestroy };
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。