コード例 #1
0
    /// <summary>
    /// 写战斗增长数据
    /// </summary>
    /// <param name="xmlWriter"></param>
    /// <param name="data"></param>
    private void WriteBattleData(XmlWriter xmlWriter, BattleDataByTime data)
    {
        xmlWriter.WriteStartElement("BattleData");

        xmlWriter.WriteAttributeString("GrowthTime", data.GrowthTime.ToString());
        xmlWriter.WriteAttributeString("BattleID", data.BattleID.ToString());
        xmlWriter.WriteAttributeString("BattleType", ((int)data.BattleType).ToString());
        xmlWriter.WriteAttributeString("Loot", data.Loot.ToString());

        xmlWriter.WriteEndElement();
    }
コード例 #2
0
    /// <summary>
    /// 加载NPC数据;
    /// </summary>
    public void LoadDungeonData()
    {
        m_DungeonDataDic = new Dictionary <int, DungeonData>();
        string textAsset = ResourcesManager.Instance.LoadConfigXML("DungeonData").text;

//		XmlReaderSettings settings = new XmlReaderSettings();
//		settings.ConformanceLevel = ConformanceLevel.Fragment;
//		settings.IgnoreWhitespace = false;
//		settings.IgnoreComments = false;
//		XmlReader reader = XmlReader.Create(textAsset, settings);
        //Debug.Log(textAsset);

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(textAsset);

        m_DungeonDataComment.Clear();
        XmlNodeList nodeList = xmlDoc.ChildNodes;

        foreach (XmlNode node in nodeList)
        {
            switch (node.NodeType)
            {
            case XmlNodeType.Comment:
                //Debug.Log("Commnent: " + node.Value);
                m_DungeonDataComment.Add(node.Value);
                break;

//			case XmlNodeType.Element:
//				Debug.Log("Element: " + node.Name);
//				break;
//			case XmlNodeType.Text:
//				Debug.Log("Text: " + node.Value);
//				break;
//			case XmlNodeType.XmlDeclaration:
//				Debug.Log("XmlDeclaration: " + node.Name + " " + node.Value);
//				break;
            default:
                break;
            }
        }

        XmlNode datas = xmlDoc.SelectSingleNode("DungeonDatas");

        XmlNodeList list = datas.ChildNodes;

        if (list == null || list.Count < 1)
        {
            return;
        }

        foreach (XmlNode node in list)
        {
            XmlElement element = node as XmlElement;

            if (!element.Name.Equals("DungeonData"))
            {
                continue;
            }
            DungeonData info = new DungeonData();

            info.ID      = CommonHelper.Str2Int(element.GetAttribute("ID"));
            info.Name    = element.GetAttribute("Name");
            info.Desc    = element.GetAttribute("Desc");
            info.SceneId = CommonHelper.Str2Int(element.GetAttribute("SceneId"));
            float x = CommonHelper.Str2Float(element.GetAttribute("PosX"));
            float y = CommonHelper.Str2Float(element.GetAttribute("PosY"));
            float z = CommonHelper.Str2Float(element.GetAttribute("PosZ"));
            info.Position        = new Vector3(x, y, z);
            info.Orient          = CommonHelper.Str2Float(element.GetAttribute("Orient"));
            info.CapitalProducts = CommonHelper.Str2IntArray(element.GetAttribute("CapitalProducts"));
            info.ItemProducts    = CommonHelper.Str2IntArray(element.GetAttribute("ItemProducts"));

            XmlNodeList data = element.ChildNodes;
            if (data == null)
            {
                continue;
            }

            foreach (XmlNode subNode in data)
            {
                XmlElement subElement = subNode as XmlElement;
                if (!subElement.Name.Equals("StageData"))
                {
                    continue;
                }
                StageData stageData = new StageData();

                stageData.ID      = CommonHelper.Str2Int(subElement.GetAttribute("ID"));
                stageData.NpcID   = CommonHelper.Str2Int(subElement.GetAttribute("NpcID"));
                stageData.NpcType = (NpcTypes)CommonHelper.Str2Int(subElement.GetAttribute("NpcType"));
                float subx = CommonHelper.Str2Float(subElement.GetAttribute("PosX"));
                float suby = CommonHelper.Str2Float(subElement.GetAttribute("PosY"));
                float subz = CommonHelper.Str2Float(subElement.GetAttribute("PosZ"));
                stageData.Position     = new Vector3(subx, suby, subz);
                stageData.Orient       = CommonHelper.Str2Float(subElement.GetAttribute("Orient"));
                stageData.IsBossBattle = CommonHelper.Str2Int(subElement.GetAttribute("IsBossBattle"));

                XmlNodeList battledata = subElement.ChildNodes;
                if (battledata == null)
                {
                    continue;
                }

                if (stageData.BattleDatasList == null)
                {
                    stageData.BattleDatasList = new List <BattleDataByTime>();
                }
                foreach (XmlNode nextNode in battledata)
                {
                    XmlElement nextElement = nextNode as XmlElement;
                    if (!nextElement.Name.Equals("BattleData"))
                    {
                        continue;
                    }

                    BattleDataByTime battleData = new BattleDataByTime();

                    battleData.GrowthTime = CommonHelper.Str2Float(nextElement.GetAttribute("GrowthTime"));
                    battleData.BattleID   = CommonHelper.Str2Int(nextElement.GetAttribute("BattleID"));
                    battleData.BattleType = (BattleTypes)CommonHelper.Str2Int(nextElement.GetAttribute("BattleType"));
                    battleData.Loot       = CommonHelper.Str2Int(nextElement.GetAttribute("Loot"));

                    //加入战斗包信息
                    stageData.BattleDatasList.Add(battleData);
                }

                stageData.BattleDatasList.Sort(delegate(BattleDataByTime a, BattleDataByTime b){
                    if (a.GrowthTime < b.GrowthTime)
                    {
                        return(-1);
                    }
                    if (a.GrowthTime > b.GrowthTime)
                    {
                        return(1);
                    }
                    return(0);
                });

                //加入npc信息
                if (info.StageDataList == null)
                {
                    info.StageDataList = new List <StageData>();
                }
                info.StageDataList.Add(stageData);
            }

            //加入副本信息
            if (!m_DungeonDataDic.ContainsKey(info.ID))
            {
                m_DungeonDataDic.Add(info.ID, info);
            }
        }
    }