// 从XML中载入棋子模板信息 public void LoadPieceInfoFromXML() { string filePath = Application.dataPath + "/Resources/Piece.xml"; if (File.Exists(filePath)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filePath); XmlNodeList node = xmlDoc.SelectSingleNode("Piece").ChildNodes; foreach (XmlElement PieceInfo in node) { //item下面的节点 //Debug.Log(ele.Name); Piece NewPiece = new Piece(); NewPiece.SetPiecePedestalInfo(GetPiecePedestalInfo("TerrainePedestal1")); NewPiece.SetPieceStatusInfo(GetPieceStatusInfo("BanelingCommando")); foreach (XmlElement PieceInfoItem in PieceInfo.ChildNodes) { //Debug.Log(i1.Name); if (PieceInfoItem.Name == "PieceID") { NewPiece.SetPieceID(PieceInfoItem.InnerText); } else if (PieceInfoItem.Name == "PieceName") { NewPiece.SetPieceName(PieceInfoItem.InnerText); } else if (PieceInfoItem.Name == "PieceMineralCost") { NewPiece.SetPieceMineralCost(PublicUtility.StringToInt(PieceInfoItem.InnerText)); } else if (PieceInfoItem.Name == "PieceGasCost") { NewPiece.SetPieceGasCost(PublicUtility.StringToInt(PieceInfoItem.InnerText)); } else if (PieceInfoItem.Name == "PieceRetreatThreshold") { // 设置棋子撤退阈值 NewPiece.SetRetreatThreshold(PublicUtility.StringToFloat(PieceInfoItem.InnerText)); } else if (PieceInfoItem.Name == "PiecePedestalID") { //Debug.Log(PieceInfoItem.InnerText); NewPiece.SetPiecePedestalInfo(GetPiecePedestalInfo(PieceInfoItem.InnerText)); } else if (PieceInfoItem.Name == "PieceStatusID") { //Debug.Log(PieceInfoItem.InnerText); NewPiece.SetPieceStatusInfo(GetPieceStatusInfo(PieceInfoItem.InnerText)); } else if (PieceInfoItem.Name == "PieceDeathEffectID") { //Debug.Log(PieceInfoItem.InnerText); NewPiece.SetPieceDeathEffect(GetEffect(PieceInfoItem.InnerText)); } else if (PieceInfoItem.Name == "PieceIncludeUnit") { string ContainUnitID = ""; int ContainUnitNum = 0; foreach (XmlElement IncludeUnitItem in PieceInfoItem.ChildNodes) { if (IncludeUnitItem.Name == "UnitID") { //Debug.Log(IncludeUnitItem.InnerText); ContainUnitID = IncludeUnitItem.InnerText; } else if (IncludeUnitItem.Name == "UnitNum") { //Debug.Log(IncludeUnitItem.InnerText); ContainUnitNum = PublicUtility.StringToInt(IncludeUnitItem.InnerText); } } NewPiece.LoadUnitInfo(GetUnit(ContainUnitID), ContainUnitNum); } else if (PieceInfoItem.Name == "PieceDescription") { foreach (XmlElement PieceDescriptionItem in PieceInfoItem.ChildNodes) { if (PieceDescriptionItem.Name == "PieceDescriptionItem") { //Debug.Log(PieceDescriptionItem.InnerText); NewPiece.AddCardDescriptionItem(PieceDescriptionItem.InnerText); } } } } // 将新加载的棋子添加到游戏棋子模板库当中 AddPiece(NewPiece); } } }