Esempio n. 1
0
        public static void CopySavePath1ToPath2()
        {
            var savePath = LTEditorUtils.GetRealPath(LTEditorData.instance.protoGenPath);

            if (!Directory.Exists(savePath))
            {
                UnityEngine.Debug.LogErrorFormat("不存在原始路径:{0}", savePath);
                return;
            }
            var files = Directory.GetFileSystemEntries(savePath);

            if (string.IsNullOrEmpty(LTEditorData.instance.protoGenPath2))
            {
                UnityEngine.Debug.LogError("目标路径不能为空");
                return;
            }
            var savePath2 = LTEditorData.instance.protoGenPath2;
            var path      = LTUtils.MakeDirExist(savePath2);

            foreach (var filePath in files)
            {
                if (filePath.EndsWith(".cs"))
                {
                    var file     = new FileInfo(filePath);
                    var destPath = path + "/" + file.Name;
                    File.Copy(filePath, destPath, true);
                    UnityEngine.Debug.LogFormat("复制成功:{0}-->{1}", filePath, destPath);
                }
            }
        }
Esempio n. 2
0
        public static void HandleProto(string protoFile)
        {
            var p         = new Process();
            var startInfo = p.StartInfo;

            startInfo.FileName = Application.dataPath + "/Plugins/LTGame/Editor/Utils/ProtoGen/protoc.exe";
            var savePath = LTEditorUtils.GetRealPath(LTEditorData.instance.protoGenPath);

            LTUtils.MakeDirExist(savePath);
            var protoDirPath = LTUtils.GetDirPath(protoFile);
            var arguments    = string.Format(" --csharp_out={0} --proto_path {1} {2}", savePath, protoDirPath, protoFile);

            // arguments = arguments.ReplaceAll("/", "\\\\");
            UnityEngine.Debug.LogFormat("arguments:{0}", arguments);
            startInfo.Arguments             = arguments;
            startInfo.RedirectStandardError = true;
            startInfo.UseShellExecute       = false;
            p.Start();
            var errorStr = p.StandardError.ReadToEnd();

            p.WaitForExit();

            if (string.IsNullOrEmpty(errorStr))
            {
                UnityEngine.Debug.LogFormat("生成{0}到{1}", protoFile, savePath);
            }
            else
            {
                UnityEngine.Debug.LogErrorFormat("errorOutput:{0}", errorStr);
                UnityEngine.Debug.LogErrorFormat("生成{0}到{1}失败", protoFile, savePath);
            }
        }
