145 lines
5.3 KiB
C#
145 lines
5.3 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using AlicizaX.Editor;
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using UnityEditor.Callbacks;
|
|
|
|
namespace AlicizaX.Localization.Editor
|
|
{
|
|
[CustomEditor(typeof(GameLocaizationTable))]
|
|
internal class GameLocaizationTableEditor : InspectorEditor<GameLocaizationTable>
|
|
{
|
|
|
|
[OnOpenAsset]
|
|
public static bool OnOpenAsset(int instanceId, int line)
|
|
|
|
{
|
|
var obj = EditorUtility.InstanceIDToObject(instanceId);
|
|
var asset = obj as GameLocaizationTable;
|
|
|
|
if (asset == null) return false;
|
|
string path = AssetDatabase.GetAssetPath(asset);
|
|
EditorPrefs.SetString("LastSelectedGameLocaizationTable", path);
|
|
OpenLocalizationEditor();
|
|
return true;
|
|
}
|
|
|
|
|
|
public override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
EditorDrawing.DrawInspectorHeader(new GUIContent("Game Localization Table"), Target);
|
|
EditorGUILayout.Space();
|
|
serializedObject.Update();
|
|
{
|
|
EditorGUILayout.HelpBox("You can edit this language in the Game Localization Table Editor window.", MessageType.Info);
|
|
EditorGUILayout.Space();
|
|
|
|
using (new EditorDrawing.BorderBoxScope(new GUIContent("GenCode"), roundedBox: false))
|
|
{
|
|
Properties.Draw("GenerateScriptCodePath", new GUIContent("File Path"));
|
|
}
|
|
}
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
|
using (new EditorDrawing.BorderBoxScope(new GUIContent("Languages"), roundedBox: false))
|
|
{
|
|
if (Target.Languages.Count > 0)
|
|
{
|
|
using (new EditorGUI.DisabledGroupScope(true))
|
|
{
|
|
foreach (var lang in Target.Languages)
|
|
{
|
|
string name = lang.LanguageName.Or("Unknown");
|
|
EditorGUILayout.ObjectField(new GUIContent(name), lang, typeof(LocalizationLanguage), false);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EditorGUILayout.HelpBox("There are currently no languages available, open the localization editor and add new languages.", MessageType.Info);
|
|
}
|
|
}
|
|
|
|
EditorGUILayout.Space();
|
|
EditorGUILayout.BeginHorizontal();
|
|
{
|
|
GUILayout.FlexibleSpace();
|
|
{
|
|
if (GUILayout.Button("Open Localization Editor", GUILayout.Width(180f), GUILayout.Height(25)))
|
|
{
|
|
string path = AssetDatabase.GetAssetPath(target);
|
|
EditorPrefs.SetString("LastSelectedGameLocaizationTable", path);
|
|
OpenLocalizationEditor();
|
|
}
|
|
|
|
if (GUILayout.Button("Gen Code", GUILayout.Width(180f), GUILayout.Height(25)))
|
|
{
|
|
LocalizationWindowUtility.GenerateCode(Target);
|
|
}
|
|
}
|
|
GUILayout.FlexibleSpace();
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
|
|
[MenuItem("Tools/AlicizaX/Localization/Open Localization Editor")]
|
|
private static void OpenLocalizationEditor()
|
|
{
|
|
EditorWindow window = EditorWindow.GetWindow<LocalizationTableWindow>(false, "Localization Editor", true);
|
|
window.minSize = new(1000, 500);
|
|
window.Show();
|
|
}
|
|
|
|
[MenuItem("Tools/AlicizaX/Localization/Open Localization ProjectSetting")]
|
|
public static void OpenSettings()
|
|
{
|
|
SettingsService.OpenProjectSettings("Project/Localization Settings");
|
|
}
|
|
|
|
|
|
[MenuItem("Tools/AlicizaX/Localization/Create Localization Table")]
|
|
private static void CreateLocalizationTable()
|
|
{
|
|
string path = "Assets/Localization/";
|
|
string fileName = "LocalizationTable.asset";
|
|
string finalPath = Path.Combine(path, fileName);
|
|
|
|
GameLocaizationTable table = ScriptableObject.CreateInstance<GameLocaizationTable>();
|
|
|
|
if (!Directory.Exists(path))
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
}
|
|
|
|
AssetDatabase.CreateAsset(table, finalPath);
|
|
EditorUtility.SetDirty(table);
|
|
AssetDatabase.SaveAssets();
|
|
AssetDatabase.Refresh();
|
|
|
|
table.TableSheet = new List<GameLocaizationTable.TableData>();
|
|
IReadOnlyList<string> languageTypes = LocalizationConfiguration.Instance.LanguageTypeNames;
|
|
|
|
for (int i = 0; i < languageTypes.Count; i++)
|
|
{
|
|
LocalizationLanguage asset = ScriptableObject.CreateInstance<LocalizationLanguage>();
|
|
asset.name = languageTypes[i];
|
|
asset.LanguageName = languageTypes[i];
|
|
asset.Strings = new List<LocalizationLanguage.LocalizationString>();
|
|
table.Languages.Add(asset);
|
|
AssetDatabase.AddObjectToAsset(asset, table);
|
|
EditorUtility.SetDirty(asset);
|
|
}
|
|
|
|
EditorUtility.SetDirty(table);
|
|
AssetDatabase.SaveAssets();
|
|
}
|
|
}
|
|
}
|