public static byte[] Export2Bytes(string value, TableFiledType type)
        {
            var bytesList = new List <byte>();

            byte[] targetBytes;
            switch (type)
            {
            case TableFiledType.FLOAT:
                targetBytes = ConvertHelper.GetBytes(float.Parse(value));
                break;

            case TableFiledType.INT:
                targetBytes = ConvertHelper.GetBytes(int.Parse(value));
                break;

            case TableFiledType.BOOL:
                targetBytes = ConvertHelper.GetBytes((int.Parse(value)) == 1);
                break;

            case TableFiledType.STRING:
            default:
                targetBytes = ConvertHelper.GetBytes(value);
                var countBytes = ConvertHelper.GetBytes(targetBytes.Length);
                bytesList.AddRange(countBytes);
                break;
            }
            bytesList.AddRange(targetBytes);
            return(bytesList.ToArray());
        }
Beispiel #2
0
        public static void ExportCs(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            _infoDict.Clear();
            _fileName = string.Empty;
            _code     = string.Empty;

            _infoDict = TableReader.ReadCsvFile(path);
            _code     = template;
            if (_infoDict.ContainsKey(2))
            {
                _fileName = Path.GetFileNameWithoutExtension(path);
                string filePath = _targetPath + _fileName + ".cs";
                _code = _code.Replace("#fileName#", _fileName);

                string fields  = string.Empty;
                string mainKey = string.Empty;
                string funcs   = string.Empty;

                List <string> line = _infoDict[2];
                for (int i = 0; i < line.Count; i++)
                {
                    string         target = line[i];
                    string[]       temp   = target.Split(":".ToArray());
                    TableFiledType type   = TableFiledType.STRING;
                    if (temp.Length < 2)
                    {
                        LogHelper.PrintWarning(string.Format("#配表未指定类型{0}行,{1}列,请先初始化#path:" + path, 2.ToString(), i.ToString()));
                        return;
                    }
                    else
                    {
                        type = TableReader.GetTableFiledType(temp[1]);
                    }
                    fields = fields + "\r\n " + "    public " + _tableTypeDict[type].ToString() + " " + temp[0] + ";";
                    if (i == 0)
                    {
                        mainKey = temp[0];
                    }
                    funcs = funcs + "\r\n " + string.Format(_tableReadDict[type], temp[0]);
                }
                _code = _code.Replace("#fields#", fields);
                _code = _code.Replace("#mainKey#", mainKey);
                _code = _code.Replace("#function#", funcs);
                File.WriteAllText(filePath, _code);
                AssetDatabase.Refresh();
                EditorUtility.DisplayDialog("提示", "cs 导出成功,等待编译通过!", "确认");
            }
        }