2025-08-01 19:32:29 +08:00
|
|
|
using System;
|
2025-09-23 12:05:22 +08:00
|
|
|
using System.Linq;
|
2025-08-01 19:32:29 +08:00
|
|
|
using AlicizaX.Localization.Runtime;
|
|
|
|
|
using AlicizaX;
|
2025-09-23 12:05:22 +08:00
|
|
|
using AlicizaX.Localization.Editor;
|
2025-08-01 19:32:29 +08:00
|
|
|
using Paps.UnityToolbarExtenderUIToolkit;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
|
|
|
|
[MainToolbarElement("LocalizationDropdownField", alignment: ToolbarAlign.Right, order: 0)]
|
|
|
|
|
public class LocalizationDropdownField : IMGUIContainer
|
|
|
|
|
{
|
|
|
|
|
private static GUIContent appConfigBtContent;
|
|
|
|
|
|
|
|
|
|
private static string[] _languageTypeNames;
|
|
|
|
|
|
|
|
|
|
public void InitializeElement()
|
|
|
|
|
{
|
2025-09-23 12:05:22 +08:00
|
|
|
_languageTypeNames = LocalizationConfiguration.Instance.LanguageTypeNames.ToArray();
|
2025-08-01 19:32:29 +08:00
|
|
|
|
|
|
|
|
appConfigBtContent =
|
|
|
|
|
EditorGUIUtility.TrTextContentWithIcon("", "",
|
|
|
|
|
"Settings");
|
|
|
|
|
onGUIHandler = MyGUIMethod;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MyGUIMethod()
|
|
|
|
|
{
|
|
|
|
|
GUILayout.BeginHorizontal();
|
2025-09-23 12:05:22 +08:00
|
|
|
string title = GetPrefsStr();
|
2025-08-01 19:32:29 +08:00
|
|
|
appConfigBtContent.text = title;
|
|
|
|
|
if (EditorGUILayout.DropdownButton(appConfigBtContent, FocusType.Passive, EditorStyles.toolbarPopup, GUILayout.MaxWidth(120)))
|
|
|
|
|
{
|
|
|
|
|
DrawEditorToolDropdownMenus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUILayout.Space(5);
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void DrawEditorToolDropdownMenus()
|
|
|
|
|
{
|
2025-09-23 12:05:22 +08:00
|
|
|
string langaugeName = GetPrefsStr();
|
2025-08-01 19:32:29 +08:00
|
|
|
GenericMenu popMenu = new GenericMenu();
|
|
|
|
|
for (int i = 0; i < _languageTypeNames.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var toolAttr = _languageTypeNames[i];
|
2025-09-23 12:05:22 +08:00
|
|
|
var selected = langaugeName == toolAttr;
|
|
|
|
|
popMenu.AddItem(new GUIContent(toolAttr), selected, menuIdx => { ClickToolsSubmenu(toolAttr); }, toolAttr);
|
2025-08-01 19:32:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
popMenu.ShowAsContext();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 12:05:22 +08:00
|
|
|
static void ClickToolsSubmenu(string langaugeName)
|
2025-08-01 19:32:29 +08:00
|
|
|
{
|
2025-09-23 12:05:22 +08:00
|
|
|
EditorPrefs.SetString(LocalizationComponent.PrefsKey, langaugeName);
|
|
|
|
|
Debug.Log(langaugeName);
|
2025-08-01 19:32:29 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-23 12:05:22 +08:00
|
|
|
static string GetPrefsStr()
|
2025-08-01 19:32:29 +08:00
|
|
|
{
|
2025-09-23 12:05:22 +08:00
|
|
|
return EditorPrefs.GetString(LocalizationComponent.PrefsKey, "None");
|
2025-08-01 19:32:29 +08:00
|
|
|
}
|
|
|
|
|
}
|