Game Development Reference
In-Depth Information
45 return;
46
47 //Get first node
48 XmlNode LanguageNode = LanguageNodes[0];
49
50 //Get text object
51 SampleGameMenu GM = Object.FindObjectOfType<SampleGameMenu>()
as SampleGameMenu;
52
53 //Loop through child xml nodes
54 foreach (XmlNode Child in LanguageNode.ChildNodes)
55 {
56 //Get text Id for this node
57 string TextID = Child.Attributes["id"].Value;
58 string LocalText = Child.InnerText;
59
60 //Loop through all fields
61 foreach(var field in GM.GetType().GetFields(BindingFlags.Instance
| BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.FlattenHierarchy))
62 {
63 //If field is a string then is relevant
64 if(field.FieldType == typeof(System.String))
65 {
66 //Get custom attributes for field
67 System.Attribute[] attrs = field.GetCustomAttributes(true) as
System.Attribute[];
68
69 foreach (System.Attribute attr in attrs)
70 {
71 if(attr is LocalizationTextAttribute)
72 {
73 //We've found text
74 LocalizationTextAttribute LocalAttr = attr as
LocalizationTextAttribute;
75
76 if(LocalAttr.LocalizationID.Equals( TextID ))