Esempio n. 3
0
        private bool _UpdateNetTime()
        {
            return(true);

            var netDateTime = LTUtils.GetNetDateTime();
            var success     = !string.IsNullOrEmpty(netDateTime);

            if (success)
            {
                var netTime   = Convert.ToDateTime(netDateTime);
                var localTime = System.DateTime.Now;
                var offset    = netTime - localTime;
                if (Math.Abs(offset.TotalMinutes) < 1)
                {
                    _netTime = localTime;
                }
                else
                {
                    _netTime = netTime;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        public static void WriteStrToFile(string str, string filePath)
        {
            LTUtils.MakeDirExist(filePath);
            FileStream   fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);

            sw.WriteLine(str);

            sw.Close();
            fs.Close();
        }
Esempio n. 5
0
        private static LTDirInfo _Init(string fullDirPath)
        {
            var dirPath   = LTUtils.GetDirPath(fullDirPath);
            var splitDirs = dirPath.Split("/");
            var dirList   = new LTDirInfo[splitDirs.Length];

            for (var i = 0; i < dirList.Length; ++i)
            {
                var splitDir = splitDirs[i];
                var dir      = new LTDirInfo(splitDir);
                dirList[i] = dir;
            }
            for (var i = 1; i < dirList.Length; ++i)
            {
                dirList[i - 1].Connect(dirList[i]);
            }
            return(dirList[splitDirs.Length - 1]);
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        public static void GenCodeWithFile(string excelPath, bool isTs)
        {
            var fileName = LTUtils.GetFileName(excelPath);

            if (fileName.StartsWith("~"))
            {
                // excel临时文件自动跳过
                return;
            }

            if (fileName.EndsWith("const"))
            {
                _DoExportConstConfig(excelPath, isTs);
            }
            else
            {
                _DoExportNormalConfig(excelPath, isTs);
            }
        }
Esempio n. 8
0
        public static void GenCodeWithFile(string excelPath, bool isTs)
        {
            var fileName = LTUtils.GetFileName(excelPath);

            if (fileName.StartsWith("~"))
            {
                // excel临时文件自动跳过
                return;
            }


            var workbook = ReadExcel(excelPath);
            var sheet1   = workbook.GetSheetAt(0);
            var code     = new CSStruct();

            code.nameSpace = isTs ? LTEditorData.instance.ts_excelNameSpace : LTEditorData.instance.excelNameSpace;
            code.className = LTUtils.ConvertNameToFormat(fileName);
            code.fileds    = new List <CSFiled>();

            var comments = new List <string>();
            var types    = new List <string>();
            var names    = new List <string>();

            const int commentIndex = 0;
            const int typeIndex    = 1;
            const int nameIndex    = 2;

            _ReadPorps(sheet1.GetRow(commentIndex), comments);
            _ReadPorps(sheet1.GetRow(typeIndex), types);
            _ReadPorps(sheet1.GetRow(nameIndex), names);

            if (comments.Count != types.Count ||
                types.Count != names.Count)
            {
                Debug.LogError("格式不正确");
                return;
            }

            for (int i = 0; i < comments.Count; ++i)
            {
                var comment = comments[i];
                var type    = types[i];
                var name    = names[i];
                code.fileds.Add(new CSFiled()
                {
                    name = name, mtype = type, region = comment, index = i
                });
            }

            var  rows  = new List <IRow>();
            var  index = 3;
            IRow row   = null;

            while ((row = sheet1.GetRow(index++)) != null)
            {
                rows.Add(row);
            }

            if (isTs)
            {
                var codeSb = new StringBuilder();
                // 写入命名空间
                codeSb.AppendLine("export namespace {0} {".ReplaceAll("{0}", code.className));

                // 写入结构体
                codeSb.AppendLine(code.GetTSClass());

                var tsSavePath = LTEditorData.instance.ts_configCodeSavePath;
                if (tsSavePath.StartsWith("/"))
                {
                    tsSavePath = Application.dataPath + tsSavePath;
                }
                tsSavePath = tsSavePath + "/" + code.className + ".ts";
                WriteStrToFile(codeSb.ToString(), tsSavePath);

                // 写入数据
                var minJson      = _GenJson(code, rows, isTs);
                var jsonSavePath = LTEditorData.instance.ts_configJsonSavePath;
                if (jsonSavePath.StartsWith("/"))
                {
                    jsonSavePath = Application.dataPath + jsonSavePath;
                }
                jsonSavePath = jsonSavePath + "/" + code.className + ".json";
                WriteStrToFile(minJson, jsonSavePath);

                Debug.Log("[TS模式]配置生成完成");
                Debug.LogFormat("ts:{0},json:{1}", tsSavePath, jsonSavePath);
            }
            else
            {
                var minJson      = _GenJson(code, rows, isTs);
                var formatJson   = JsonFormatterPlus.JsonFormatter.Format(minJson);
                var jsonSavePath = LTEditorData.instance.configDataSavePath;
                if (jsonSavePath.StartsWith("/"))
                {
                    jsonSavePath = Application.dataPath + jsonSavePath;
                }
                var jsonPath = jsonSavePath + "/" + code.className + ".json";
                WriteStrToFile(formatJson, jsonPath);

                var codeSavePath = LTEditorData.instance.configCodeSavePath;
                if (codeSavePath.StartsWith("/"))
                {
                    codeSavePath = Application.dataPath + codeSavePath;
                }
                var codePath = codeSavePath + "/" + code.className + ".cs";

                var cachePath = jsonPath.Replace(Application.dataPath, "Assets");
                WriteStrToFile(code.GetString(cachePath), codePath);

                Debug.Log("[C#模式]配置生成完成");
                Debug.LogFormat("code:{0}", codePath);
                Debug.LogFormat("json:{0}", jsonPath);
            }
        }
Esempio n. 9
0
        private static void _DoExportNormalConfig(string excelPath, bool isTs)
        {
            var fileName = LTUtils.GetFileName(excelPath);

            var workbook = ReadExcel(excelPath);
            var sheet1   = workbook.GetSheetAt(0);
            var code     = new CSStruct();

            code.nameSpace = isTs ? "NoName" : LTEditorData.instance.excelNameSpace;
            code.className = LTUtils.ConvertNameToFormat(fileName);
            code.fileds    = new List <CSFiled>();
            code.isConst   = false;

            var comments = new List <string>();
            var types    = new List <string>();
            var names    = new List <string>();

            const int commentIndex = 0;
            const int typeIndex    = 1;
            const int nameIndex    = 2;

            _ReadPorps(sheet1.GetRow(commentIndex), comments);
            _ReadPorps(sheet1.GetRow(typeIndex), types);
            _ReadPorps(sheet1.GetRow(nameIndex), names);

            if (comments.Count != types.Count ||
                types.Count != names.Count)
            {
                Debug.LogError("格式不正确");
                return;
            }

            for (int i = 0; i < comments.Count; ++i)
            {
                var comment = comments[i];
                var type    = types[i];
                var name    = names[i];
                code.fileds.Add(new CSFiled()
                {
                    name = name, mtype = type, region = comment, index = i
                });
            }

            var  rows  = new List <IRow>();
            var  index = 3;
            IRow row   = null;

            while ((row = sheet1.GetRow(index++)) != null)
            {
                rows.Add(row);
            }

            if (isTs)
            {
                _GenTs(isTs, code, rows);
            }
            else
            {
                _GenCSharp(isTs, code, rows);
            }
        }
Esempio n. 10
0
        private static void _DoExportConstConfig(string excelPath, bool isTs)
        {
            var fileName = LTUtils.GetFileName(excelPath);

            var workbook = ReadExcel(excelPath);
            var sheet1   = workbook.GetSheetAt(0);
            var code     = new CSStruct();

            code.nameSpace = isTs ? "NoName" : LTEditorData.instance.excelNameSpace;
            code.className = LTUtils.ConvertNameToFormat(fileName);
            code.fileds    = new List <CSFiled>();
            code.isConst   = true;

            var startIndex = 1;
            var rows       = new List <IRow>();
            var row        = sheet1.GetRow(startIndex);

            while (row != null)
            {
                code.fileds.Add(new CSFiled()
                {
                    index  = startIndex,
                    mtype  = row.GetCell(1).StringCellValue,
                    region = row.GetCell(3).StringCellValue,
                    name   = row.GetCell(0).StringCellValue
                });
                rows.Add(row);
                startIndex++;
                row = sheet1.GetRow(startIndex);
            }

            if (isTs)
            {
                var codeSb = new StringBuilder();
                // 写入命名空间
                codeSb.AppendLine("export namespace {0} {".ReplaceAll("{0}", code.className));

                // 写入结构体
                codeSb.AppendLine(code.GetTSClass());

                var tsSavePath = LTEditorData.instance.ts_configCodeSavePath;
                if (tsSavePath.StartsWith("/"))
                {
                    tsSavePath = Application.dataPath + tsSavePath;
                }
                tsSavePath = tsSavePath + "/" + code.className + ".ts";
                WriteStrToFile(codeSb.ToString(), tsSavePath);

                // 写入数据
                var minJson      = _GenJson(code, rows, isTs);
                var jsonSavePath = LTEditorData.instance.ts_configJsonSavePath;
                if (jsonSavePath.StartsWith("/"))
                {
                    jsonSavePath = Application.dataPath + jsonSavePath;
                }
                jsonSavePath = jsonSavePath + "/" + code.className + ".json";
                WriteStrToFile(minJson, jsonSavePath);

                Debug.Log("[TS模式]配置生成完成");
                Debug.LogFormat("ts:{0},json:{1}", tsSavePath, jsonSavePath);
            }
            else
            {
                Debug.LogError("暂未支持");
            }
        }