Ejemplo n.º 1
0
        public void LoadLocalisation(bool reset = false)
        {
            localisation = null;
            localisation = new Dictionary <string, Dictionary <string, string> >();
            CSVFiles     = Resources.LoadAll <TextAsset>(CSVPath);

            csvDatas = new CSVData[CSVFiles.Length];

            for (int i = 0; i < CSVFiles.Length; i++)
            {
                csvDatas[i] = CSVLoader.LoadCSV(CSVFiles[i]);
                localisation.Add(csvDatas[i].headers[0], csvDatas[i].data);
            }

            for (int i = 0; i < CSVFiles.Length; i++)
            {
                bool hit   = false;
                int  index = -1;
                for (int a = 0; a < Languages.Length; a++)
                {
                    if (CSVFiles[i].name != Languages[a].name)
                    {
                        continue;
                    }

                    hit   = true;
                    index = a;
                    break;
                }
                if (hit)
                {
                    Languages[index].Header          = csvDatas[i].headers[0];
                    Languages[index].DefaultLanguage = bool.Parse(csvDatas[i].headers[1]);
                }
#if UNITY_EDITOR
                else
                {
                    string additionalPath = Application.dataPath + "/Resources/" + LanguagePath;
                    if (!Directory.Exists(additionalPath))
                    {
                        Directory.CreateDirectory(additionalPath);
                    }

                    Languages language = CreateInstance <Languages>();
                    language.Header          = csvDatas[i].headers[0];
                    language.DefaultLanguage = bool.Parse(csvDatas[i].headers[1]);

                    UnityEditor.AssetDatabase.CreateAsset(language, "Assets/Resources/" + LanguagePath + "/" + CSVFiles[i].name + ".asset");
                    UnityEditor.AssetDatabase.SaveAssets();
                    UnityEditor.AssetDatabase.Refresh();
                }
#endif
            }

            if (reset || !CurrentLanguage)
            {
                UpdateData();
            }
        }
Ejemplo n.º 2
0
        public void Remove(string key, bool reload = true)
        {
            for (int i = 0; i < languages.Length; i++)
            {
                CSVLoader.Remove(key, CSVFiles[i]);
            }

            if (reload)
            {
                LoadLocalisation();
            }
        }
Ejemplo n.º 3
0
        public void Edit(string key, string value, string header = "", bool reload = true)
        {
            if (value.Contains("\""))
            {
                value.Replace('"', '\"');
            }

            if (string.IsNullOrEmpty(header))
            {
                header = CurrentLanguage.Header;
            }

            if (!GetIndexFromLanguages(header, out int index))
            {
                return;
            }

            CSVLoader.Edit(key, value, CSVFiles[index]);
            if (reload)
            {
                LoadLocalisation();
            }
        }
Ejemplo n.º 4
0
        public void Add(string key, string value, string header = "", bool reload = true)
        {
            if (value.Contains("\""))
            {
                value.Replace('"', '\"');
            }

            if (string.IsNullOrEmpty(header))
            {
                header = CurrentLanguage.Header;
            }

            for (int i = 0; i < languages.Length; i++)
            {
                string temp = languages[i].Header == header ? value : "";
                CSVLoader.Add(key, temp, CSVFiles[i]);
            }

            if (reload)
            {
                LoadLocalisation();
            }
        }