Esempio n. 1
0
    /// <summary>
    /// 得到文件夹下所有语言名,经测试ipad不能搜索目录
    /// </summary>
    //void GetListLanguageName()
    //{
    //    DirectoryInfo folder = new DirectoryInfo("Assets/Resources/DB/Localization");
    //    foreach (DirectoryInfo next in folder.GetDirectories())
    //    {
    //        listLanguageName.Add(next.Name);
    //        //Debuger.LogWarning("GetListLanguageName name" + next.Name);
    //    }
    //}

    /// <summary>
    /// 必须放在LoadLanguageName后
    /// </summary>
    /// <param name="language"></param>
    //void LoadFont(string language)
    //{
    //    Debuger.Log("LoadFont==" + language);
    //    ReplacementFont = Resources.Load("UI/font/ChineseFont26", typeof(Font)) as Font;

    //    if (ReferenceFont == null)
    //    {
    //        ReferenceFont = Resources.Load("UI/font/Font_3_7", typeof(Font)) as Font;
    //    }

    //    ReferenceFont.replacement = ReplacementFont;
    //}

    /// <summary>
    /// 加载和某个语言相关的所有本地化文档
    /// </summary>
    /// <param name="language"></param>
    void LoadAllLocalizations(string language)
    {
        //string file = "DB/Localization/" + curLanguage;
        //XmlElement rootEle = CXmlRead.GetRootElement("DB/Localization/LocalizationFileName");
        XmlDocument xmlDoc    = new XmlDocument();
        TextAsset   textAsset = (TextAsset)Resources.Load("NetRes/DB/Localization/LocalizationFileName", typeof(TextAsset));

        //GameRes res = new GameRes("NetRes/DB/Localization/LocalizationFileName", GameRes.eCatchType.CT_None);
        //res.m_eCatchType = GameRes.eCatchType.CT_None;
        //res = ResourcesManager.LoadObj(res);
        //TextAsset textAsset = (TextAsset)res.m_Object;
        if (textAsset == null)
        {
            Debuger.LogError("Load LoadLanguageName DB Failed!");
            return;
        }
        //Debuger.Log("DB/Localization/LocalizationFileName----------------");
        xmlDoc.Load(new StringReader(textAsset.text));
        XmlElement xmlRoot = xmlDoc.DocumentElement;

        foreach (XmlNode node in xmlRoot.ChildNodes)
        {
            if (node.Name == "row")
            {
                CXmlRead xmlRead = new CXmlRead(node as XmlElement);
                string   name    = xmlRead.Str("name");
                string   strPath = "NetRes/DB/Localization/" + curLanguage + "/" + name;

                Debuger.Log(strPath);
                LoadFile(name, strPath);
            }
        }
        //UIRoot.Broadcast("OnLocalize", this);
        //OnChangeLanguage();
    }
Esempio n. 2
0
    void LoadFile(string name, string path)
    {
        Debuger.Log("-----------------------------load file name=" + path);
        Dictionary <string, string> texts = new Dictionary <string, string>();
        // XmlElement rootEle = CXmlRead.GetRootElement(path);

        XmlDocument xmlDoc    = new XmlDocument();
        TextAsset   textAsset = (TextAsset)Resources.Load(path, typeof(TextAsset));

        //GameRes res = new GameRes(path, GameRes.eCatchType.CT_None);
        //res = ResourcesManager.LoadObj(res);
        //TextAsset textAsset = (TextAsset)res.m_Object;
        if (textAsset == null)
        {
            Debuger.LogError("Load LoadLanguageName DB Failed! path=" + path);
            return;
        }
        xmlDoc.Load(new StringReader(textAsset.text));
        XmlElement xmlRoot = xmlDoc.DocumentElement;

        if (xmlRoot == null)
        {
            Debuger.LogWarning("LoadFile fail:" + path);
            return;
        }
        foreach (XmlNode node in xmlRoot.ChildNodes)
        {
            if (node.Name == "row")
            {
                CXmlRead xmlRead = new CXmlRead(node as XmlElement);
                string   id      = xmlRead.Str("id");
                string   text    = xmlRead.Str("text");
                if (texts.ContainsKey(id))
                {
                    Debuger.LogWarning("duplicate record id name:" + name + "id:" + id);
                    continue;
                }
                texts.Add(id, text);
                //Debuger.LogWarning("GetListLanguageName" + text);
            }
        }
        dicLocalLanguages.Add(name, texts);
    }