예제 #1
0
    /// <summary>
    /// 拷贝筛选的AB包及自动生成服务器配置表
    /// </summary>
    /// <param name="changeList"></param>
    /// <param name="hotCount"></param>
    static void CopyABAndGeneratXml(List <string> changeList, string hotCount)
    {
        if (!Directory.Exists(m_HotPath))
        {
            Directory.CreateDirectory(m_HotPath);
        }
        DeleteAllFile(m_HotPath);
        foreach (string str in changeList)
        {
            if (!str.EndsWith(".manifest"))
            {
                File.Copy(m_BunleTargetPath + "/" + str, m_HotPath + "/" + str);
            }
        }

        //生成服务器Patch
        DirectoryInfo directory = new DirectoryInfo(m_HotPath);

        FileInfo[] files   = directory.GetFiles("*", SearchOption.AllDirectories);
        Patches    pathces = new Patches();

        pathces.Version = 1;
        pathces.Files   = new List <Patch> ();
        for (int i = 0; i < files.Length; i++)
        {
            Patch patch = new Patch();
            patch.MD5      = MD5Manager.Instance.BuildFileMd5(files[i].FullName);
            patch.Name     = files[i].Name;
            patch.Size     = files[i].Length / 1024.0f;
            patch.Platform = EditorUserBuildSettings.activeBuildTarget.ToString();
            patch.Url      = "http://127.0.0.1/hotfix/" + PlayerSettings.bundleVersion + "/" + hotCount + "/" + files[i].Name;
            pathces.Files.Add(patch);
        }
        BinarySerializeOpt.Xmlserialize(m_HotPath + "/Patch.xml", pathces);
    }
예제 #2
0
    /// <summary>
    /// 实际的类转XML
    /// </summary>
    /// <param name="name"></param>
    private static void ClassToXml(string name)
    {
        if (string.IsNullOrEmpty(name))
        {
            return;
        }

        try
        {
            Type type = null;
            foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                Type tempType = asm.GetType(name);
                if (tempType != null)
                {
                    type = tempType;
                    break;
                }
            }

            if (type != null)
            {
                var temp = Activator.CreateInstance(type);
                if (temp is ExcelBase)
                {
                    (temp as ExcelBase).Construction();
                }

                string xmlPath = XmlPath + name + ".xml";
                BinarySerializeOpt.Xmlserialize(xmlPath, temp);
                Debug.Log(name + "类转xml成功,xml路径为:" + xmlPath);
            }
        }
        catch
        {
            Debug.LogError(name + "类转xml失败!");
        }
    }
예제 #3
0
    private static void ExcelToXml(string name)
    {
        string className = "";
        string xmlName   = "";
        string excelName = "";
        //第一步,读取Reg文件,确定类的结构
        Dictionary <string, SheetClass> allSheetClassDic = ReadReg(name, ref excelName, ref xmlName, ref className);

        //第二步,读取excel里面的数据
        string excelPath = ExcelPath + excelName;
        Dictionary <string, SheetData> sheetDataDic = new Dictionary <string, SheetData>();

        try
        {
            using (FileStream stream = new FileStream(excelPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (ExcelPackage package = new ExcelPackage(stream))
                {
                    ExcelWorksheets worksheetArray = package.Workbook.Worksheets;
                    for (int i = 0; i < worksheetArray.Count; i++)
                    {
                        SheetData      sheetData  = new SheetData();
                        ExcelWorksheet worksheet  = worksheetArray[i + 1];
                        SheetClass     sheetClass = allSheetClassDic[worksheet.Name];
                        int            colCount   = worksheet.Dimension.End.Column;
                        int            rowCount   = worksheet.Dimension.End.Row;

                        for (int n = 0; n < sheetClass.VarList.Count; n++)
                        {
                            sheetData.AllName.Add(sheetClass.VarList[n].Name);
                            sheetData.AllType.Add(sheetClass.VarList[n].Type);
                        }

                        for (int m = 1; m < rowCount; m++)
                        {
                            RowData rowData = new RowData();
                            int     n       = 0;
                            if (string.IsNullOrEmpty(sheetClass.SplitStr) && sheetClass.ParentVar != null &&
                                !string.IsNullOrEmpty(sheetClass.ParentVar.Foregin))
                            {
                                rowData.ParnetVlue = worksheet.Cells[m + 1, 1].Value.ToString().Trim();
                                n = 1;
                            }
                            for (; n < colCount; n++)
                            {
                                ExcelRange range = worksheet.Cells[m + 1, n + 1];
                                string     value = "";
                                if (range.Value != null)
                                {
                                    value = range.Value.ToString().Trim();
                                }
                                string colValue = worksheet.Cells[1, n + 1].Value.ToString().Trim();
                                rowData.RowDataDic.Add(GetNameFormCol(sheetClass.VarList, colValue), value);
                            }

                            sheetData.AllData.Add(rowData);
                        }
                        sheetDataDic.Add(worksheet.Name, sheetData);
                    }
                }
            }
        }
        catch (Exception e)
        {
            Debug.LogError(e);
            return;
        }

        //根据类的结构,创建类,并且给每个变量赋值(从excel里读出来的值)
        object objClass = CreateClass(className);

        List <string> outKeyList = new List <string>();

        foreach (string str in allSheetClassDic.Keys)
        {
            SheetClass sheetClass = allSheetClassDic[str];
            if (sheetClass.Depth == 1)
            {
                outKeyList.Add(str);
            }
        }

        for (int i = 0; i < outKeyList.Count; i++)
        {
            ReadDataToClass(objClass, allSheetClassDic[outKeyList[i]], sheetDataDic[outKeyList[i]], allSheetClassDic, sheetDataDic, null);
        }

        BinarySerializeOpt.Xmlserialize(XmlPath + xmlName, objClass);
        //BinarySerializeOpt.BinarySerilize(BinaryPath + className + ".bytes", objClass);
        Debug.Log(excelName + "表导入unity完成!");
        AssetDatabase.Refresh();
    }