コード例 #1
0
ファイル: FishMenu.cs プロジェクト: atom-chen/FishUtil
    static void CombineToOneFileJson()
    {
        string dir        = Application.dataPath + "/FishPath/Resources/PathConfig/";
        string resultFile = EditorUtility.SaveFilePanel("Save", dir, "pathes", "json");

        if (resultFile.Length > 0)
        {
            JsonPathList pathList = new JsonPathList();
            string[]     files    = Directory.GetFiles(dir, "*.bytes");
            foreach (string file in files)
            {
                FileStream   fs       = new FileStream(file, FileMode.Open);
                StreamReader sr       = new StreamReader(fs);
                string       jsonStr  = sr.ReadToEnd();
                JsonPath     jsonPath = new JsonPath();
                jsonPath = JsonMapper.ToObject <JsonPath>(jsonStr);
                pathList.AddPath(jsonPath);
                fs.Close();
            }
            string       str = JsonMapper.ToJson(pathList);
            FileStream   fs1 = new FileStream(resultFile, FileMode.Create, FileAccess.Write);
            StreamWriter sw  = new StreamWriter(fs1);
            sw.Write(str);
            sw.Flush();
            fs1.Close();
        }
    }
コード例 #2
0
ファイル: FishMenu.cs プロジェクト: atom-chen/FishUtil
    static void CombineToOneFileXML()
    {
        string dir        = Application.dataPath + "/FishPath/Resources/PathConfig/";
        string resultFile = EditorUtility.SaveFilePanel("Save", dir, "pathes", "xml");

        if (resultFile.Length > 0)
        {
            JsonPathList pathList = new JsonPathList();
            string[]     files    = Directory.GetFiles(dir, "*.bytes");
            foreach (string file in files)
            {
                FileStream   fs       = new FileStream(file, FileMode.Open);
                StreamReader sr       = new StreamReader(fs);
                string       jsonStr  = sr.ReadToEnd();
                JsonPath     jsonPath = new JsonPath();
                jsonPath = JsonMapper.ToObject <JsonPath>(jsonStr);
                pathList.AddPath(jsonPath);
                fs.Close();
            }

            XmlDocument xmlDoc = new XmlDocument();
            //创建根节点
            XmlElement pathes = xmlDoc.CreateElement("Pathes");
            xmlDoc.AppendChild(pathes);
            foreach (JsonPath path in pathList.PathList)
            {
                XmlElement onePath = xmlDoc.CreateElement("OnePath");
                pathes.AppendChild(onePath);
                onePath.SetAttribute("id", path.id.ToString());
                int index = 0;
                foreach (JsonControlPoint cp in path.pointList)
                {
                    XmlElement onePoint = xmlDoc.CreateElement("ControlPoint");
                    onePoint.SetAttribute("id", index.ToString());
                    onePoint.SetAttribute("time", cp.time.ToString());
                    onePoint.SetAttribute("speedMulti", cp.speedScale.ToString());
                    onePoint.SetAttribute("rotation", cp.r.ToString());
                    onePath.AppendChild(onePoint);
                    index++;
                }
            }
            xmlDoc.Save(resultFile);
        }
    }