Example #1
0
        // 将TextAsset内容读取到字典中
        void ReadTextAsset(TextAsset resource)
        {
            XmlDocument       xml = new XmlDocument();
            XmlReaderSettings set = new XmlReaderSettings();

            set.IgnoreComments = true;            //这个设置是忽略xml注释文档的影响。有时候注释会影响到xml的读取
            xml.Load(XmlReader.Create(new MemoryStream(resource.bytes), set));
            //得到objects节点下的所有子节点
            XmlNodeList xmlNodeList = xml.SelectSingleNode("contents").ChildNodes;

            xmlNodeList = xmlNodeList [0].ChildNodes;
            Files.Add(resource.name);
            StringsByFile.Add(resource.name, new Dictionary <string, string>());

            for (int i = 0; i < xmlNodeList.Count; i++)
            {
                string id    = xmlNodeList[i].Attributes["id"].Value;
                string value = xmlNodeList[i].InnerText;


                if (Strings.ContainsKey(id))
                {
                    Debug.LogWarning("Duplicate string : " + resource + " : " + id);
                    return;
                }
                else
                {
                    Strings.Add(id, value);
                }
                StringsByFile[resource.name].Add(id, value);
            }
        }
Example #2
0
        void ReadCSVAsset(TextAsset resource)
        {
            try
            {
                Files.Add(resource.name);
                StringsByFile.Add(resource.name, new Dictionary <string, string>());

                var rows = CsvReader.ReadCSV(resource.text);

                foreach (var row in rows)
                {
                    var key   = row[0];
                    var value = row[1].TrimEnd('\r');

                    StringsByFile[resource.name].Add(key, value);

                    if (Strings.ContainsKey(key))
                    {
                        Debug.LogWarning("Duplicate string : " + resource + " : " + key);
                    }
                    else
                    {
                        Strings.Add(key, value);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
                Debug.LogError(string.Format("Failed to read file : {0}/{1}  ", Language, resource.name));
            }
        }
Example #3
0
        public string GetFromFile(string groupId, string key, string fallback)
        {
            if (!StringsByFile.ContainsKey(groupId))
            {
                Debug.LogWarning("Localization File Not Found : " + groupId);
                return(fallback);
            }
            var group = StringsByFile[groupId];

            if (!group.ContainsKey(key))
            {
                Debug.LogWarning("Localization Key Not Found : " + key);
                return(fallback);
            }
            return(group[key]);
        }
Example #4
0
        // 将TextAsset内容读取到字典中
        void ReadTextAsset(TextAsset resource)
        {
            var jsonArray = JSONNode.Parse(resource.text);

            Files.Add(resource.name);
            StringsByFile.Add(resource.name, new Dictionary <string, string>());
            foreach (KeyValuePair <string, JSONNode> json in (JSONClass)jsonArray)
            {
                StringsByFile[resource.name].Add(json.Key, json.Value);
                if (Strings.ContainsKey(json.Key))
                {
                    Debug.LogWarning("Duplicate string : " + resource + " : " + json.Key);
                }
                else
                {
                    Strings.Add(json.Key, json.Value);
                }
            }
        }