void CreateNeedPrototypes() { needPrototypes = new Dictionary <string, Need>(); // READ FURNITURE PROTOTYPE XML FILE HERE // TODO: Probably we should be getting past a StreamIO handle or the raw // text here, rather than opening the file ourselves. string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "Data"); filePath = System.IO.Path.Combine(filePath, "Need.xml"); string furnitureXmlText = System.IO.File.ReadAllText(filePath); XmlTextReader reader = new XmlTextReader(new StringReader(furnitureXmlText)); int needCount = 0; if (reader.ReadToDescendant("Needs")) { if (reader.ReadToDescendant("Need")) { do { needCount++; Need need = new Need(); try { need.ReadXmlPrototype(reader); } catch { Debug.LogError("Error reading need prototype for: " + need.needType); } needPrototypes[need.needType] = need; } while (reader.ReadToNextSibling("Need")); } else { Debug.LogError("The need prototype definition file doesn't have any 'Need' elements."); } Debug.Log("Need prototypes read: " + needCount.ToString()); } }
void LoadNeedPrototypesFromFile(string needXmlText) { // READ FURNITURE PROTOTYPE XML FILE HERE // TODO: Probably we should be getting past a StreamIO handle or the raw // text here, rather than opening the file ourselves. XmlTextReader reader = new XmlTextReader(new StringReader(needXmlText)); int needCount = 0; if (reader.ReadToDescendant("Needs")) { if (reader.ReadToDescendant("Need")) { do { needCount++; Need need = new Need(); try { need.ReadXmlPrototype(reader); } catch { Debug.LogError("Error reading need prototype for: " + need.needType); } needPrototypes[need.needType] = need; } while (reader.ReadToNextSibling("Need")); } else { Debug.LogError("The need prototype definition file doesn't have any 'Need' elements."); } Debug.Log("Need prototypes read: " + needCount.ToString()); } }