コード例 #1
0
        //自定义加载
        private byte[] CustomLoader(ref string filePath)
        {
            string    path      = System.IO.Path.Combine(_luaPathPrefix, $"{filePath}{_luaPathExtension}");
            TextAsset textAsset = _resource.LoadAssetSync <TextAsset>(_luaAssetBundle, path);

            return(textAsset.bytes);
        }
コード例 #2
0
        /// <summary>
        /// 加载数据表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data">配置表的数据</param>
        /// <returns></returns>
        public void LoadDataTable <T>(string assetBundleName, string dataTablePath) where T : class, IDataTableRow, new()
        {
            TextAsset textAsset = _resource.LoadAssetSync <TextAsset>(assetBundleName, dataTablePath);

            string        data      = textAsset.text;
            DataTable <T> dataTable = new DataTable <T>("");

            string[] rows = data.Split('\n');
            foreach (var item in rows)
            {
                //排除多余的数据
                if (string.IsNullOrEmpty(item) || item.Length == 0 || item.Contains("#"))
                {
                    continue;
                }
                //Debug.Log(item);
                dataTable.AddDataRow(item);
            }
            int hasCode = typeof(T).GetHashCode();

            _allDataTables[hasCode] = dataTable;
        }
コード例 #3
0
        /// <summary>
        /// 读取XML文件
        /// </summary>
        /// <param name="rootPath"></param>
        /// <param name="lang"></param>
        /// <returns></returns>
        public Dictionary <string, string> ReadXML(Language lang = Language.Chinese)
        {
            string path = "";

            if (_resource.ResUpdateType == ResourceUpdateType.Resource)
            {
                path = xmlRootPath + lang.ToString() + "/" + lang.ToString();
            }
            else
            {
                path = xmlRootPath + lang.ToString() + "/" + lang.ToString() + ".xml";
            }

            TextAsset xmlAsset = _resource.LoadAssetSync <TextAsset>(assetsBundleName, path);

            //TextAsset xmlAsset = Resources.Load(path) as TextAsset;

            if (!xmlAsset)
            {
                Debug.LogError("File not found at path " + path);
                return(null);
            }

            var reader = XmlReader.Create(new StringReader(xmlAsset.text));

            Dictionary <string, string> data = new Dictionary <string, string>();

            var key   = string.Empty;
            var value = string.Empty;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    key = reader["key"];
                    break;

                case XmlNodeType.Text:
                    value = reader.Value;
                    break;

                case XmlNodeType.EndElement:
                    if (!string.IsNullOrEmpty(key))
                    {
                        if (data.ContainsKey(key))
                        {
                            throw new Exception("Key " + key + " already exists in string dictionary!");
                        }

                        data.Add(key, value);
                        key   = string.Empty;
                        value = string.Empty;
                    }
                    break;
                }
            }

            reader.Close();

            return(data);
        }