71 lines
2.0 KiB
C#
71 lines
2.0 KiB
C#
using System;
|
|
using System.Linq;
|
|
using AlicizaX.Localization.Runtime;
|
|
using AlicizaX.Resource.Runtime;
|
|
using AlicizaX.Runtime;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityToolbarExtender;
|
|
|
|
namespace TEngine.Editor
|
|
{
|
|
public static class ToolbarStyles
|
|
{
|
|
public static readonly GUIStyle ToolBarButtonGuiStyle;
|
|
private const string ButtonStyleName = "Tab middle";
|
|
|
|
static ToolbarStyles()
|
|
{
|
|
ToolBarButtonGuiStyle = new GUIStyle(ButtonStyleName)
|
|
{
|
|
padding = new RectOffset(2, 8, 2, 2),
|
|
alignment = TextAnchor.MiddleCenter,
|
|
fontStyle = FontStyle.Bold
|
|
};
|
|
}
|
|
}
|
|
|
|
[InitializeOnLoad]
|
|
public class EditorLanguageMode
|
|
{
|
|
static EditorLanguageMode()
|
|
{
|
|
ToolbarExtender.LeftToolbarGUI.Add(OnToolbarGUI);
|
|
_languageIndex = EditorPrefs.GetInt(LocalizationComponent.PrefsKey, 0);
|
|
}
|
|
|
|
|
|
static GUIStyle _buttonGuiStyle;
|
|
|
|
private static readonly string[] _languageNames =
|
|
{
|
|
"Unspecified",
|
|
"ChineseSimplified ",
|
|
"English",
|
|
"Japanese",
|
|
};
|
|
|
|
private static int _languageIndex = 0;
|
|
public static int LanguageIndex => _languageIndex;
|
|
|
|
static void OnToolbarGUI()
|
|
{
|
|
EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
|
|
{
|
|
GUILayout.Space(400);
|
|
GUILayout.FlexibleSpace();
|
|
|
|
// 资源模式
|
|
int selectedIndex = EditorGUILayout.Popup(_languageIndex, _languageNames, ToolbarStyles.ToolBarButtonGuiStyle);
|
|
if (selectedIndex != _languageIndex)
|
|
{
|
|
Debug.Log($"更改编辑器语言 : {_languageNames[selectedIndex]}");
|
|
_languageIndex = selectedIndex;
|
|
EditorPrefs.SetInt(LocalizationComponent.PrefsKey, selectedIndex);
|
|
}
|
|
}
|
|
EditorGUI.EndDisabledGroup();
|
|
}
|
|
}
|
|
}
|