コード例 #1
0
    public string CreateCS(ConfigsNamesTemplate rpt)
    {
        AddHead();
        AddBody(rpt);
        AddTail();
        string result = GetFomatedCS();

        return(result);
    }
コード例 #2
0
    private void AddBody(ConfigsNamesTemplate rpt)
    {
        foreach (var item in rpt.configsNameList)
        {
            CSString.Add(string.Format("public static Dictionary<{2}, {1}> {0};", item.Key + "Dict", item.Key, item.Value));
            CSString.Add(string.Format("public static List<{1}> {0};", item.Key + "List", item.Key));
        }

        CSString.Add(string.Format("public static void Install()"));
        CSString.Add("{");
        foreach (var item in rpt.configsNameList)
        {
            CSString.Add(string.Format("{0} = {1}.Values.ToList();", item.Key + "List", item.Key + "Dict"));
        }
        CSString.Add("}");
    }
コード例 #3
0
        public static void CsvToCs()
        {
            Debug.Log("配置文件转化为代码  开始!");
            _csvListToBeRestored.Clear();
            string xlsxpath   = Application.dataPath + "/XLSX";
            string streampath = Application.dataPath + "/StreamingAssets";
            string csvOutPath = Application.dataPath + "/StreamingAssets/csv";
            string csOutPath  = Application.dataPath + "/Scripts/CSV";

            if (!FrameworkConfig.Instance.UseHotFixMode)
            {
                csOutPath = Application.dataPath + "/Scripts/CSV";
            }
            else
            {
                csOutPath = Application.dataPath + "/Scripts/ILRuntime/HotFixLogic/CSV";
            }
            DirectoryInfo theXMLFolder = new DirectoryInfo(xlsxpath);

            //文件列表
            //string listpath = Application.dataPath + "/StreamingAssets/csvList.txt";
            //FileStream fs = new FileStream( listpath, FileMode.Create );
            //StreamWriter listwriter = new StreamWriter( fs, new UTF8Encoding(false) );

            if (!Directory.Exists(csvOutPath))
            {
                Directory.CreateDirectory(csvOutPath);
            }
            if (!Directory.Exists(csOutPath))
            {
                Directory.CreateDirectory(csOutPath);
            }

            try
            {
                ConfigsNamesTemplate cnt = new ConfigsNamesTemplate();
                //对文件进行遍历
                foreach (var NextFile in theXMLFolder.GetFiles())
                {
                    if (Path.GetExtension(NextFile.Name) == ".xlsx" && !NextFile.Name.StartsWith("~$"))
                    {
                        LDebug.Log(" >表处理 : " + NextFile.Name);
                        FileStream stream  = NextFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        string     csvfile = XLSXTOCSV(stream);
                        CSVParser  cp      = new CSVParser();
                        CreateCSFile(csOutPath, NextFile.Name.Split('.')[0] + ".cs", cp.CreateCS(NextFile.Name.Split('.')[0], csvfile));
                        CreateCSVFile(csvOutPath + "/" + NextFile.Name.Split('.')[0] + ".csv", csvfile);
                        LDebug.Log(NextFile.Name.Split('.')[0] + "  文件生成成功!");

                        //这里固定取配置表第三行配置作为类型读取,如果需要修改配置表适配服务器(增加第四行),需要同步修改
                        CSVReader reader = new CSVReader(csvfile);
                        cnt.configsNameList.Add(NextFile.Name.Split('.')[0], reader.GetData(0, 2));
                        //listwriter.WriteLine( "csv/" + NextFile.Name.Split( '.' )[ 0 ] + ".csv" );
                        string str = "csv/" + NextFile.Name.Split('.')[0] + ".csv";
                        _csvListToBeRestored.Add(new ABVersion {
                            AbName = str, MD5 = LitFramework.Crypto.Crypto.md5.GetFileHash(csvOutPath + "/" + NextFile.Name.Split('.')[0] + ".csv"), Version = 1
                        });
                    }
                    else if (Path.GetExtension(NextFile.Name) == ".txt")
                    {
                        FileInfo fi = new FileInfo(csvOutPath + "/" + NextFile.Name);
                        if (fi.Exists)
                        {
                            fi.Delete();
                        }
                        NextFile.CopyTo(csvOutPath + "/" + NextFile.Name);
                        //listwriter.WriteLine( NextFile.Name );
                        _csvListToBeRestored.Add(new ABVersion {
                            AbName = NextFile.Name, MD5 = string.Empty, Version = 0
                        });
                    }
                }

                //遍历框架配置的额外后缀文件
                string[] extralFile = FrameworkConfig.Instance.configs_suffix.Split('|');
                foreach (var item in extralFile)
                {
                    if (item.Equals("csv"))
                    {
                        continue;
                    }

                    GetFiles(new DirectoryInfo(streampath), item, _csvListToBeRestored);
                }

                //============更新并保存CS============//
                ConfigsParse rpp = new ConfigsParse();

                if (!FrameworkConfig.Instance.UseHotFixMode)
                {
                    EditorMenuExtention.CreateCSFile(Application.dataPath + "/Scripts/Model/Const/", "Configs.cs", rpp.CreateCS(cnt));
                }
                else
                {
                    EditorMenuExtention.CreateCSFile(Application.dataPath + "/Scripts/ILRuntime/HotFixLogic/Model/Const/", "Configs.cs", rpp.CreateCS(cnt));
                }
            }
            catch (Exception e) { LDebug.LogError(e.Message); }
            finally
            {
                //加载本地文件,没有就创建完成。有则比对同名文件的MD5,不一样则version+1
                MatchCSVTotalFile(_csvListToBeRestored);

                //listwriter.Close();
                //listwriter.Dispose();
                //fs.Dispose();
#if UNITY_EDITOR
                AssetDatabase.Refresh();
#endif
            }
        }