hi there im currently trying to program my game to take xml files that i have writen but i keep getting error like this no matter wat i do(Assets/enemy1.cs(10,17): error CS0246: The type or namespace name `Texturedata’ could not be found. Are you missing a using directive or an assembly reference?)
here is my enemy1.cs code:
using UnityEngine;
using System.Collections;
using System.Xml;
using System.IO;
public class TextureManager : MonoBehaviour
{
public Texture2D textureFile;
public TextAsset AtlasFile;
private Texturedata[] atlas;
public static TextureManager Instance { get { return instance; } }
private static TextureManager instance = null;
void Awake()
{
if (instance != null && instance != this)
{
Destroy(this.gameObject);
return;
}
else
{
instance = this;
}
DontDestroyOnLoad(this.gameObject);
string textData = atlasFile.text;
ParseXML( textData );
}
//load the xml file and parse it.
private void ParseXML(string xmlData)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load( new StringReader(xmlData) );
string xmlPathPattern = "//atlas/image";
XmlNodeList nodeList = xmlDoc.SelectNodes(xmlPathPattern );
atlas = new TextureData[nodeList.Count];
int counter = 0;
foreach(XmlNode node in nodeList)
{
atlas[counter] = ParseNode(node);
counter++;
}
}
//get the data from each image node.
private TextureData ParseNode(XmlNode node)
{
//grab the nodes
XmlNode nameNode = node.FirstChild;
XmlNode xNode = nameNode.NextSibling;
XmlNode yNode = xNode.NextSibling;
XmlNode widthNode = yNode.NextSibling;
XmlNode heightNode = widthNode.NextSibling;
//create the data struct
TextureData data;
data.name = nameNode.InnerXml;
data.x = int.Parse(xNode.InnerXml);
data.y = int.Parse(yNode.InnerXml);
data.width = int.Parse(widthNode.InnerXml);
data.height = int.Parse(heightNode.InnerXml);
//now scale the struct to uv normals (i.e. a 0 to 1 range)
data.x /= textureFile.width;
data.y /= textureFile.height;
data.width /= textureFile.width;
data.height /= textureFile.height;
return data;
}
//find the data they want from our atlas.
public TextureData GetTexture(string name)
{
//Search for the texture data he wants
foreach(TextureData data in atlas)
{
if(data.name == name)
{
return data;
}
}
//otherwise texture not found, so return an empty one.
return new TextureData();
}
}
and this is my “atlasfile.Xml” code for it:
<image>
<name>player</name>
<x>86</x>
<y>86</y>
<width>75</width>
<height>70</height>
</image>
<image>
<name>Mothership</name>
<x>167</x>
<y>167</y>
<width>169</width>
<height>169</height>
</image>
<image>
<name>enemy1</name>
<x>83</x>
<y>258</y>
<width>82</width>
<height>72</height>
</image>
<image>
<name>enemy2</name>
<x>83</x>
<y>167</y>
<width>85</width>
<height>85</height>
</image>
<image>
<name>enemy3</name>
<x>355</x>
<y>251</y>
<width>80</width>
<height>80</height>
</image>
<image>
<name>enemy4</name>
<x>254</x>
<y>84</y>
<width>76</width>
<height>80</height>
</image>
please help me its part of my school project