Imported UI Assets
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CreateAssetMenu(fileName = "New Localization Table", menuName = "Heat UI/Localization/New Language")]
|
||||
public class LocalizationLanguage : ScriptableObject
|
||||
{
|
||||
public LocalizationSettings localizationSettings;
|
||||
public string languageID;
|
||||
public string languageName;
|
||||
public string localizedName;
|
||||
public List<TableList> tableList = new List<TableList>();
|
||||
|
||||
[System.Serializable]
|
||||
public class TableList
|
||||
{
|
||||
public LocalizationTable table;
|
||||
public List<TableContent> tableContent = new List<TableContent>();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class TableContent
|
||||
{
|
||||
public string key;
|
||||
[TextArea] public string value;
|
||||
public AudioClip audioValue;
|
||||
public Sprite spriteValue;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b70abea511859e248a1cf2c44035e321
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- localizationSettings: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: d5cd25c6d1180024295fa5919baf502a, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizationLanguage.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,233 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(LocalizationLanguage))]
|
||||
[System.Serializable]
|
||||
public class LocalizationLanguageEditor : Editor
|
||||
{
|
||||
private LocalizationLanguage lTarget;
|
||||
private GUISkin customSkin;
|
||||
private LocalizationLanguage.TableList tempTable;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
lTarget = (LocalizationLanguage)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (customSkin == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Editor variables are missing. You can manually fix this by deleting " +
|
||||
"Heat UI > Resources folder and then re-import the package. \n\nIf you're still seeing this " +
|
||||
"dialog even after the re-import, contact me with this ID: " + UIManager.buildID, MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Info Header
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 8);
|
||||
|
||||
var localizationSettings = serializedObject.FindProperty("localizationSettings");
|
||||
var languageID = serializedObject.FindProperty("languageID");
|
||||
var languageName = serializedObject.FindProperty("languageName");
|
||||
var localizedName = serializedObject.FindProperty("localizedName");
|
||||
var tableList = serializedObject.FindProperty("tableList");
|
||||
|
||||
GUI.enabled = false;
|
||||
HeatUIEditorHandler.DrawProperty(languageID, customSkin, "Language ID");
|
||||
HeatUIEditorHandler.DrawProperty(languageName, customSkin, "Language Name");
|
||||
HeatUIEditorHandler.DrawProperty(localizedName, customSkin, "Localized Name");
|
||||
GUI.enabled = true;
|
||||
|
||||
// Settings Header
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 14);
|
||||
HeatUIEditorHandler.DrawPropertyCW(localizationSettings, customSkin, "Localization Settings", 130);
|
||||
|
||||
if (localizationSettings != null && GUILayout.Button("Show Localization Settings", customSkin.button))
|
||||
{
|
||||
Selection.activeObject = localizationSettings.objectReferenceValue;
|
||||
}
|
||||
|
||||
// Content Header
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Tables Header", 14);
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Import Table", customSkin.button)) { Import(); return; }
|
||||
if (GUILayout.Button("Export Table(s)", customSkin.button)) { Export(); return; }
|
||||
GUILayout.EndHorizontal();
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.PropertyField(tableList, new GUIContent("Table List (Debug Only)"), true);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
void Import()
|
||||
{
|
||||
string path = EditorUtility.OpenFilePanel("Select a file to import", "", "");
|
||||
|
||||
if (path.Length != 0)
|
||||
{
|
||||
string tempKey = null;
|
||||
bool checkForValue = false;
|
||||
bool processNewEntry = false;
|
||||
|
||||
LocalizationTable targetTable = null;
|
||||
List<LocalizationLanguage.TableContent> keysToBeAdded = new List<LocalizationLanguage.TableContent>();
|
||||
|
||||
foreach (string option in File.ReadLines(path))
|
||||
{
|
||||
if (option.Contains("[LanguageID] "))
|
||||
{
|
||||
string tempLangID = option.Replace("[LanguageID] ", "");
|
||||
checkForValue = false;
|
||||
|
||||
if (tempLangID != lTarget.languageID)
|
||||
{
|
||||
Debug.LogError("The language ID does not match with the language asset.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (option.Contains("[TableID] "))
|
||||
{
|
||||
string tempTableID = option.Replace("[TableID] ", "");
|
||||
checkForValue = false;
|
||||
|
||||
for (int i = 0; i < lTarget.tableList.Count; i++)
|
||||
{
|
||||
if (lTarget.tableList[i].table.tableID == tempTableID)
|
||||
{
|
||||
targetTable = lTarget.tableList[i].table;
|
||||
tempTable = lTarget.tableList[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (option.Contains("[StringKey] "))
|
||||
{
|
||||
tempKey = option.Replace("[StringKey] ", "");
|
||||
checkForValue = false;
|
||||
processNewEntry = false;
|
||||
}
|
||||
|
||||
else if (option.Contains("[Value] "))
|
||||
{
|
||||
if (tempTable == null)
|
||||
{
|
||||
Debug.LogError("Can't find the given table ID.");
|
||||
break;
|
||||
}
|
||||
|
||||
processNewEntry = true;
|
||||
|
||||
for (int i = 0; i < tempTable.tableContent.Count; i++)
|
||||
{
|
||||
if (tempTable.tableContent[i].key == tempKey)
|
||||
{
|
||||
processNewEntry = false;
|
||||
string tempValue = option.Replace("[Value] ", "");
|
||||
tempTable.tableContent[i].value = tempValue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (processNewEntry)
|
||||
{
|
||||
LocalizationLanguage.TableContent tempEntry = new LocalizationLanguage.TableContent();
|
||||
tempEntry.key = tempKey;
|
||||
tempEntry.value = option.Replace("[Value] ", "");
|
||||
keysToBeAdded.Add(tempEntry);
|
||||
}
|
||||
|
||||
checkForValue = true;
|
||||
}
|
||||
|
||||
else if (checkForValue == true && !option.Contains("[Value] ") && !string.IsNullOrEmpty(option))
|
||||
{
|
||||
if (tempTable == null)
|
||||
{
|
||||
Debug.LogError("Can't find the given table ID.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (processNewEntry) { keysToBeAdded[keysToBeAdded.Count - 1].value = keysToBeAdded[keysToBeAdded.Count - 1].value + "\n" + option; }
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < tempTable.tableContent.Count; i++)
|
||||
{
|
||||
if (tempTable.tableContent[i].key == tempKey)
|
||||
{
|
||||
tempTable.tableContent[i].value = tempTable.tableContent[i].value + "\n" + option;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(tempKey) && tempTable != null)
|
||||
{
|
||||
for (int i = 0; i < keysToBeAdded.Count; i++)
|
||||
{
|
||||
LocalizationTable.TableContent newTableEntry = new LocalizationTable.TableContent();
|
||||
newTableEntry.key = keysToBeAdded[i].key;
|
||||
targetTable.tableContent.Add(newTableEntry);
|
||||
|
||||
for (int x = 0; x < lTarget.localizationSettings.languages.Count; x++)
|
||||
{
|
||||
foreach (LocalizationLanguage.TableList list in lTarget.localizationSettings.languages[x].localizationLanguage.tableList)
|
||||
{
|
||||
if (list.table.tableID == tempTable.table.tableID)
|
||||
{
|
||||
list.tableContent.Add(keysToBeAdded[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EditorUtility.SetDirty(lTarget.localizationSettings.languages[x].localizationLanguage);
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log(keysToBeAdded.Count.ToString() + " new localization entries has been added.");
|
||||
Debug.Log(tempTable.table.tableID + " (table) has been successfully imported to " + lTarget.languageID);
|
||||
|
||||
EditorUtility.SetDirty(lTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Export()
|
||||
{
|
||||
for (int i = 0; i < lTarget.tableList.Count; i++)
|
||||
{
|
||||
string path = EditorUtility.SaveFilePanel("Export: " + lTarget.tableList[i].table.tableID, "", "Exported_" + lTarget.tableList[i].table.tableID + "(" + lTarget.languageID + ")", "txt");
|
||||
|
||||
if (path.Length != 0)
|
||||
{
|
||||
TextWriter tw = new StreamWriter(path, false);
|
||||
tw.WriteLine("[LanguageID] " + lTarget.languageID);
|
||||
tw.WriteLine("[TableID] " + lTarget.tableList[i].table.tableID);
|
||||
tw.WriteLine("\n------------------------------");
|
||||
|
||||
for (int x = 0; x < lTarget.tableList[i].table.tableContent.Count; x++)
|
||||
{
|
||||
tw.WriteLine("\n[StringKey] " + lTarget.tableList[i].table.tableContent[x].key);
|
||||
tw.Write("[Value] " + lTarget.tableList[i].tableContent[x].value + "\n");
|
||||
}
|
||||
|
||||
tw.Close();
|
||||
Debug.Log(lTarget.tableList[i].table.tableID + " has been exported to: " + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dedc906d85868e44b8f315819172167
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizationLanguageEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,115 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[DefaultExecutionOrder(-100)]
|
||||
[DisallowMultipleComponent]
|
||||
public class LocalizationManager : MonoBehaviour
|
||||
{
|
||||
// Static Instance
|
||||
public static LocalizationManager instance;
|
||||
|
||||
// Resources
|
||||
public UIManager UIManagerAsset;
|
||||
public HorizontalSelector languageSelector;
|
||||
|
||||
// Settings
|
||||
public bool setLanguageOnAwake = true;
|
||||
public bool updateItemsOnSet = true;
|
||||
public bool saveLanguageChanges = true;
|
||||
public static bool enableLogs = true;
|
||||
|
||||
// Helpers
|
||||
public string currentLanguage;
|
||||
public LocalizationLanguage currentLanguageAsset;
|
||||
public List<LocalizedObject> localizedItems = new List<LocalizedObject>();
|
||||
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
|
||||
if (UIManagerAsset == null) { UIManagerAsset = (UIManager)Resources.FindObjectsOfTypeAll(typeof(UIManager))[0]; }
|
||||
if (UIManagerAsset == null || !UIManagerAsset.enableLocalization) { return; }
|
||||
if (setLanguageOnAwake) { InitializeLanguage(); }
|
||||
|
||||
// Populate language selector
|
||||
if (languageSelector != null)
|
||||
{
|
||||
languageSelector.items.Clear();
|
||||
|
||||
for (int i = 0; i < UIManagerAsset.localizationSettings.languages.Count; i++)
|
||||
{
|
||||
languageSelector.CreateNewItem(UIManagerAsset.localizationSettings.languages[i].localizedName);
|
||||
|
||||
string tempID = UIManagerAsset.localizationSettings.languages[i].languageID;
|
||||
languageSelector.items[i].onItemSelect.AddListener(() => SetLanguage(tempID));
|
||||
|
||||
if (UIManagerAsset.localizationSettings.languages[i].localizationLanguage == currentLanguageAsset)
|
||||
{
|
||||
languageSelector.index = i;
|
||||
languageSelector.defaultIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
languageSelector.UpdateUI();
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeLanguage()
|
||||
{
|
||||
if (PlayerPrefs.HasKey(UIManager.localizationSaveKey)) { currentLanguage = PlayerPrefs.GetString(UIManager.localizationSaveKey); }
|
||||
else { currentLanguage = UIManagerAsset.localizationSettings.defaultLanguageID; }
|
||||
|
||||
SetLanguage(currentLanguage);
|
||||
}
|
||||
|
||||
public void SetLanguageByIndex(int index)
|
||||
{
|
||||
SetLanguage(UIManagerAsset.localizationSettings.languages[index].languageID);
|
||||
}
|
||||
|
||||
public void SetLanguage(string langID)
|
||||
{
|
||||
if (UIManagerAsset == null || !UIManagerAsset.enableLocalization)
|
||||
{
|
||||
UIManager.isLocalizationEnabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
currentLanguageAsset = null;
|
||||
|
||||
for (int i = 0; i < UIManagerAsset.localizationSettings.languages.Count; i++)
|
||||
{
|
||||
if (UIManagerAsset.localizationSettings.languages[i].languageID == langID) { currentLanguageAsset = UIManagerAsset.localizationSettings.languages[i].localizationLanguage; break; }
|
||||
else if (UIManagerAsset.localizationSettings.languages[i].languageName + " (" + UIManagerAsset.localizationSettings.languages[i].languageID + ")" == langID) { currentLanguageAsset = UIManagerAsset.localizationSettings.languages[i].localizationLanguage; break; }
|
||||
else if (UIManagerAsset.localizationSettings.languages[i].languageName == langID + ")") { currentLanguageAsset = UIManagerAsset.localizationSettings.languages[i].localizationLanguage; break; }
|
||||
}
|
||||
|
||||
if (currentLanguageAsset == null) { Debug.Log("<b>[Localization Manager]</b> No language named <b>" + langID + "</b> found.", this); return; }
|
||||
else { currentLanguage = currentLanguageAsset.languageName + " (" + currentLanguageAsset.languageID + ")"; }
|
||||
|
||||
if (updateItemsOnSet)
|
||||
{
|
||||
for (int i = 0; i < localizedItems.Count; i++)
|
||||
{
|
||||
if (localizedItems[i] == null) { localizedItems.RemoveAt(i); }
|
||||
else if (localizedItems[i].gameObject.activeInHierarchy && localizedItems[i].updateMode != LocalizedObject.UpdateMode.OnDemand) { localizedItems[i].UpdateItem(); }
|
||||
}
|
||||
}
|
||||
|
||||
if (saveLanguageChanges)
|
||||
{
|
||||
PlayerPrefs.SetString(UIManager.localizationSaveKey, currentLanguageAsset.languageID);
|
||||
}
|
||||
|
||||
UIManagerAsset.currentLanguage = currentLanguageAsset;
|
||||
UIManager.isLocalizationEnabled = true;
|
||||
}
|
||||
|
||||
public static void SetLanguageWithoutNotify(string langID)
|
||||
{
|
||||
PlayerPrefs.SetString(UIManager.localizationSaveKey, langID);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8709296e96cff814f90f27b8b791504c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- UIManagerAsset: {fileID: 11400000, guid: 98972d851a944df4a9402eac62a896e7, type: 2}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b9f229d37449a7e4a9d5466e48f8a6e2, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizationManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,46 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(LocalizationManager))]
|
||||
public class LocalizationManagerEditor : Editor
|
||||
{
|
||||
private LocalizationManager lmTarget;
|
||||
private GUISkin customSkin;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
lmTarget = (LocalizationManager)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var UIManagerAsset = serializedObject.FindProperty("UIManagerAsset");
|
||||
var languageSelector = serializedObject.FindProperty("languageSelector");
|
||||
|
||||
var setLanguageOnAwake = serializedObject.FindProperty("setLanguageOnAwake");
|
||||
var updateItemsOnSet = serializedObject.FindProperty("updateItemsOnSet");
|
||||
var saveLanguageChanges = serializedObject.FindProperty("saveLanguageChanges");
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(UIManagerAsset, customSkin, "UI Manager");
|
||||
HeatUIEditorHandler.DrawProperty(languageSelector, customSkin, "Language Selector");
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 10);
|
||||
setLanguageOnAwake.boolValue = HeatUIEditorHandler.DrawToggle(setLanguageOnAwake.boolValue, customSkin, "Set Language On Awake");
|
||||
updateItemsOnSet.boolValue = HeatUIEditorHandler.DrawToggle(updateItemsOnSet.boolValue, customSkin, "Update Items On Language Set");
|
||||
saveLanguageChanges.boolValue = HeatUIEditorHandler.DrawToggle(saveLanguageChanges.boolValue, customSkin, "Save Language Changes");
|
||||
LocalizationManager.enableLogs = HeatUIEditorHandler.DrawToggle(LocalizationManager.enableLogs, customSkin, "Enable Logs");
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88ca311fe1d389c47b9d31f121dd9e12
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizationManagerEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CreateAssetMenu(fileName = "New Localization Settings", menuName = "Heat UI/Localization/New Localization Settings")]
|
||||
public class LocalizationSettings : ScriptableObject
|
||||
{
|
||||
public List<Language> languages = new List<Language>();
|
||||
public List<Table> tables = new List<Table>();
|
||||
public string defaultLanguageID;
|
||||
public int defaultLanguageIndex;
|
||||
public bool enableExperimental = false;
|
||||
|
||||
// Global Variables
|
||||
public static string notInitializedText = "NOT_INITIALIZED";
|
||||
|
||||
[System.Serializable]
|
||||
public class Language
|
||||
{
|
||||
public string languageID = "en-US";
|
||||
public string languageName = "English";
|
||||
public string localizedName = "English (US)";
|
||||
public LocalizationLanguage localizationLanguage;
|
||||
#if UNITY_EDITOR
|
||||
[HideInInspector] public bool isExpanded;
|
||||
#endif
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Table
|
||||
{
|
||||
public string tableID;
|
||||
public LocalizationTable localizationTable;
|
||||
#if UNITY_EDITOR
|
||||
[HideInInspector] public bool isExpanded;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c100adba1f0bea4bb29ed7154d77640
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b9f229d37449a7e4a9d5466e48f8a6e2, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizationSettings.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,400 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(LocalizationSettings))]
|
||||
[System.Serializable]
|
||||
public class LocalizationSettingsEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private LocalizationSettings lsTarget;
|
||||
|
||||
private int defaultLanguageIndex;
|
||||
private List<string> languageList = new List<string>();
|
||||
|
||||
protected static float foldoutItemSpace = 2;
|
||||
protected static float foldoutTopSpace = 5;
|
||||
protected static float foldoutBottomSpace = 2;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
lsTarget = (LocalizationSettings)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
|
||||
// Sort by language name
|
||||
lsTarget.languages.Sort(SortByName);
|
||||
|
||||
// Refresh language dropdown
|
||||
RefreshLanguageDropdown();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (customSkin == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Editor variables are missing. You can manually fix this by deleting " +
|
||||
"Reach UI > Resources folder and then re-import the package. \n\nIf you're still seeing this " +
|
||||
"dialog even after the re-import, contact me with this ID: " + UIManager.buildID, MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Foldout style
|
||||
GUIStyle foldoutStyle = customSkin.FindStyle("UIM Foldout");
|
||||
|
||||
// Settings Header
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 8);
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
EditorGUILayout.LabelField(new GUIContent("Default Language"), customSkin.FindStyle("Text"), GUILayout.Width(120));
|
||||
|
||||
if (languageList.Count != 0)
|
||||
{
|
||||
var defaultLanguageIndex = serializedObject.FindProperty("defaultLanguageIndex");
|
||||
var defaultLanguageID = serializedObject.FindProperty("defaultLanguageID");
|
||||
|
||||
defaultLanguageIndex.intValue = EditorGUILayout.Popup(defaultLanguageIndex.intValue, languageList.ToArray());
|
||||
defaultLanguageID.stringValue = languageList[defaultLanguageIndex.intValue];
|
||||
}
|
||||
else { EditorGUILayout.HelpBox("There are no available languages.", MessageType.Info); }
|
||||
if (GUILayout.Button("Refresh List", customSkin.button)) { RefreshLanguageDropdown(); }
|
||||
|
||||
GUILayout.Space(1);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
#region Available Languages
|
||||
// Available Languages Header
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Languages Header", 14);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
// Draw languages
|
||||
for (int i = 0; i < lsTarget.languages.Count; i++)
|
||||
{
|
||||
// Draw Action Buttons
|
||||
GUILayout.Space(6);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (GUILayout.Button("Delete", customSkin.button, GUILayout.Width(50)))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Delete Language", "Are you sure you want to delete the following language: " + lsTarget.languages[i].languageName + " (" + lsTarget.languages[i].languageID + ")"
|
||||
+ "\n\nThis action deletes the specified language resources and cannot be undone.", "Yes", "Cancel"))
|
||||
{
|
||||
if (lsTarget.languages[i].localizationLanguage != null) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(lsTarget.languages[i].localizationLanguage)); }
|
||||
lsTarget.languages.Remove(lsTarget.languages[i]);
|
||||
RefreshLanguageDropdown();
|
||||
EditorUtility.SetDirty(lsTarget);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Space(5);
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// Start language item
|
||||
GUILayout.Space(-29);
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
|
||||
GUILayout.Space(4);
|
||||
GUILayout.BeginHorizontal();
|
||||
if (string.IsNullOrEmpty(lsTarget.languages[i].languageName) == true) { lsTarget.languages[i].isExpanded = EditorGUILayout.Foldout(lsTarget.languages[i].isExpanded, "Language #" + i.ToString(), true, foldoutStyle); }
|
||||
else { lsTarget.languages[i].isExpanded = EditorGUILayout.Foldout(lsTarget.languages[i].isExpanded, lsTarget.languages[i].languageName + " (" + lsTarget.languages[i].languageID + ")", true, foldoutStyle); }
|
||||
lsTarget.languages[i].isExpanded = GUILayout.Toggle(lsTarget.languages[i].isExpanded, new GUIContent(""), customSkin.FindStyle("Toggle Helper"));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// Start language content
|
||||
if (lsTarget.languages[i].isExpanded)
|
||||
{
|
||||
lsTarget.languages[i].languageID = EditorGUILayout.TextField("Language ID", lsTarget.languages[i].languageID);
|
||||
lsTarget.languages[i].languageName = EditorGUILayout.TextField("Language Name", lsTarget.languages[i].languageName);
|
||||
lsTarget.languages[i].localizedName = EditorGUILayout.TextField("Localized Name", lsTarget.languages[i].localizedName);
|
||||
lsTarget.languages[i].localizationLanguage = EditorGUILayout.ObjectField("Language Asset", lsTarget.languages[i].localizationLanguage, typeof(LocalizationLanguage), true) as LocalizationLanguage;
|
||||
|
||||
if (lsTarget.languages[i].localizationLanguage == null && GUILayout.Button("Create Language Asset", customSkin.button))
|
||||
{
|
||||
LocalizationLanguage newLocale = ScriptableObject.CreateInstance<LocalizationLanguage>();
|
||||
|
||||
// Check for the path
|
||||
string path = AssetDatabase.GetAssetPath(lsTarget);
|
||||
path = path.Replace("/" + lsTarget.name + ".asset", "").Trim();
|
||||
string fullPath = path.Replace("/" + lsTarget.name + ".asset", "").Trim() + "/Languages/";
|
||||
if (!Directory.Exists(fullPath)) { AssetDatabase.CreateFolder(path, "Languages"); }
|
||||
|
||||
// Create the new asset
|
||||
AssetDatabase.CreateAsset(newLocale, fullPath + lsTarget.languages[i].languageName + ".asset");
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
newLocale.localizationSettings = lsTarget;
|
||||
newLocale.languageID = lsTarget.languages[i].languageID;
|
||||
newLocale.name = lsTarget.languages[i].languageName;
|
||||
newLocale.localizedName = lsTarget.languages[i].localizedName;
|
||||
lsTarget.languages[i].localizationLanguage = newLocale;
|
||||
|
||||
// Add all available tables
|
||||
for (int x = 0; x < lsTarget.tables.Count; x++)
|
||||
{
|
||||
LocalizationLanguage.TableList newList = new LocalizationLanguage.TableList();
|
||||
newList.table = lsTarget.tables[x].localizationTable;
|
||||
lsTarget.languages[i].localizationLanguage.tableList.Add(newList);
|
||||
EditorUtility.SetDirty(lsTarget.languages[i].localizationLanguage);
|
||||
|
||||
for (int y = 0; y < lsTarget.tables[x].localizationTable.tableContent.Count; y++)
|
||||
{
|
||||
LocalizationLanguage.TableContent newContent = new LocalizationLanguage.TableContent();
|
||||
newContent.key = "Key #" + y;
|
||||
newList.tableContent.Add(newContent);
|
||||
}
|
||||
}
|
||||
|
||||
// Change the s.o. file name
|
||||
AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(newLocale), lsTarget.languages[i].languageName + " (" + lsTarget.languages[i].languageID + ")");
|
||||
newLocale.name = lsTarget.languages[i].languageName + " (" + lsTarget.languages[i].languageID + ")";
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
// Set dirty
|
||||
EditorUtility.FocusProjectWindow();
|
||||
EditorUtility.SetDirty(lsTarget);
|
||||
}
|
||||
|
||||
else if (lsTarget.languages[i].localizationLanguage != null && GUILayout.Button("Show Language Asset", customSkin.button))
|
||||
{
|
||||
Selection.activeObject = lsTarget.languages[i].localizationLanguage;
|
||||
}
|
||||
}
|
||||
|
||||
// Set localization settings for the items
|
||||
if (lsTarget.languages[i].localizationLanguage != null)
|
||||
{
|
||||
lsTarget.languages[i].localizationLanguage.localizationSettings = lsTarget;
|
||||
lsTarget.languages[i].localizationLanguage.languageID = lsTarget.languages[i].localizationLanguage.localizationSettings.languages[i].languageID;
|
||||
lsTarget.languages[i].localizationLanguage.languageName = lsTarget.languages[i].localizationLanguage.localizationSettings.languages[i].languageName;
|
||||
lsTarget.languages[i].localizationLanguage.localizedName = lsTarget.languages[i].localizationLanguage.localizationSettings.languages[i].localizedName;
|
||||
}
|
||||
|
||||
// End language item
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(-3);
|
||||
}
|
||||
|
||||
GUILayout.Space(2);
|
||||
|
||||
if (GUILayout.Button("+ New Language", customSkin.button))
|
||||
{
|
||||
LocalizationSettings.Language language = new LocalizationSettings.Language();
|
||||
language.languageID = "null";
|
||||
language.languageName = "New Language";
|
||||
language.isExpanded = false;
|
||||
lsTarget.languages.Add(language);
|
||||
|
||||
// Refresh language list
|
||||
RefreshLanguageDropdown();
|
||||
|
||||
EditorUtility.SetDirty(lsTarget);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Available Tables
|
||||
// Available Tables Header
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Tables Header", 14);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
// Draw tables
|
||||
for (int i = 0; i < lsTarget.tables.Count; i++)
|
||||
{
|
||||
// Draw Action Buttons
|
||||
GUILayout.Space(6);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (lsTarget.tables[i].localizationTable != null && GUILayout.Button("Edit", customSkin.button, GUILayout.Width(34)))
|
||||
{
|
||||
LocalizationTableWindow.ShowWindow(lsTarget, lsTarget.tables[i].localizationTable, i);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Delete", customSkin.button, GUILayout.Width(50)))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Delete Table", "Are you sure you want to delete the following table: " + lsTarget.tables[i].tableID
|
||||
+ "\n\nThis action deletes the specified table resources and cannot be undone.", "Yes", "Cancel"))
|
||||
{
|
||||
// Clear empty languages first
|
||||
for (int x = 0; x < lsTarget.languages.Count; x++)
|
||||
{
|
||||
for (int y = 0; y < lsTarget.languages[x].localizationLanguage.tableList.Count; y++)
|
||||
{
|
||||
if (lsTarget.languages[x].localizationLanguage.tableList[y].table == null)
|
||||
{
|
||||
lsTarget.languages[x].localizationLanguage.tableList.RemoveAt(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete from all existing langs if available
|
||||
if (lsTarget.tables[i].localizationTable != null)
|
||||
{
|
||||
for (int x = 0; x < lsTarget.languages.Count; x++)
|
||||
{
|
||||
if (lsTarget.languages[x].localizationLanguage == null)
|
||||
continue;
|
||||
|
||||
for (int y = 0; y < lsTarget.languages[x].localizationLanguage.tableList.Count; y++)
|
||||
{
|
||||
if (lsTarget.languages[x].localizationLanguage.tableList[y].table == lsTarget.tables[i].localizationTable)
|
||||
{
|
||||
lsTarget.languages[x].localizationLanguage.tableList.RemoveAt(y);
|
||||
EditorUtility.SetDirty(lsTarget.languages[x].localizationLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lsTarget.tables[i].localizationTable != null) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(lsTarget.tables[i].localizationTable)); }
|
||||
lsTarget.tables.Remove(lsTarget.tables[i]);
|
||||
EditorUtility.SetDirty(lsTarget);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Space(5);
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// Start table item
|
||||
GUILayout.Space(-29);
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
|
||||
GUILayout.Space(4);
|
||||
GUILayout.BeginHorizontal();
|
||||
if (string.IsNullOrEmpty(lsTarget.tables[i].tableID) == true) { lsTarget.tables[i].isExpanded = EditorGUILayout.Foldout(lsTarget.tables[i].isExpanded, "Table #" + i.ToString(), true, foldoutStyle); }
|
||||
else { lsTarget.tables[i].isExpanded = EditorGUILayout.Foldout(lsTarget.tables[i].isExpanded, lsTarget.tables[i].tableID, true, foldoutStyle); }
|
||||
lsTarget.tables[i].isExpanded = GUILayout.Toggle(lsTarget.tables[i].isExpanded, new GUIContent(""), customSkin.FindStyle("Toggle Helper"));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// Start table content
|
||||
if (lsTarget.tables[i].isExpanded)
|
||||
{
|
||||
lsTarget.tables[i].tableID = EditorGUILayout.TextField("Table ID", lsTarget.tables[i].tableID);
|
||||
lsTarget.tables[i].localizationTable = EditorGUILayout.ObjectField("Localization Table", lsTarget.tables[i].localizationTable, typeof(LocalizationTable), true) as LocalizationTable;
|
||||
|
||||
if (lsTarget.tables[i].localizationTable != null) { lsTarget.tables[i].localizationTable.tableID = lsTarget.tables[i].tableID; }
|
||||
if (lsTarget.tables[i].localizationTable == null && GUILayout.Button("+ Create Table Asset", customSkin.button))
|
||||
{
|
||||
LocalizationTable newTable = ScriptableObject.CreateInstance<LocalizationTable>();
|
||||
|
||||
// Check for the path
|
||||
string path = AssetDatabase.GetAssetPath(lsTarget);
|
||||
path = path.Replace("/" + lsTarget.name + ".asset", "").Trim();
|
||||
string fullPath = path.Replace("/" + lsTarget.name + ".asset", "").Trim() + "/Tables/";
|
||||
if (!Directory.Exists(fullPath)) { AssetDatabase.CreateFolder(path, "Tables"); }
|
||||
|
||||
// Create the new asset
|
||||
AssetDatabase.CreateAsset(newTable, fullPath + lsTarget.tables[i].tableID + ".asset");
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
// Change the s.o. values
|
||||
AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(newTable), lsTarget.tables[i].tableID);
|
||||
newTable.name = lsTarget.tables[i].tableID;
|
||||
newTable.tableID = lsTarget.tables[i].tableID;
|
||||
newTable.localizationSettings = lsTarget;
|
||||
lsTarget.tables[i].localizationTable = newTable;
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
// Add table to all available languages
|
||||
for (int x = 0; x < lsTarget.languages.Count; x++)
|
||||
{
|
||||
if (lsTarget.languages[x].localizationLanguage == null)
|
||||
continue;
|
||||
|
||||
LocalizationLanguage.TableList newList = new LocalizationLanguage.TableList();
|
||||
newList.table = newTable;
|
||||
lsTarget.languages[x].localizationLanguage.tableList.Add(newList);
|
||||
EditorUtility.SetDirty(lsTarget.languages[x].localizationLanguage);
|
||||
}
|
||||
|
||||
// Set dirty
|
||||
EditorUtility.FocusProjectWindow();
|
||||
EditorUtility.SetDirty(lsTarget);
|
||||
EditorUtility.SetDirty(newTable);
|
||||
}
|
||||
|
||||
else if (lsTarget.tables[i].localizationTable != null && GUILayout.Button("Show Table Asset", customSkin.button))
|
||||
{
|
||||
if (lsTarget.tables[i].localizationTable.localizationSettings == null) { lsTarget.tables[i].localizationTable.localizationSettings = lsTarget; }
|
||||
Selection.activeObject = lsTarget.tables[i].localizationTable;
|
||||
}
|
||||
}
|
||||
|
||||
// End table item
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(-3);
|
||||
}
|
||||
|
||||
GUILayout.Space(2);
|
||||
|
||||
if (lsTarget.tables.Count == 0)
|
||||
{
|
||||
EditorGUILayout.HelpBox("There are no localization tables to show.", MessageType.Info);
|
||||
|
||||
if (GUILayout.Button("+ New Table", customSkin.button))
|
||||
{
|
||||
LocalizationSettings.Table table = new LocalizationSettings.Table();
|
||||
table.tableID = "Table #" + lsTarget.tables.Count.ToString();
|
||||
lsTarget.tables.Add(table);
|
||||
EditorUtility.SetDirty(lsTarget);
|
||||
}
|
||||
}
|
||||
|
||||
else if (lsTarget.tables[lsTarget.tables.Count - 1].localizationTable != null && GUILayout.Button("+ New Table", customSkin.button))
|
||||
{
|
||||
LocalizationSettings.Table table = new LocalizationSettings.Table();
|
||||
table.tableID = "Table #" + lsTarget.tables.Count.ToString();
|
||||
lsTarget.tables.Add(table);
|
||||
EditorUtility.SetDirty(lsTarget);
|
||||
}
|
||||
|
||||
else if (lsTarget.tables[lsTarget.tables.Count - 1].localizationTable == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("In order to create a new table, you must first create a table asset for " + lsTarget.tables[lsTarget.tables.Count - 1].tableID + ".", MessageType.Warning);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Settings
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 14);
|
||||
var enableExperimental = serializedObject.FindProperty("enableExperimental");
|
||||
enableExperimental.boolValue = HeatUIEditorHandler.DrawToggle(enableExperimental.boolValue, customSkin, "Enable Experimental Features");
|
||||
#endregion
|
||||
|
||||
#region Support
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Support Header", 14);
|
||||
EditorGUILayout.HelpBox("Stuck or just getting started? You can check out the documentation page.", MessageType.Info);
|
||||
if (GUILayout.Button("Documentation", customSkin.button)) { Docs(); }
|
||||
#endregion
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
|
||||
private static int SortByName(LocalizationSettings.Language o1, LocalizationSettings.Language o2)
|
||||
{
|
||||
// Compare the names and sort by A to Z
|
||||
return o1.languageName.CompareTo(o2.languageName);
|
||||
}
|
||||
|
||||
private void RefreshLanguageDropdown()
|
||||
{
|
||||
for (int i = 0; i < lsTarget.languages.Count; i++)
|
||||
{
|
||||
languageList.Add(lsTarget.languages[i].languageName + " (" + lsTarget.languages[i].languageID + ")");
|
||||
if (string.IsNullOrEmpty(lsTarget.defaultLanguageID) == false && languageList[i] == lsTarget.defaultLanguageID) { defaultLanguageIndex = i; }
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(lsTarget.defaultLanguageID) == true && languageList.Count != 0) { lsTarget.defaultLanguageID = languageList[0]; }
|
||||
}
|
||||
|
||||
void Docs() { Application.OpenURL("https://docs.michsky.com/docs/heat-ui/localization"); }
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 730a3669931016246b4f80d655889daa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizationSettingsEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CreateAssetMenu(fileName = "New Localization Table", menuName = "Heat UI/Localization/New Localization Table")]
|
||||
public class LocalizationTable : ScriptableObject
|
||||
{
|
||||
public string tableID;
|
||||
public LocalizationSettings localizationSettings;
|
||||
public List<TableContent> tableContent = new List<TableContent>();
|
||||
|
||||
[System.Serializable]
|
||||
public class TableContent
|
||||
{
|
||||
public string key;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69fd36d4daedf43479c8f4036f7b2406
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- localizationSettings: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b9f229d37449a7e4a9d5466e48f8a6e2, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizationTable.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,54 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(LocalizationTable))]
|
||||
public class LocalizationTableEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private LocalizationTable ltTarget;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ltTarget = (LocalizationTable)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (customSkin == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Editor variables are missing. You can manually fix this by deleting " +
|
||||
"Heat UI > Resources folder and then re-import the package. \n\nIf you're still seeing this " +
|
||||
"dialog even after the re-import, contact me with this ID: " + UIManager.buildID, MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Settings Header
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 8);
|
||||
GUI.enabled = false;
|
||||
|
||||
var tableID = serializedObject.FindProperty("tableID");
|
||||
HeatUIEditorHandler.DrawProperty(tableID, customSkin, "Table ID");
|
||||
|
||||
var localizationSettings = serializedObject.FindProperty("localizationSettings");
|
||||
HeatUIEditorHandler.DrawProperty(localizationSettings, customSkin, "Localization Settings");
|
||||
|
||||
GUI.enabled = true;
|
||||
|
||||
if (ltTarget.localizationSettings != null && ltTarget.localizationSettings.languages.Count != 0 && GUILayout.Button("Edit Table", customSkin.button))
|
||||
{
|
||||
for (int i = 0; i < ltTarget.localizationSettings.languages[0].localizationLanguage.tableList.Count; i++)
|
||||
{
|
||||
if (ltTarget.localizationSettings.languages[0].localizationLanguage.tableList[i].table == ltTarget)
|
||||
LocalizationTableWindow.ShowWindow(ltTarget.localizationSettings, ltTarget, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c7ae862261a8e1459ca93d31412f189
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizationTableEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,269 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
public class LocalizationTableWindow : EditorWindow
|
||||
{
|
||||
static LocalizationTableWindow window;
|
||||
static LocalizationSettings localizationSettings;
|
||||
static LocalizationTable selectedTable;
|
||||
static int tableIndex;
|
||||
|
||||
private GUISkin customSkin;
|
||||
protected GUIStyle panelStyle;
|
||||
static GUIStyle langLabelStyle;
|
||||
static float textFieldWidth = 180;
|
||||
static float textFieldHeight = 80;
|
||||
static float itemSpacing = 3;
|
||||
private string searchString;
|
||||
Vector2 scrollPosition = Vector2.zero;
|
||||
|
||||
// Caching a table in case of compilation
|
||||
public LocalizationTable cachedTable;
|
||||
|
||||
public static void ShowWindow(LocalizationSettings settings, LocalizationTable table, int index)
|
||||
{
|
||||
window = GetWindow<LocalizationTableWindow>();
|
||||
window.minSize = new Vector2(600, 400);
|
||||
|
||||
// Replace variables
|
||||
localizationSettings = null;
|
||||
localizationSettings = settings;
|
||||
selectedTable = null;
|
||||
selectedTable = table;
|
||||
tableIndex = index;
|
||||
|
||||
// Set title
|
||||
var icon = Resources.Load<Texture>("LocalizationWindowIcon");
|
||||
GUIContent newTitle = new GUIContent("Localization Table (" + table.tableID + ")", icon);
|
||||
window.titleContent = newTitle;
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
// Initialize table and content
|
||||
if (cachedTable == null && selectedTable != null) { cachedTable = selectedTable; }
|
||||
if (langLabelStyle == null) { langLabelStyle = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter }; }
|
||||
if (EditorStyles.textArea.wordWrap == false) { EditorStyles.textArea.wordWrap = true; }
|
||||
if (localizationSettings == null || selectedTable == null)
|
||||
{
|
||||
if (cachedTable != null) { selectedTable = cachedTable; localizationSettings = selectedTable.localizationSettings; }
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("There's no selected table. You can reopen the table via Localization Settings or the table file.", MessageType.Info);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Top Bar
|
||||
GUILayout.Space(8);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(8);
|
||||
|
||||
searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSearchTextField"), GUILayout.Width(textFieldWidth + 24));
|
||||
if (!string.IsNullOrEmpty(searchString) && GUILayout.Button(new GUIContent("", "Clear search bar"), GUI.skin.FindStyle("ToolbarSearchCancelButton")))
|
||||
{
|
||||
searchString = "";
|
||||
GUI.FocusControl(null);
|
||||
}
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.LabelField("Table", GUILayout.Width(40));
|
||||
selectedTable = EditorGUILayout.ObjectField(selectedTable, typeof(LocalizationTable), true, GUILayout.Width(200)) as LocalizationTable;
|
||||
GUI.enabled = true;
|
||||
GUILayout.Space(8);
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// Horizontal line to separate stuff
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(8);
|
||||
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider, GUILayout.Height(14));
|
||||
GUILayout.Space(8);
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// Top indicators
|
||||
GUILayout.BeginScrollView(scrollPosition, GUIStyle.none, GUIStyle.none);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(27);
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("String Key"), langLabelStyle, GUILayout.Width(textFieldWidth));
|
||||
EditorGUILayout.LabelField("", GUI.skin.verticalSlider, GUILayout.Width(0));
|
||||
|
||||
for (int i = 0; i < localizationSettings.languages.Count; i++)
|
||||
{
|
||||
if (localizationSettings.languages[i].localizationLanguage == null)
|
||||
continue;
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent(localizationSettings.languages[i].languageName + " (" + localizationSettings.languages[i].languageID + ")")
|
||||
, langLabelStyle, GUILayout.Width(textFieldWidth));
|
||||
if (i != localizationSettings.languages.Count - 1) { EditorGUILayout.LabelField("", GUI.skin.verticalSlider, GUILayout.Width(0)); }
|
||||
}
|
||||
|
||||
GUILayout.Space(27);
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndScrollView();
|
||||
|
||||
// Custom panel
|
||||
panelStyle = new GUIStyle(GUI.skin.box);
|
||||
|
||||
// Scroll panel
|
||||
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true);
|
||||
GUILayout.BeginVertical(panelStyle);
|
||||
|
||||
for (int i = 0; i < selectedTable.tableContent.Count; i++)
|
||||
{
|
||||
// If search field is blank
|
||||
if (string.IsNullOrEmpty(searchString))
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button(new GUIContent("-", "Remove string key"), customSkin.button, GUILayout.Width(20), GUILayout.Height(textFieldHeight)))
|
||||
{
|
||||
Undo.RecordObject(this, "Removed localization string key");
|
||||
|
||||
for (int x = 0; x < localizationSettings.languages.Count; x++)
|
||||
{
|
||||
localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent.RemoveAt(i);
|
||||
EditorUtility.SetDirty(localizationSettings.languages[x].localizationLanguage);
|
||||
}
|
||||
|
||||
selectedTable.tableContent.RemoveAt(i);
|
||||
EditorUtility.SetDirty(selectedTable);
|
||||
GUILayout.EndScrollView();
|
||||
continue;
|
||||
}
|
||||
|
||||
selectedTable.tableContent[i].key = EditorGUILayout.TextArea(selectedTable.tableContent[i].key, GUILayout.Width(textFieldWidth), GUILayout.Height(textFieldHeight));
|
||||
EditorUtility.SetDirty(selectedTable);
|
||||
GUILayout.Space(itemSpacing);
|
||||
|
||||
for (int x = 0; x < localizationSettings.languages.Count; x++)
|
||||
{
|
||||
if (localizationSettings.languages[x].localizationLanguage == null || localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].table != selectedTable)
|
||||
continue;
|
||||
|
||||
if (localizationSettings.enableExperimental)
|
||||
{
|
||||
GUILayout.BeginVertical(GUILayout.Width(textFieldWidth));
|
||||
|
||||
localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].value = EditorGUILayout.TextArea(localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].value, EditorStyles.textArea, GUILayout.Width(textFieldWidth), GUILayout.Height(textFieldHeight - 20));
|
||||
localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].key = selectedTable.tableContent[i].key;
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
// GUILayout.Label("Audio Clip", GUILayout.Width(70));
|
||||
localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].audioValue = EditorGUILayout.ObjectField(localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].audioValue, typeof(AudioClip), true) as AudioClip;
|
||||
// GUILayout.Label("Sprite", GUILayout.Width(70));
|
||||
localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].spriteValue = EditorGUILayout.ObjectField(localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].spriteValue, typeof(Sprite), true) as Sprite;
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(itemSpacing);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].value = EditorGUILayout.TextArea(localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].value, EditorStyles.textArea, GUILayout.Width(textFieldWidth), GUILayout.Height(textFieldHeight));
|
||||
localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].key = selectedTable.tableContent[i].key;
|
||||
GUILayout.Space(itemSpacing);
|
||||
}
|
||||
|
||||
EditorUtility.SetDirty(localizationSettings.languages[x].localizationLanguage);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(itemSpacing);
|
||||
}
|
||||
|
||||
// If using search field
|
||||
else if (localizationSettings.languages[0].localizationLanguage.tableList[tableIndex].tableContent[i].key.ToLower().Contains(searchString.ToLower()))
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button(new GUIContent("-", "Remove string key"), customSkin.button, GUILayout.Width(20), GUILayout.Height(textFieldHeight)))
|
||||
{
|
||||
Undo.RecordObject(this, "Removed localization string key");
|
||||
|
||||
for (int x = 0; x < localizationSettings.languages.Count; x++)
|
||||
{
|
||||
localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent.RemoveAt(i);
|
||||
EditorUtility.SetDirty(localizationSettings.languages[x].localizationLanguage);
|
||||
}
|
||||
|
||||
selectedTable.tableContent.RemoveAt(i);
|
||||
EditorUtility.SetDirty(selectedTable);
|
||||
GUILayout.EndScrollView();
|
||||
continue;
|
||||
}
|
||||
|
||||
// To do later: Add key edit support while searching
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.TextArea(selectedTable.tableContent[i].key, GUILayout.Width(textFieldWidth), GUILayout.Height(textFieldHeight));
|
||||
GUI.enabled = true;
|
||||
GUILayout.Space(itemSpacing);
|
||||
|
||||
for (int x = 0; x < localizationSettings.languages.Count; x++)
|
||||
{
|
||||
if (localizationSettings.languages[x].localizationLanguage == null || localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].table != selectedTable)
|
||||
continue;
|
||||
|
||||
localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].value = EditorGUILayout.TextArea(localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].value, EditorStyles.textArea, GUILayout.Width(textFieldWidth), GUILayout.Height(textFieldHeight));
|
||||
GUILayout.Space(itemSpacing);
|
||||
localizationSettings.languages[x].localizationLanguage.tableList[tableIndex].tableContent[i].key = selectedTable.tableContent[i].key;
|
||||
EditorUtility.SetDirty(localizationSettings.languages[x].localizationLanguage);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(itemSpacing);
|
||||
}
|
||||
}
|
||||
|
||||
// Scroll Panel End
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
// New entry
|
||||
if (GUILayout.Button("+ Add New Table Entry", customSkin.button))
|
||||
{
|
||||
Undo.RecordObject(this, "Added localization string key");
|
||||
|
||||
LocalizationTable.TableContent tempContent = new LocalizationTable.TableContent();
|
||||
tempContent.key = "Key " + selectedTable.tableContent.Count.ToString();
|
||||
selectedTable.tableContent.Add(tempContent);
|
||||
EditorUtility.SetDirty(selectedTable);
|
||||
|
||||
for (int i = 0; i < localizationSettings.languages.Count; i++)
|
||||
{
|
||||
if (localizationSettings.languages[i].localizationLanguage == null)
|
||||
continue;
|
||||
|
||||
LocalizationLanguage.TableContent ltc = new LocalizationLanguage.TableContent();
|
||||
ltc.key = tempContent.key;
|
||||
localizationSettings.languages[i].localizationLanguage.tableList[tableIndex].table = selectedTable;
|
||||
localizationSettings.languages[i].localizationLanguage.tableList[tableIndex].tableContent.Add(ltc);
|
||||
EditorUtility.SetDirty(localizationSettings.languages[i].localizationLanguage);
|
||||
}
|
||||
|
||||
scrollPosition = new Vector2(scrollPosition.x, selectedTable.tableContent.Count * (textFieldHeight + itemSpacing));
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Open Settings", customSkin.button, GUILayout.Width(100)))
|
||||
{
|
||||
Selection.activeObject = localizationSettings;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c10cad8ff3d7d8e4dba9cbb552e15cde
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b9f229d37449a7e4a9d5466e48f8a6e2, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizationTableWindow.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,391 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Heat UI/Localization/Localized Object")]
|
||||
public class LocalizedObject : MonoBehaviour
|
||||
{
|
||||
// Resources
|
||||
public LocalizationSettings localizationSettings;
|
||||
public TextMeshProUGUI textObj;
|
||||
public AudioSource audioObj;
|
||||
public Image imageObj;
|
||||
|
||||
// Settings
|
||||
public int tableIndex = -1;
|
||||
public string localizationKey;
|
||||
public ObjectType objectType = ObjectType.TextMeshPro;
|
||||
public UpdateMode updateMode = UpdateMode.OnEnable;
|
||||
public bool rebuildLayoutOnUpdate;
|
||||
[SerializeField] private bool forceAddToManager = false;
|
||||
#if UNITY_EDITOR
|
||||
public bool showOutputOnEditor = true;
|
||||
#endif
|
||||
|
||||
// Events
|
||||
public LanguageChangedEvent onLanguageChanged = new LanguageChangedEvent();
|
||||
|
||||
[System.Serializable]
|
||||
public class LanguageChangedEvent : UnityEvent<string> { }
|
||||
|
||||
// Helpers
|
||||
public bool isInitialized = false;
|
||||
|
||||
public enum UpdateMode { OnEnable, OnDemand }
|
||||
public enum ObjectType { TextMeshPro, Custom, ComponentDriven, Audio, Image }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (LocalizationManager.instance != null && !LocalizationManager.instance.UIManagerAsset.enableLocalization)
|
||||
{
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
|
||||
InitializeItem();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (LocalizationManager.instance == null) { Destroy(this); return; }
|
||||
if (!isInitialized || LocalizationManager.instance.currentLanguageAsset == null) { return; }
|
||||
if (updateMode == UpdateMode.OnEnable) { UpdateItem(); }
|
||||
}
|
||||
|
||||
public void InitializeItem()
|
||||
{
|
||||
if (isInitialized)
|
||||
return;
|
||||
|
||||
if (LocalizationManager.instance == null)
|
||||
{
|
||||
UIManager tempUIM = (UIManager)Resources.FindObjectsOfTypeAll(typeof(UIManager))[0];
|
||||
if (tempUIM == null || !tempUIM.enableLocalization) { return; }
|
||||
|
||||
GameObject newLM = new GameObject("Localization Manager [Auto Generated]");
|
||||
newLM.AddComponent<LocalizationManager>();
|
||||
}
|
||||
|
||||
if (LocalizationManager.instance != null && !LocalizationManager.instance.UIManagerAsset.enableLocalization) { Destroy(this); return; }
|
||||
if (LocalizationManager.instance == null || LocalizationManager.instance.UIManagerAsset == null || !LocalizationManager.instance.UIManagerAsset.enableLocalization) { return; }
|
||||
if (forceAddToManager && !LocalizationManager.instance.localizedItems.Contains(this)) { LocalizationManager.instance.localizedItems.Add(this); }
|
||||
|
||||
if (objectType == ObjectType.TextMeshPro && textObj == null) { textObj = gameObject.GetComponent<TextMeshProUGUI>(); }
|
||||
else if (objectType == ObjectType.Audio && audioObj == null) { audioObj = gameObject.GetComponent<AudioSource>(); }
|
||||
else if (objectType == ObjectType.Image && imageObj == null) { imageObj = gameObject.GetComponent<Image>(); }
|
||||
|
||||
LocalizationManager.instance.localizedItems.Add(this);
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
public void ReInitializeItem()
|
||||
{
|
||||
isInitialized = false;
|
||||
InitializeItem();
|
||||
}
|
||||
|
||||
public void UpdateItem()
|
||||
{
|
||||
if (!isInitialized || LocalizationManager.instance == null || LocalizationManager.instance.currentLanguageAsset == null || LocalizationManager.instance.currentLanguageAsset.tableList.Count == 0)
|
||||
return;
|
||||
|
||||
if (objectType == ObjectType.TextMeshPro && textObj != null)
|
||||
{
|
||||
for (int i = 0; i < LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (localizationKey == LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].value))
|
||||
{
|
||||
if (LocalizationManager.enableLogs) { Debug.Log("<b>[Localized Object]</b> The specified key '" + localizationKey + "' could not be found or the output value is empty for " + LocalizationManager.instance.currentLanguageAsset.languageName + ".", this); }
|
||||
break;
|
||||
}
|
||||
|
||||
textObj.text = LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].value;
|
||||
onLanguageChanged.Invoke(LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (objectType == ObjectType.Audio && audioObj != null)
|
||||
{
|
||||
for (int i = 0; i < LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (localizationKey == LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].key)
|
||||
{
|
||||
if (LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].audioValue == null)
|
||||
{
|
||||
if (LocalizationManager.enableLogs) { Debug.Log("<b>[Localized Object]</b> The specified key '" + localizationKey + "' could not be found or the output value is empty for " + LocalizationManager.instance.currentLanguageAsset.languageName + ".", this); }
|
||||
break;
|
||||
}
|
||||
|
||||
audioObj.clip = LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].audioValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (objectType == ObjectType.Image && imageObj != null)
|
||||
{
|
||||
for (int i = 0; i < LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (localizationKey == LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].key)
|
||||
{
|
||||
if (LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].spriteValue == null)
|
||||
{
|
||||
if (LocalizationManager.enableLogs) { Debug.Log("<b>[Localized Object]</b> The specified key '" + localizationKey + "' could not be found or the output value is empty for " + LocalizationManager.instance.currentLanguageAsset.languageName + ".", this); }
|
||||
break;
|
||||
}
|
||||
|
||||
imageObj.sprite = LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].spriteValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (objectType == ObjectType.Custom || objectType == ObjectType.ComponentDriven)
|
||||
{
|
||||
for (int i = 0; i < LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (localizationKey == LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].key)
|
||||
{
|
||||
if (string.IsNullOrEmpty(LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].value))
|
||||
break;
|
||||
|
||||
onLanguageChanged.Invoke(LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rebuildLayoutOnUpdate && gameObject.activeInHierarchy) { StartCoroutine("RebuildLayout"); }
|
||||
}
|
||||
|
||||
public bool CheckLocalizationStatus()
|
||||
{
|
||||
if (!isInitialized) { InitializeItem(); }
|
||||
if (LocalizationManager.instance == null || LocalizationManager.instance.UIManagerAsset == null || !LocalizationManager.instance.UIManagerAsset.enableLocalization) { return false; }
|
||||
else { return true; }
|
||||
}
|
||||
|
||||
public string GetKeyOutput(string key)
|
||||
{
|
||||
string keyValue = null;
|
||||
bool keyFound = false;
|
||||
|
||||
if (LocalizationManager.instance != null && LocalizationManager.instance.currentLanguageAsset == null) { LocalizationManager.instance.InitializeLanguage(); }
|
||||
if (!isInitialized || LocalizationManager.instance == null || LocalizationManager.instance.currentLanguageAsset == null || LocalizationManager.instance.currentLanguageAsset.tableList.Count == 0)
|
||||
return LocalizationSettings.notInitializedText;
|
||||
|
||||
for (int i = 0; i < LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (key == LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].key)
|
||||
{
|
||||
keyValue = LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].value;
|
||||
keyFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (keyFound && string.IsNullOrEmpty(keyValue))
|
||||
{
|
||||
if (LocalizationManager.enableLogs == true) { Debug.Log("<b>[Localized Object]</b> The output value for '" + key + "' is empty in " + LocalizationManager.instance.currentLanguageAsset.languageName + ".", this); }
|
||||
return "EMPTY_KEY_IN_" + LocalizationManager.instance.currentLanguageAsset.languageID + ": " + key;
|
||||
}
|
||||
|
||||
else if (!keyFound)
|
||||
{
|
||||
if (LocalizationManager.enableLogs == true) { Debug.Log("<b>[Localized Object]</b> The specified key '" + key + "' could not be found in " + LocalizationManager.instance.currentLanguageAsset.languageName + ".", this); }
|
||||
return "MISSING_KEY_IN_" + LocalizationManager.instance.currentLanguageAsset.languageID + ": " + key;
|
||||
}
|
||||
|
||||
return keyValue;
|
||||
}
|
||||
|
||||
public AudioClip GetKeyOutputAudio(string key)
|
||||
{
|
||||
AudioClip keyValue = null;
|
||||
bool keyFound = false;
|
||||
|
||||
if (LocalizationManager.instance != null && LocalizationManager.instance.currentLanguageAsset == null) { LocalizationManager.instance.InitializeLanguage(); }
|
||||
if (!isInitialized || LocalizationManager.instance == null || LocalizationManager.instance.currentLanguageAsset == null || LocalizationManager.instance.currentLanguageAsset.tableList.Count == 0)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (key == LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].key)
|
||||
{
|
||||
keyValue = LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].audioValue;
|
||||
keyFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (keyFound && keyValue == null)
|
||||
{
|
||||
if (LocalizationManager.enableLogs) { Debug.Log("<b>[Localized Object]</b> The output value for '" + key + "' is empty in " + LocalizationManager.instance.currentLanguageAsset.languageName + ".", this); }
|
||||
return null;
|
||||
}
|
||||
|
||||
else if (!keyFound)
|
||||
{
|
||||
if (LocalizationManager.enableLogs) { Debug.Log("<b>[Localized Object]</b> The specified key '" + key + "' could not be found in " + LocalizationManager.instance.currentLanguageAsset.languageName + ".", this); }
|
||||
return null;
|
||||
}
|
||||
|
||||
return keyValue;
|
||||
}
|
||||
|
||||
public Sprite GetKeyOutputSprite(string key)
|
||||
{
|
||||
Sprite keyValue = null;
|
||||
bool keyFound = false;
|
||||
|
||||
if (LocalizationManager.instance != null && LocalizationManager.instance.currentLanguageAsset == null) { LocalizationManager.instance.InitializeLanguage(); }
|
||||
if (!isInitialized || LocalizationManager.instance == null || LocalizationManager.instance.currentLanguageAsset == null || LocalizationManager.instance.currentLanguageAsset.tableList.Count == 0)
|
||||
return null;
|
||||
|
||||
for (int i = 0; i < LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (key == LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].key)
|
||||
{
|
||||
keyValue = LocalizationManager.instance.currentLanguageAsset.tableList[tableIndex].tableContent[i].spriteValue;
|
||||
keyFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (keyFound && keyValue == null)
|
||||
{
|
||||
if (LocalizationManager.enableLogs) { Debug.Log("<b>[Localized Object]</b> The output value for '" + key + "' is empty in " + LocalizationManager.instance.currentLanguageAsset.languageName + ".", this); }
|
||||
return null;
|
||||
}
|
||||
|
||||
else if (!keyFound)
|
||||
{
|
||||
if (LocalizationManager.enableLogs) { Debug.Log("<b>[Localized Object]</b> The specified key '" + key + "' could not be found in " + LocalizationManager.instance.currentLanguageAsset.languageName + ".", this); }
|
||||
return null;
|
||||
}
|
||||
|
||||
return keyValue;
|
||||
}
|
||||
|
||||
public static string GetKeyOutput(string tableID, string tableKey)
|
||||
{
|
||||
UIManager tempUIM = (UIManager)Resources.FindObjectsOfTypeAll(typeof(UIManager))[0];
|
||||
|
||||
if (tempUIM == null || !tempUIM.enableLocalization)
|
||||
return null;
|
||||
|
||||
int tableIndex = -1;
|
||||
string keyValue = null;
|
||||
|
||||
for (int i = 0; i < tempUIM.currentLanguage.tableList.Count; i++)
|
||||
{
|
||||
if (tempUIM.currentLanguage.tableList[i].table.tableID == tableID)
|
||||
{
|
||||
tableIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tableIndex == -1) { return null; }
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < tempUIM.currentLanguage.tableList[tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (tempUIM.currentLanguage.tableList[tableIndex].tableContent[i].key == tableKey)
|
||||
{
|
||||
keyValue = tempUIM.currentLanguage.tableList[tableIndex].tableContent[i].value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return keyValue;
|
||||
}
|
||||
|
||||
public static AudioClip GetKeyOutputAudio(string tableID, string tableKey)
|
||||
{
|
||||
UIManager tempUIM = (UIManager)Resources.FindObjectsOfTypeAll(typeof(UIManager))[0];
|
||||
|
||||
if (tempUIM == null || !tempUIM.enableLocalization)
|
||||
return null;
|
||||
|
||||
int tableIndex = -1;
|
||||
AudioClip keyValue = null;
|
||||
|
||||
for (int i = 0; i < tempUIM.currentLanguage.tableList.Count; i++)
|
||||
{
|
||||
if (tempUIM.currentLanguage.tableList[i].table.tableID == tableID)
|
||||
{
|
||||
tableIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tableIndex == -1) { return null; }
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < tempUIM.currentLanguage.tableList[tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (tempUIM.currentLanguage.tableList[tableIndex].tableContent[i].key == tableKey)
|
||||
{
|
||||
keyValue = tempUIM.currentLanguage.tableList[tableIndex].tableContent[i].audioValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return keyValue;
|
||||
}
|
||||
|
||||
public static Sprite GetKeyOutputSprite(string tableID, string tableKey)
|
||||
{
|
||||
UIManager tempUIM = (UIManager)Resources.FindObjectsOfTypeAll(typeof(UIManager))[0];
|
||||
|
||||
if (tempUIM == null || !tempUIM.enableLocalization)
|
||||
return null;
|
||||
|
||||
int tableIndex = -1;
|
||||
Sprite keyValue = null;
|
||||
|
||||
for (int i = 0; i < tempUIM.currentLanguage.tableList.Count; i++)
|
||||
{
|
||||
if (tempUIM.currentLanguage.tableList[i].table.tableID == tableID)
|
||||
{
|
||||
tableIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tableIndex == -1) { return null; }
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < tempUIM.currentLanguage.tableList[tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (tempUIM.currentLanguage.tableList[tableIndex].tableContent[i].key == tableKey)
|
||||
{
|
||||
keyValue = tempUIM.currentLanguage.tableList[tableIndex].tableContent[i].spriteValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return keyValue;
|
||||
}
|
||||
|
||||
IEnumerator RebuildLayout()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.025f);
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(transform.parent.GetComponent<RectTransform>());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efc2fc407cf287745b4df9913e70134e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- localizationManager: {instanceID: 0}
|
||||
- localizationSettings: {fileID: 11400000, guid: 2cbd73cf0fc79bf4ab2e27e18b1ba7c8,
|
||||
type: 2}
|
||||
- textObj: {instanceID: 0}
|
||||
- audioObj: {instanceID: 0}
|
||||
- imageObj: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b9f229d37449a7e4a9d5466e48f8a6e2, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizedObject.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,257 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(LocalizedObject))]
|
||||
public class LocalizedObjectEditor : Editor
|
||||
{
|
||||
private LocalizedObject loTarget;
|
||||
private GUISkin customSkin;
|
||||
private int currentTab;
|
||||
|
||||
private List<string> tableList = new List<string>();
|
||||
private string searchString;
|
||||
private string tempValue;
|
||||
Vector2 scrollPosition = Vector2.zero;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
loTarget = (LocalizedObject)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
|
||||
if (loTarget.localizationSettings == null
|
||||
&& Resources.Load<UIManager>("Heat UI Manager") != null
|
||||
&& Resources.Load<UIManager>("Heat UI Manager").localizationSettings != null)
|
||||
{
|
||||
loTarget.localizationSettings = Resources.Load<UIManager>("Heat UI Manager").localizationSettings;
|
||||
}
|
||||
|
||||
if (loTarget.localizationSettings == null
|
||||
&& LocalizationManager.instance != null
|
||||
&& LocalizationManager.instance.UIManagerAsset != null
|
||||
&& LocalizationManager.instance.UIManagerAsset.localizationSettings != null)
|
||||
{
|
||||
loTarget.localizationSettings = LocalizationManager.instance.UIManagerAsset.localizationSettings;
|
||||
}
|
||||
|
||||
// Update language settings if it's driven by the manager
|
||||
else if (LocalizationManager.instance != null
|
||||
&& LocalizationManager.instance.UIManagerAsset != null
|
||||
&& LocalizationManager.instance.UIManagerAsset.localizationSettings != null)
|
||||
{
|
||||
loTarget.localizationSettings = LocalizationManager.instance.UIManagerAsset.localizationSettings;
|
||||
}
|
||||
|
||||
RefreshTableDropdown();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Localization Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[2];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Settings");
|
||||
|
||||
currentTab = HeatUIEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 1;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var localizationSettings = serializedObject.FindProperty("localizationSettings");
|
||||
var tableIndex = serializedObject.FindProperty("tableIndex");
|
||||
var objectType = serializedObject.FindProperty("objectType");
|
||||
var onLanguageChanged = serializedObject.FindProperty("onLanguageChanged");
|
||||
var rebuildLayoutOnUpdate = serializedObject.FindProperty("rebuildLayoutOnUpdate");
|
||||
var forceAddToManager = serializedObject.FindProperty("forceAddToManager");
|
||||
var updateMode = serializedObject.FindProperty("updateMode");
|
||||
var textObj = serializedObject.FindProperty("textObj");
|
||||
var audioObj = serializedObject.FindProperty("audioObj");
|
||||
var imageObj = serializedObject.FindProperty("imageObj");
|
||||
var localizationKey = serializedObject.FindProperty("localizationKey");
|
||||
|
||||
if (LocalizationManager.instance != null && LocalizationManager.instance.UIManagerAsset != null && LocalizationManager.instance.UIManagerAsset.enableLocalization == false)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Localization is disabled.", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
if (LocalizationManager.instance != null) { GUI.enabled = false; }
|
||||
HeatUIEditorHandler.DrawProperty(localizationSettings, customSkin, "Loc. Settings");
|
||||
GUI.enabled = true;
|
||||
|
||||
if (loTarget.localizationSettings == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Localization Settings is missing. Please assign a valid variable to use component features.", MessageType.Warning);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
return;
|
||||
}
|
||||
|
||||
HeatUIEditorHandler.DrawProperty(updateMode, customSkin, "Update Mode");
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(new GUIContent("Object Type"), customSkin.FindStyle("Text"), GUILayout.Width(120));
|
||||
EditorGUILayout.PropertyField(objectType, new GUIContent(""));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (loTarget.objectType == LocalizedObject.ObjectType.TextMeshPro)
|
||||
{
|
||||
HeatUIEditorHandler.DrawProperty(textObj, customSkin, "Text Object");
|
||||
if (Application.isPlaying == false
|
||||
&& loTarget.showOutputOnEditor == true
|
||||
&& string.IsNullOrEmpty(tempValue) == false
|
||||
&& loTarget.textObj != null
|
||||
&& GUILayout.Button(new GUIContent("Update Text"), customSkin.button))
|
||||
{
|
||||
loTarget.textObj.text = tempValue;
|
||||
loTarget.textObj.enabled = false;
|
||||
loTarget.textObj.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
else if (loTarget.objectType == LocalizedObject.ObjectType.Audio)
|
||||
{
|
||||
HeatUIEditorHandler.DrawProperty(audioObj, customSkin, "Audio Source");
|
||||
}
|
||||
|
||||
else if (loTarget.objectType == LocalizedObject.ObjectType.Image)
|
||||
{
|
||||
HeatUIEditorHandler.DrawProperty(imageObj, customSkin, "Image Object");
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (loTarget.localizationSettings.tables.Count != 0 && loTarget.tableIndex != -1)
|
||||
{
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Tables Header", 10);
|
||||
|
||||
// Selected table
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(new GUIContent("Selected Table"), customSkin.FindStyle("Text"), GUILayout.Width(120));
|
||||
tableIndex.intValue = EditorGUILayout.Popup(loTarget.tableIndex, tableList.ToArray());
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Edit Table"), customSkin.button))
|
||||
{
|
||||
LocalizationTableWindow.ShowWindow(loTarget.localizationSettings, loTarget.localizationSettings.tables[loTarget.tableIndex].localizationTable, loTarget.tableIndex);
|
||||
}
|
||||
|
||||
if (loTarget.objectType != LocalizedObject.ObjectType.ComponentDriven)
|
||||
{
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
EditorGUILayout.LabelField(new GUIContent("Localization Key"), customSkin.FindStyle("Text"), GUILayout.Width(120));
|
||||
EditorGUILayout.PropertyField(localizationKey, new GUIContent(""));
|
||||
loTarget.showOutputOnEditor = GUILayout.Toggle(loTarget.showOutputOnEditor, new GUIContent("", "See output"), GUILayout.Width(15), GUILayout.Height(18));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// Search for keys
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
EditorGUILayout.LabelField(new GUIContent("Search for keys in " + loTarget.localizationSettings.tables[loTarget.tableIndex].tableID), customSkin.FindStyle("Text"));
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSearchTextField"));
|
||||
if (!string.IsNullOrEmpty(searchString) && GUILayout.Button(new GUIContent("", "Clear search bar"), GUI.skin.FindStyle("ToolbarSearchCancelButton"))) { searchString = ""; GUI.FocusControl(null); }
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
{
|
||||
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUIStyle.none, GUI.skin.verticalScrollbar, GUILayout.Height(132));
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
for (int i = 0; i < loTarget.localizationSettings.languages[0].localizationLanguage.tableList[loTarget.tableIndex].tableContent.Count; i++)
|
||||
{
|
||||
if (loTarget.localizationSettings.languages[0].localizationLanguage.tableList[loTarget.tableIndex].tableContent[i].key.ToLower().Contains(searchString.ToLower()))
|
||||
{
|
||||
if (GUILayout.Button(new GUIContent(loTarget.localizationSettings.languages[0].localizationLanguage.tableList[loTarget.tableIndex].tableContent[i].key), customSkin.button))
|
||||
{
|
||||
loTarget.localizationKey = loTarget.localizationSettings.languages[0].localizationLanguage.tableList[loTarget.tableIndex].tableContent[i].key;
|
||||
searchString = "";
|
||||
GUI.FocusControl(null);
|
||||
EditorUtility.SetDirty(loTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (loTarget.showOutputOnEditor == true)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
for (int i = 0; i < loTarget.localizationSettings.languages.Count; i++)
|
||||
{
|
||||
for (int x = 0; x < loTarget.localizationSettings.languages[i].localizationLanguage.tableList[loTarget.tableIndex].tableContent.Count; x++)
|
||||
{
|
||||
if (loTarget.localizationSettings.languages[i].localizationLanguage.tableList[loTarget.tableIndex].tableContent[x].key == loTarget.localizationKey)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(new GUIContent("[" + loTarget.localizationSettings.languages[i].languageID + "] " +
|
||||
loTarget.localizationSettings.languages[i].localizationLanguage.tableList[loTarget.tableIndex].tableContent[x].value), customSkin.FindStyle("Text"));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
// Used for Update Text button
|
||||
tempValue = loTarget.localizationSettings.languages[loTarget.localizationSettings.defaultLanguageIndex].localizationLanguage.tableList[loTarget.tableIndex].tableContent[x].value;
|
||||
}
|
||||
}
|
||||
}
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
else if (loTarget.localizationSettings.tables.Count != 0 && loTarget.tableIndex == -1) { RefreshTableDropdown(); }
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onLanguageChanged, new GUIContent("On Language Changed"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
rebuildLayoutOnUpdate.boolValue = HeatUIEditorHandler.DrawToggle(rebuildLayoutOnUpdate.boolValue, customSkin, "Rebuild Layout On Update", "Force to rebuild layout on item update to prevent visual glitches.");
|
||||
forceAddToManager.boolValue = HeatUIEditorHandler.DrawToggle(forceAddToManager.boolValue, customSkin, "Force Add To Manager", "Force to add this component to the manager on awake.");
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
|
||||
private void RefreshTableDropdown()
|
||||
{
|
||||
if (loTarget.localizationSettings == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < loTarget.localizationSettings.tables.Count; i++)
|
||||
{
|
||||
if (loTarget.localizationSettings.tables[i].localizationTable != null)
|
||||
{
|
||||
tableList.Add(loTarget.localizationSettings.tables[i].tableID);
|
||||
}
|
||||
}
|
||||
|
||||
if (loTarget.localizationSettings.tables.Count == 0) { loTarget.tableIndex = -1; }
|
||||
else if (loTarget.tableIndex > loTarget.localizationSettings.tables.Count - 1) { loTarget.tableIndex = 0; }
|
||||
else if (loTarget.tableIndex == -1 && loTarget.localizationSettings.tables.Count != 0) { loTarget.tableIndex = 0; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2937926259f6d74cbde8f5c85acc754
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/Localization/LocalizedObjectEditor.cs
|
||||
uploadId: 629893
|
Reference in New Issue
Block a user