/// <summary>
        /// 导出服务器数据
        /// </summary>
        /// <param name="dataType">数据类型:1-客户端,2-服务器</param>
        static public new List <NodeElement> ExportServerData(GKToyData data, string destPath)
        {
            GameData           gameData    = new GameData();
            List <NodeElement> npcTalkText = new List <NodeElement>();
            NodeElement        tmpItem;
            int startId = 0;

            if (!Directory.Exists(destPath))
            {
                GKFile.GKFileUtil.CreateDirectoryFromFileName(destPath);
            }
            data.LoadNodes();
            foreach (GKToyNode node in data.nodeLst.Values)
            {
                tmpItem = new NodeElement();
                if (NodeType.Group == node.nodeType || NodeType.VirtualNode == node.nodeType || "GKToy.GKToyEnd" == node.className)
                {
                    continue;
                }
                if ("GKToy.GKToyStart" == node.className)
                {
                    if (0 < node.links.Count)
                    {
                        startId = node.links[0].next;
                    }
                    continue;
                }
                tmpItem.attrs = _GetFieldsWithAttribute(((GKToyDialogue)node).NodeID.ToString(), data.name, node, typeof(ExportServerAttribute), npcTalkText, node.id == startId);
                gameData.Add(tmpItem);
            }
            // 导出xml.
            XmlSerializer serializer = new XmlSerializer(typeof(GameData));
            FileStream    stream     = new FileStream(destPath, FileMode.Create);

            try
            {
                serializer.Serialize(stream, gameData);
            }
            finally
            {
                stream.Close();
            }
            return(npcTalkText);
        }
示例#2
0
        /// <summary>
        /// 导出客户端数据
        /// </summary>
        /// <param name="data">要导出的数据源</param>
        /// <param name="destPath"></param>
        static public void ExportClientData(GKToyData data, string destPath, string fileName)
        {
            GameData         mainTaskData   = new GameData();
            GameData         subTaskData    = new GameData();
            GameData         taskConfigData = new GameData();
            GameData         npcTalkData    = new GameData();
            GameData         taskTextData   = new GameData();
            List <GKToyData> dfgDatas       = new List <GKToyData>();
            NodeElement      tmpItem;
            Type             exportType = typeof(ExportClientAttribute);

            if (!Directory.Exists(destPath))
            {
                GKFile.GKFileUtil.CreateDirectory(destPath);
            }
            string subPath = string.Format("{0}/{1}", destPath, fileName);

            if (!Directory.Exists(subPath))
            {
                GKFile.GKFileUtil.CreateDirectory(subPath);
            }
            data.LoadNodes();
            foreach (GKToyNode node in data.nodeLst.Values)
            {
                if (NodeType.Group == node.nodeType || NodeType.VirtualNode == node.nodeType)
                {
                    continue;
                }
                if ("GKToyTaskEditor.GKToyTask" == node.className)
                {
                    tmpItem       = new NodeElement();
                    tmpItem.attrs = _GetFieldsWithAttribute(((GKToyTask)node).TaskID.ToString(), node, exportType, taskTextData, dfgDatas, data);
                    mainTaskData.Add(tmpItem);
                    _FindSubTask(data, node, node, subTaskData, taskConfigData, exportType, 1, taskTextData, dfgDatas);
                }
            }
            // 导出任务主表lua.
            string       filePath = string.Format("{0}/Task.lua", subPath);
            StreamWriter stream   = new StreamWriter(filePath, false);

            try
            {
                stream.Write(_DataToLua("Task", mainTaskData));
            }
            finally
            {
                stream.Close();
            }
            // 导出任务配置表lua.
            filePath = string.Format("{0}/TaskConfig.lua", subPath);
            stream   = new StreamWriter(filePath, false);
            try
            {
                stream.Write(_DataToLua("TaskConfig", taskConfigData));
            }
            finally
            {
                stream.Close();
            }
            // 导出子任务表lua.
            filePath = string.Format("{0}/TaskTarget.lua", subPath);
            stream   = new StreamWriter(filePath, false);
            try
            {
                stream.Write(_DataToLua("TaskTarget", subTaskData));
            }
            finally
            {
                stream.Close();
            }
            // 导出taskText lua.
            filePath = string.Format("{0}/TaskText.lua", subPath);
            stream   = new StreamWriter(filePath, false);
            try
            {
                stream.Write(_DataToLua("TaskText", taskTextData));
            }
            finally
            {
                stream.Close();
            }
            // 导出任务对话lua.
            string dfgPath = string.Format("{0}/TaskDfg", destPath);

            if (!Directory.Exists(dfgPath))
            {
                GKFile.GKFileUtil.CreateDirectoryFromFileName(dfgPath);
            }
            foreach (GKToyData dfgData in dfgDatas)
            {
                npcTalkData.AddRange(GKToyMakerDialogueDataExporter.ExportClientData(dfgData, string.Format("{0}/{1}.lua", dfgPath, dfgData.name)));
            }
            // 导出npctalk lua.
            filePath = string.Format("{0}/NpcTalk.lua", subPath);
            stream   = new StreamWriter(filePath, false);
            try
            {
                stream.Write(_DataToLua("NpcTalk", npcTalkData));
            }
            finally
            {
                stream.Close();
            }
            // prize.
        }