Jurajkeee
@Jurajkeee
Baby Developer

Как получить доступ к моему языковому пакету на андроид?

Есть ридер xml файла, но он требует путь к файлу. Запихнул LanguageDictionary.xml в StreamingAssets, и написал для всех систем пути. Но в билде всё-равно не находит языковый файл. Што делатb ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;
using System.IO;
//https://toster.ru/q/271453
public class Lang
    {
        private Hashtable Strings;
   
    public Lang(string path, string language)
    {      
            SetLanguage(path, language);   
    }

    public void SetLanguage(string path, string language)
        {
            
            XmlDocument xml = new XmlDocument();
            xml.Load(path);
            Strings = new Hashtable();
            var element = xml.DocumentElement[language];
            if (element != null)
            {
                var elemEnum = element.GetEnumerator();
                while (elemEnum.MoveNext())
                {
                    var xmlItem = (XmlElement)elemEnum.Current;
                    Strings.Add(xmlItem.GetAttribute("name"), xmlItem.InnerText);
                }
            }
            else
            {
                Debug.LogError("The specified language does not exist: " + language);
            }
        }


        public string GetString(string name)
        {
            if (!Strings.ContainsKey(name))
            {
                Debug.LogError("The specified string does not exist: " + name);

                return "";
            }

            return (string)Strings[name];
        }
    }

private void Update()
    {
//Должен засветиться определенный цвет если языковый пакет найден
        if (Application.platform == RuntimePlatform.Android)
        {
            if (File.Exists("jar:file://" + Application.dataPath + "!/assets/" + "/LanguageDictionary.xml"))
            {
                debugImg.color = new Color(0, 0, 0);
            }
        }
        else if (Application.platform == RuntimePlatform.OSXEditor)
        {
            if (File.Exists(Application.dataPath + "/StreamingAssets" + "/LanguageDictionary.xml"))
            {
                debugImg.color = new Color(0, 173, 0);
            }
        }
        else if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            if (File.Exists(Application.dataPath + "/StreamingAssets" + "/LanguageDictionary.xml"))
            {
                debugImg.color = new Color(0, 0, 175);
            }

        }
        else if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            if (File.Exists(Application.dataPath + "/Raw" + "/LanguageDictionary.xml"))
            {
                debugImg.color = new Color(123, 123, 0);
            }

        }

    }

5b7d6f7b49c79992024221.png
  • Вопрос задан
  • 144 просмотра
Решения вопроса 1
GavriKos
@GavriKos Куратор тега Разработка игр
В андроиде могут не работать File. Грузите через www. Кстати путь же у вас не к стриминг ассетам для андроида. Используйте Application.streamingAssetsPath
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы