Example #1
0
        public override void DoExport(JsonData jsonData, CSFiled filed, ICell cell)
        {
            var cellStr = cell.StringCellValue;

            if (cellStr.StartsWith("[") && cellStr.EndsWith("]"))
            {
                if (cellStr.Length == 2)
                {
                    jsonData[filed.name] = new JsonData();
                    jsonData[filed.name].SetJsonType(JsonType.Array);
                }
                else
                {
                    jsonData[filed.name] = new JsonData();
                    var numStr = cellStr.Substring(1, cellStr.Length - 2);
                    var nums   = numStr.SplitToInt(",");
                    foreach (var num in nums)
                    {
                        jsonData[filed.name].Add(num);
                    }
                }
            }
            else
            {
                LTDebug.LogError("配置类型错误,数组格式必须为[XX,XX,XX,XX],当前为:{0}", cellStr);
            }
        }
Example #2
0
        public override void DoExport(JsonData jsonData, CSFiled filed, ICell cell)
        {
            var isTure = false;

            switch (cell.CellType)
            {
            case CellType.Numeric:
                isTure = cell.NumericCellValue == 1;
                break;

            case CellType.String:
                if (cell.StringCellValue.Equals("true", System.StringComparison.CurrentCultureIgnoreCase))
                {
                    isTure = true;
                }
                break;

            case CellType.Boolean:
                isTure = cell.BooleanCellValue;
                break;

            default:
                LTDebug.LogError("配置类型错误,期望为0/1/true/false");
                break;
            }
            jsonData[filed.name] = isTure;
        }
Example #3
0
        public override void DoExport(JsonData jsonData, CSFiled filed, ICell cell)
        {
            var cellStr = cell.StringCellValue;

            if (cellStr.StartsWith("[") && cellStr.EndsWith("]"))
            {
                if (cellStr.Length == 2)
                {
                    // 不添加任何东西
                }
                else
                {
                    jsonData[filed.name] = new JsonData();
                    var str      = cellStr.Substring(2, cellStr.Length - 4);
                    var strArray = str.Split("\",\"");
                    foreach (var singleStr in strArray)
                    {
                        jsonData[filed.name].Add(singleStr);
                    }
                }
            }
            else
            {
                LTDebug.LogError("配置类型错误,数组格式必须为[\"XX\",\"XX\",\"XX\",\"XX\"]");
            }
        }
Example #4
0
        private static void _CheckHandle()
        {
            if (_handleActions != null)
            {
                return;
            }
            _handleActions = new Dictionary <string, BaseExcelFiledExporter>();
            var baseExport = typeof(BaseExcelFiledExporter);

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (type.BaseType == baseExport)
                    {
                        var instance = type.Assembly.CreateInstance(type.FullName) as BaseExcelFiledExporter;
                        foreach (var typeStr in instance.typeStrs)
                        {
                            if (_handleActions.ContainsKey(typeStr))
                            {
                                LTDebug.LogError("存在重复注册的Excel Filed解析函数:{0}", instance.typeStrs);
                            }
                            else
                            {
                                _handleActions.Add(typeStr, instance);
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        public static IWorkbook ReadExcel(string excelPath)
        {
            var isXlsx = excelPath.EndsWith(".xlsx", System.StringComparison.CurrentCultureIgnoreCase);

            Debug.Log("处理文件:" + excelPath);
            FileStream fs = null;

            try
            {
                fs = new FileStream(excelPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            }
            catch { }

            if (fs == null)
            {
                LTDebug.LogError("无法打开文件{0},跳过处理", excelPath);
                return(null);
            }

            IWorkbook workbook = null;

            if (isXlsx)
            {
                workbook = new XSSFWorkbook(fs);
            }
            else
            {
                workbook = new HSSFWorkbook(fs);
            }

            return(workbook);
        }
Example #6
0
 public static string GetMD5FromFile(string filePath)
 {
     if (!File.Exists(filePath))
     {
         LTDebug.LogError("尝试计算不存在文件的MD5:{0}", filePath);
         return("");
     }
     return(GetMD5(File.ReadAllBytes(filePath)));
 }
Example #7
0
        public void ReturnObj(string objName, GameObject obj)
        {
            LTGameObjPollData objPool = null;

            _objPools.TryGetValue(objName, out objPool);
            if (objPool == null)
            {
                LTDebug.LogError("不存在指定对象池:" + objName);
                return;
            }
            objPool.Return(obj);
        }
Example #8
0
 public override void DoExport(JsonData jsonData, CSFiled filed, ICell cell)
 {
     if (cell == null)
     {
         jsonData[filed.name] = 0;
     }
     else if (cell.CellType == CellType.Numeric)
     {
         var fValue = cell.NumericCellValue;
         jsonData[filed.name] = fValue;
     }
     else
     {
         LTDebug.LogError("配置类型错误,期望为浮点数,得到类型为:" + cell.CellType);
     }
 }
Example #9
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="notifyID"></param>
        /// <param name="_string"></param>
        public static void SendNotify(string notifyID, string _string)
        {
            List <LTEventHandler> findList = null;
            bool isDone = false;

            if (_eventMap.TryGetValue(notifyID, out findList))
            {
                for (int i = 0; i < findList.Count; ++i)
                {
                    _DoAction(findList[i], _string);
                    isDone = true;
                }
            }
            if (!isDone)
            {
                LTDebug.LogWarning("[LTEventLog]{0}事件没有任何响应", notifyID);
            }
        }
Example #10
0
 public static bool RenameFile(string oldFilePath, string newFilePath)
 {
     if (!File.Exists(oldFilePath))
     {
         LTDebug.LogError("原始文件不存在:{0}", oldFilePath);
         return(false);
     }
     if (File.Exists(newFilePath))
     {
         File.Delete(newFilePath);
     }
     if (File.Exists(newFilePath))
     {
         LTDebug.LogError("目标文件无法删除:{0}", newFilePath);
         return(false);
     }
     File.Move(oldFilePath, newFilePath);
     return(true);
 }
Example #11
0
        public async static Task <bool> WriteBytesToFile(string filePath, byte[] bytes)
        {
            try
            {
                LTUtils.MakeDirExist(filePath);

                var fs = new FileStream(filePath, FileMode.Create);
                await fs.WriteAsync(bytes, 0, bytes.Length);

                fs.Dispose();

                return(true);
            }
            catch (Exception e)
            {
                LTDebug.LogException(e);
                return(false);
            }
        }
Example #12
0
 public override void DoExport(JsonData jsonData, CSFiled filed, ICell cell)
 {
     if (cell == null)
     {
         jsonData[filed.name] = 0;
     }
     else if (cell.CellType == CellType.String)
     {
         int.TryParse(cell.StringCellValue, out int parseInt);
         jsonData[filed.name] = parseInt;
         LTDebug.LogWarning("int格式,获取到配置表为string:" + cell.StringCellValue + "已自动转为int:" + parseInt);
     }
     else if (cell.CellType == CellType.Numeric)
     {
         jsonData[filed.name] = (int)cell.NumericCellValue;
     }
     else
     {
         LTDebug.LogError("int格式期望类型不匹配,当前为:" + cell.CellType);
         jsonData[filed.name] = 0;
     }
 }
Example #13
0
        private static void _HandleRegist(string notifyID, LTEventHandler handle)
        {
            List <LTEventHandler> findList = null;

            if (_eventMap.TryGetValue(notifyID, out findList))
            {
                if (findList.Contains(handle))
                {
                    LTDebug.LogWarning("{0}已存在同样事件注册{1},本次注册取消", notifyID, handle);
                }
                else
                {
                    findList.Add(handle);
                }
            }
            else
            {
                findList = new List <LTEventHandler>();
                findList.Add(handle);
                _eventMap.Add(notifyID, findList);
            }
        }
Example #14
0
        private static string _GenJson(CSStruct code, List <IRow> rows, bool isTs)
        {
            _CheckHandle();
            var filedCount = code.fileds.Count;
            var totalData  = new JsonData();
            var isAdded    = false;

            foreach (var row in rows)
            {
                if (row == null)
                {
                    continue;
                }
                var jsonData = new JsonData();
                var isId     = true;
                var id       = 0;
                var isGen    = false;
                foreach (var filed in code.fileds)
                {
                    if (isId)
                    {
                        isId = false;
                        // 检查是否是ID
                        if (filed.name != "id")
                        {
                            LTDebug.LogError("excel配置表首行必须为id");
                            break;
                        }
                        // 检查是否是ID
                        if (filed.mtype != "int")
                        {
                            LTDebug.LogError("id配表类型必须为int");
                            break;
                        }
                        // 检查内容是否为空
                        var idCell = row.GetCell(filed.index);
                        if (idCell == null)
                        {
                            break;
                        }
                        if (idCell.CellType != CellType.Numeric)
                        {
                            break;
                        }
                        id    = Mathf.CeilToInt((float)row.GetCell(filed.index).NumericCellValue);
                        isGen = true;
                    }
                    if (filed.mtype == "" || filed.mtype == "skip")
                    {
                        continue;
                    }
                    var cell = row.GetCell(filed.index);
                    BaseExcelFiledExporter exporter = null;
                    if (_handleActions.TryGetValue(filed.mtype, out exporter))
                    {
                        exporter.DoExport(jsonData, filed, cell);
                    }
                    else
                    {
                        LTDebug.LogError("未处理的配表类型:{0}", filed.mtype);
                    }
                }
                if (isGen)
                {
                    if (isTs)
                    {
                        (totalData as IDictionary)[id.ToString()] = jsonData;
                    }
                    else
                    {
                        totalData.Add(jsonData);
                    }
                    isAdded = true;
                }
            }
            if (!isAdded)
            {
                return(string.Empty);
            }
            if (isTs)
            {
                return(totalData.ToJson());
            }
            else
            {
                var finalData = new JsonData();
                finalData["dataList"] = totalData;
                return(finalData.ToJson());
            }
        }