Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Dictionary<string, BuildingType> LoadBuildingTypesWithString() {
- Dictionary<string, BuildingType> buildingTypes = new Dictionary<string, BuildingType>();
- TextAsset text = Resources.Load<TextAsset>("Data/Buildings");
- XmlTextReader reader_parent = new XmlTextReader(new StringReader(text.text));
- if (reader_parent.ReadToDescendant("Buildings")) {
- if (reader_parent.ReadToDescendant("Building")) {
- do {
- string name = "";
- Sprite sprite;
- List<BuildCost> buildCosts = new List<BuildCost>();
- string rawLuaCode = "";
- XmlReader reader = reader_parent.ReadSubtree();
- while (reader.Read()) {
- switch (reader.Name) {
- case "Name":
- reader.Read();
- name = reader.ReadContentAsString();
- break;
- case "BuildCosts":
- string item = "";
- int amount = 0;
- XmlReader buildCost_reader = reader.ReadSubtree();
- while (buildCost_reader.Read()) {
- switch (buildCost_reader.Name) {
- case "Item":
- reader.Read();
- item = buildCost_reader.ReadContentAsString();
- break;
- case "Amount":
- reader.Read();
- amount = buildCost_reader.ReadContentAsInt();
- break;
- }
- }
- buildCosts.Add(new BuildCost(WorldController.instance.itemTypesString[item], amount));
- break;
- case "LUA":
- reader.Read();
- rawLuaCode = reader.ReadContentAsString();
- break;
- }
- }
- sprite = (Sprite)Resources.Load("BuildingTypes/Sprites/" + name, typeof(Sprite));
- buildingTypes.Add(name, new BuildingType(name, sprite, buildCosts, rawLuaCode));
- } while (reader_parent.ReadToNextSibling("Building"));
- } else {
- Debug.LogError("The Buildings definition file doesn't have any 'Building' elements");
- }
- } else {
- Debug.LogError("Did not find a 'Buildings' element in the definition file");
- }
- /*foreach (BuildingType t in Resources.LoadAll("BuildingTypes", typeof(BuildingType))) {
- buildingTypes.Add(t.name, t);
- }*/
- return buildingTypes;
- }
- public static List<BuildingType> LoadBuildingTypes() {
- List<BuildingType> buildingTypes = new List<BuildingType>();
- TextAsset text = Resources.Load<TextAsset>("Data/Buildings");
- XmlTextReader reader_parent = new XmlTextReader(new StringReader(text.text));
- if (reader_parent.ReadToDescendant("Buildings")) {
- if (reader_parent.ReadToDescendant("Building")) {
- do {
- string name = "";
- Sprite sprite;
- List<BuildCost> buildCosts = new List<BuildCost>();
- string rawLuaCode = "";
- XmlReader reader = reader_parent.ReadSubtree();
- while (reader.Read()) {
- switch (reader.Name) {
- case "Name":
- reader.Read();
- name = reader.ReadContentAsString();
- break;
- case "BuildCosts":
- string item = "";
- int amount = 0;
- XmlReader buildCost_reader = reader.ReadSubtree();
- while (buildCost_reader.Read()) {
- switch (buildCost_reader.Name) {
- case "Item":
- reader.Read();
- item = buildCost_reader.ReadContentAsString();
- break;
- case "Amount":
- reader.Read();
- amount = buildCost_reader.ReadContentAsInt();
- break;
- }
- }
- buildCosts.Add(new BuildCost(WorldController.instance.itemTypesString[item], amount));
- break;
- case "LUA":
- reader.Read();
- rawLuaCode = reader.ReadContentAsString();
- break;
- }
- }
- sprite = (Sprite)Resources.Load("BuildingTypes/Sprites/" + name, typeof(Sprite));
- buildingTypes.Add(new BuildingType(name, sprite, buildCosts, rawLuaCode));
- } while (reader_parent.ReadToNextSibling("Building"));
- } else {
- Debug.LogError("The Buildings definition file doesn't have any 'Building' elements");
- }
- } else {
- Debug.LogError("Did not find a 'Buildings' element in the definition file");
- }
- /*foreach (BuildingType t in Resources.LoadAll("BuildingTypes", typeof(BuildingType))) {
- buildingTypes.Add(t);
- }*/
- return buildingTypes;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement