빌드시에 특정 파일 읽지 못하는 경우

2011. 5. 3. 08:40C# And Unity

Resource폴더에 넣은 파일들은 기본적으로 빌드시에 포함됩니다.

하지만 빌드시에 정상적으로 해당 자원들을 읽지 못하는 경우가 있는데요.

이는 Resources.Load를 사용하지 않았기 때문입니다.

XML을 읽을 때나, 다른 Text파일들을 읽을때는 이점 유의하시기바랍니다.

//data path : Resources/Data.xml

TextAsset textAsset = (TextAsset)Resources.Load("Data", typeof(TextAsset));
XmlTextReader tr = new XmlTextReader( new StringReader(textAsset.text));
XmlDocument xdoc = new XmlDocument();
xdoc.Load(tr);

XmlNode root = xdoc.DocumentElement;
if (root.HasChildNodes) 
{
XmlNodeList child = root.ChildNodes;
for (int i = 0 ; i < child.Count; ++i) 
{
XmlNodeList data = child[i].ChildNodes;

// set data info.
......

}
}