2013-08-25 2 views
1

나는 유니티에서 내가 만들고있는 게임의 임무를 손쉽게 만들 수있는 방법을 찾고 있습니다. 그래서 XML 파일을 통해 제대로 작동하는지 테스트하기로 결정했습니다. 내 XML 파일이 유효합니다. 그래서 누군가 나를 도와 줄 수 있니?Unity JS 및 XML. 항목 가져 오기

import System.Xml; 
import System.IO; 

function Start() { 
    var mission = getXMLFile("C:/test.plz"); 
    //Debug.Log(mission); 
    var xmlDoc = new XmlDocument(); 
    xmlDoc.LoadXml(mission); 
    xmlDoc.GetElementsByTagName("mission"); 
    Debug.Log(xmlDoc['stages'].id['1']['hud_icon']); 
} 

XML 파일을 얻을 수있는 다른 기능이 있습니다 : 어떤 시점에서

function getXMLFile(filepathIncludingFileName : String) { 
    var sr = new File.ReadAllText(filepathIncludingFileName); 
    return sr; 
} 

답변

0

, 당신이 할 : xmlDoc.GetElementsByTagName("mission");은.

이 있어야한다 :이 XmlNodeList missionList = xmlDoc.GetElementsByTagName("mission");

, 당신은 그 임무로 모든 작업을 수행 할 수 있습니다.

foreach (XmlNode missionInfo in missionList) 
{ 
    XmlNodeList missioncontent = missionInfo.ChildNodes; 

    foreach (XmlNode missionItems in missioncontent) //The nodes 
    { 
     if(missionItems.Name == "stages") 
     { 
      //You'll have the stage 
     } 
     if(levelsItens.Name == "hud_icon") 
     { 
      //You'll have the hud icon object 
     } 
     if(levelsItens.Name == "id") 
     { 
      //You'll have the ID 
     } 
    } 
} 
+0

나를 도와 주셔서 감사합니다. 저에게 올바른 방향으로 임무 XML 파일을 파싱 해 주셔서 감사합니다. – Jake