diff options
Diffstat (limited to 'Assets')
| -rw-r--r-- | Assets/Resources.meta | 8 | ||||
| -rw-r--r-- | Assets/Resources/localisation.csv | 3 | ||||
| -rw-r--r-- | Assets/Resources/localisation.csv.meta | 7 | ||||
| -rw-r--r-- | Assets/Scenes/Main Menu/MainMenu.unity | 58 | ||||
| -rw-r--r-- | Assets/Scripts/Localisation.meta | 8 | ||||
| -rw-r--r-- | Assets/Scripts/Localisation/CSVLoader.cs | 68 | ||||
| -rw-r--r-- | Assets/Scripts/Localisation/CSVLoader.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/Localisation/LocalisationSystem.cs | 54 | ||||
| -rw-r--r-- | Assets/Scripts/Localisation/LocalisationSystem.cs.meta | 11 | ||||
| -rw-r--r-- | Assets/Scripts/Localisation/TextLocaliserUI.cs | 21 | ||||
| -rw-r--r-- | Assets/Scripts/Localisation/TextLocaliserUI.cs.meta | 11 |
11 files changed, 255 insertions, 5 deletions
diff --git a/Assets/Resources.meta b/Assets/Resources.meta new file mode 100644 index 0000000..8915759 --- /dev/null +++ b/Assets/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c2362ff5e64c1bc429c8e562e156ab66 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/localisation.csv b/Assets/Resources/localisation.csv new file mode 100644 index 0000000..33e3b51 --- /dev/null +++ b/Assets/Resources/localisation.csv @@ -0,0 +1,3 @@ +"key","en","fr" +"game_title","Unicity","Unicity" +"play_button","Play","Jouer"
\ No newline at end of file diff --git a/Assets/Resources/localisation.csv.meta b/Assets/Resources/localisation.csv.meta new file mode 100644 index 0000000..22aa3c3 --- /dev/null +++ b/Assets/Resources/localisation.csv.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5a7b08a33ea9739489e608ec1514514e +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Main Menu/MainMenu.unity b/Assets/Scenes/Main Menu/MainMenu.unity index d5502a1..9dd0bcc 100644 --- a/Assets/Scenes/Main Menu/MainMenu.unity +++ b/Assets/Scenes/Main Menu/MainMenu.unity @@ -137,7 +137,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &17355103 RectTransform: m_ObjectHideFlags: 0 @@ -520,6 +520,25 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 242390865} m_CullTransparentMesh: 0 +--- !u!1 &501625860 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 8340192342033218831, guid: 83359716712d3c04293cf99088933eb6, + type: 3} + m_PrefabInstance: {fileID: 8754154739295469120} + m_PrefabAsset: {fileID: 0} +--- !u!114 &501625861 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 501625860} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7c6a2fc696577634c999293f25c45550, type: 3} + m_Name: + m_EditorClassIdentifier: + key: play_button --- !u!1 &604245000 stripped GameObject: m_CorrespondingSourceObject: {fileID: 8754154740269184898, guid: 83359716712d3c04293cf99088933eb6, @@ -1216,6 +1235,7 @@ GameObject: - component: {fileID: 1244813969} - component: {fileID: 1244813971} - component: {fileID: 1244813970} + - component: {fileID: 1244813972} m_Layer: 5 m_Name: Title m_TagString: Untagged @@ -1262,7 +1282,7 @@ MonoBehaviour: m_Calls: [] m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, Unity.ugui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - m_text: Unicity + m_text: not localised m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: fa623acb39bd0fa47807173407e82458, type: 2} m_sharedMaterial: {fileID: 3933269349784766730, guid: fa623acb39bd0fa47807173407e82458, @@ -1332,10 +1352,10 @@ MonoBehaviour: m_margin: {x: 0, y: 0, z: -2.88316, w: 0} m_textInfo: textComponent: {fileID: 1244813970} - characterCount: 7 + characterCount: 13 spriteCount: 0 - spaceCount: 0 - wordCount: 1 + spaceCount: 1 + wordCount: 2 linkCount: 0 lineCount: 1 pageCount: 1 @@ -1363,6 +1383,19 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1244813968} m_CullTransparentMesh: 0 +--- !u!114 &1244813972 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1244813968} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7c6a2fc696577634c999293f25c45550, type: 3} + m_Name: + m_EditorClassIdentifier: + key: game_title --- !u!1 &1258274238 GameObject: m_ObjectHideFlags: 0 @@ -2637,6 +2670,21 @@ PrefabInstance: value: objectReference: {fileID: 3933269349784766730, guid: fa623acb39bd0fa47807173407e82458, type: 2} + - target: {fileID: 7217120645699259296, guid: 83359716712d3c04293cf99088933eb6, + type: 3} + propertyPath: m_text + value: play_button + objectReference: {fileID: 0} + - target: {fileID: 7217120645699259296, guid: 83359716712d3c04293cf99088933eb6, + type: 3} + propertyPath: m_textInfo.characterCount + value: 11 + objectReference: {fileID: 0} + - target: {fileID: 7217120645699259296, guid: 83359716712d3c04293cf99088933eb6, + type: 3} + propertyPath: m_textInfo.wordCount + value: 2 + objectReference: {fileID: 0} - target: {fileID: 8754154740269184903, guid: 83359716712d3c04293cf99088933eb6, type: 3} propertyPath: m_Delegates.Array.data[0].callback.m_PersistentCalls.m_Calls.Array.data[0].m_Target diff --git a/Assets/Scripts/Localisation.meta b/Assets/Scripts/Localisation.meta new file mode 100644 index 0000000..1ed2220 --- /dev/null +++ b/Assets/Scripts/Localisation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 92d477af9741ec149b21177b60c5a8e0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Localisation/CSVLoader.cs b/Assets/Scripts/Localisation/CSVLoader.cs new file mode 100644 index 0000000..6805761 --- /dev/null +++ b/Assets/Scripts/Localisation/CSVLoader.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using UnityEngine; + +public class CSVLoader +{ + //Reference file; + private TextAsset csvFile; + private char lineSeperator = '\n'; + private char surrond = '"'; + private string[] fieldSeperator = { "\", \"" }; + + public void LoadCSV() + { + csvFile = Resources.Load<TextAsset>("localisation"); + } + + public Dictionary<string, string> GetDictionaryValues(string attributeID) + { + Dictionary<string, string> dictionary = new Dictionary<string, string>(); + + string[] lines = csvFile.text.Split(lineSeperator); + + int attributeIndex = -1; + + string[] headers = lines[0].Split(fieldSeperator, StringSplitOptions.None); + + for(int i=0; i<headers.Length; i++) + { + if(headers[i].Contains(attributeID)) + { + attributeIndex = i; + break; + } + } + + Regex CSVParser = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))"); + + for(int i=1; i<lines.Length; i++) + { + string line = lines[i]; + + string[] fields = CSVParser.Split(line); + + for(int f=0; f<fields.Length; f++) + { + fields[f] = fields[f].TrimStart(' ', surrond); + fields[f] = fields[f].TrimEnd(surrond); + } + + if(fields.Length > attributeIndex) + { + var key = fields[0]; + + if (dictionary.ContainsKey(key)) { continue; } + + var value = fields[attributeIndex]; + + dictionary.Add(key, value); + } + } + + return dictionary; + } + +} diff --git a/Assets/Scripts/Localisation/CSVLoader.cs.meta b/Assets/Scripts/Localisation/CSVLoader.cs.meta new file mode 100644 index 0000000..f8da045 --- /dev/null +++ b/Assets/Scripts/Localisation/CSVLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 61806182744136d43ac66686d8fd4a8c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Localisation/LocalisationSystem.cs b/Assets/Scripts/Localisation/LocalisationSystem.cs new file mode 100644 index 0000000..3d48244 --- /dev/null +++ b/Assets/Scripts/Localisation/LocalisationSystem.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LocalisationSystem +{ + public enum Language + { + English, + French + } + + public static Language language = Language.English; + + private static Dictionary<string, string> localisedEN; + private static Dictionary<string, string> localisedFR; + + public static bool isInit; + + public static void Init() + { + Debug.Log("Initalizing the localisation system..."); + CSVLoader csvLoader = new CSVLoader(); + csvLoader.LoadCSV(); + + localisedEN = csvLoader.GetDictionaryValues("en"); + localisedFR = csvLoader.GetDictionaryValues("fr"); + + isInit = true; + Debug.Log("Loaded the values for the localisation system."); + } + + public static string GetLocalisedValue(string key) + { + if (!isInit) { Init(); } + + string value = key; + + switch (language) + { + case Language.English: + localisedEN.TryGetValue(key, out value); + break; + case Language.French: + localisedFR.TryGetValue(key, out value); + break; + + } + + return value; + } + +} diff --git a/Assets/Scripts/Localisation/LocalisationSystem.cs.meta b/Assets/Scripts/Localisation/LocalisationSystem.cs.meta new file mode 100644 index 0000000..59e4525 --- /dev/null +++ b/Assets/Scripts/Localisation/LocalisationSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a3891ee2e9bce604eb56fc66b0ee96ac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Localisation/TextLocaliserUI.cs b/Assets/Scripts/Localisation/TextLocaliserUI.cs new file mode 100644 index 0000000..a56afb0 --- /dev/null +++ b/Assets/Scripts/Localisation/TextLocaliserUI.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using TMPro; +using UnityEngine; + +[RequireComponent(typeof(TextMeshProUGUI))] +public class TextLocaliserUI : MonoBehaviour +{ + TextMeshProUGUI textField; + + public string key; + + // Start is called before the first frame update + void Start() + { + textField = GetComponent<TextMeshProUGUI>(); + string value = LocalisationSystem.GetLocalisedValue(key); + textField.text = value; + } + +} diff --git a/Assets/Scripts/Localisation/TextLocaliserUI.cs.meta b/Assets/Scripts/Localisation/TextLocaliserUI.cs.meta new file mode 100644 index 0000000..93e3094 --- /dev/null +++ b/Assets/Scripts/Localisation/TextLocaliserUI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7c6a2fc696577634c999293f25c45550 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: |
