static void OnToolbarGUI() { if (m_icon_earth == null) { m_icon_earth = AssetDatabase.LoadAssetAtPath <Texture>("Packages/io.nekonya.tinax.i18n/Editor/Res/Icon/earth.png"); } GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent(m_icon_earth, "TinaX I18N"), EditorStyles.toolbarButton, GUILayout.MaxWidth(25), GUILayout.MaxHeight(20))) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Refresh Data"), false, () => { I18NEditorManager.RefreshData(); }); menu.ShowAsContext(); } if (!I18NEditorManager.EditorCurrentRegionName.IsNullOrEmpty()) { if (GUILayout.Button(I18NEditorManager.EditorCurrentRegionName, EditorStyles.toolbarPopup)) { string cur_name = I18NEditorManager.EditorCurrentRegionName; string[] region_names = I18NEditorManager.GetRegionNames(); GenericMenu _menu = new GenericMenu(); foreach (var item in region_names) { string name = item; _menu.AddItem(new GUIContent(name), (name == cur_name), () => { if (name != cur_name) { I18NEditorManager.RefreshDataByRegionName(name); if (Application.isPlaying) { if (XCore.MainInstance != null && XCore.MainInstance.IsRunning) { XCore.MainInstance.GetService <II18N>().UseRegionAsync(name, e => { if (e != null) { throw e; } }); } } } }); } _menu.ShowAsContext(); } } }
public override void OnInspectorGUI() { //I18N key EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("I18N Key", GUILayout.Width(65)); EditorGUILayout.PropertyField(this.serializedObject.FindProperty("I18NKey"), GUIContent.none); GUILayout.Button("Refresh", GUILayout.MaxWidth(55)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("I18N Group", GUILayout.Width(65)); EditorGUILayout.PropertyField(this.serializedObject.FindProperty("I18NGroup"), GUIContent.none); EditorGUILayout.EndHorizontal(); // 搜索 GUILayout.Space(10); if (!mShowSearchGUI) { if (GUILayout.Button("Search", GUILayout.MaxWidth(150))) { mShowSearchGUI = true; } } if (mShowSearchGUI) { if (mSearchIcon == null) { mSearchIcon = AssetDatabase.LoadAssetAtPath <Texture>("Packages/io.nekonya.tinax.i18n/Editor/Res/Icon/Search.png"); } if (mSelectIcon == null) { mSelectIcon = AssetDatabase.LoadAssetAtPath <Texture>("Packages/io.nekonya.tinax.i18n/Editor/Res/Icon/select.png"); } EditorGUILayout.BeginHorizontal(); mSearchText = EditorGUILayout.TextField(mSearchText, EditorStyles.toolbarSearchField); if (GUILayout.Button(new GUIContent(mSearchIcon, "Search"), GUILayout.MaxWidth(25), GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight))) { mSearchResult = I18NEditorManager.SearchKeyOrValue(mSearchText); } EditorGUILayout.EndHorizontal(); if (mSearchResult != null) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); if (mSearchResult.Count == 0) { GUILayout.Label("No Result, Please try to refresh data."); } else { var rect = EditorGUILayout.GetControlRect(); if (rect.width > 20) { max_width = rect.width; } mV2_Result = EditorGUILayout.BeginScrollView(mV2_Result, GUILayout.MaxHeight(200), GUILayout.MinHeight(40)); foreach (var item in mSearchResult) { GUILayout.Label(item.Key, EditorStyles.boldLabel); foreach (var kv in item.Value) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(kv.Key, GUILayout.MaxWidth((max_width - 45) / 2)); EditorGUILayout.LabelField("|" + kv.Value, GUILayout.MaxWidth((max_width - 45) / 2)); if (GUILayout.Button(new GUIContent(mSelectIcon, "select it"), GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight), GUILayout.MaxWidth(25))) { this.serializedObject.FindProperty("I18NKey").stringValue = kv.Key; this.serializedObject.FindProperty("I18NGroup").stringValue = item.Key; var text = ((TextLocalized)target).GetComponent <Text>(); if (text != null) { text.text = kv.Value; } } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndVertical(); } } this.serializedObject.ApplyModifiedProperties(); //base.OnInspectorGUI(); }