private void OnBuildDone() { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.transform.position = transform.position; StaticEntityProperties props = EntitiesHolder.LoadEntityById(_id) as StaticEntityProperties; (go.AddComponent <StorageBuilding>() as BaseUnit).OnCreated(props.scriptInfo.arguments); Destroy(gameObject); }
public static StaticEntityProperties[] ParseBuildings(string content) { XmlReader reader = XmlReader.Create (new StringReader (content)); List<StaticEntityProperties> entities = new List<StaticEntityProperties> (); StaticEntityProperties current = null; while (reader.Read()) { if(reader.IsStartElement("building")) { if(current != null) { entities.Add(current); } current = new StaticEntityProperties(); } if(current != null) { if(reader.IsStartElement("id")) { current.Id = reader.ReadElementContentAsInt(); } if(reader.IsStartElement("name")) { current.Name = reader.ReadElementContentAsString(); } if(reader.IsStartElement("resources")) { int food, wood, gold = 0; food = int.Parse(reader.GetAttribute("food")); gold = int.Parse(reader.GetAttribute("gold")); wood = int.Parse(reader.GetAttribute("wood")); current.NecessaryResources = new ResourceSet(wood, food, gold); } if(reader.IsStartElement("description")) { current.Description = reader.ReadElementContentAsString(); } if(reader.IsStartElement("availableOn")) { current.AvailableOn = reader.ReadElementContentAsInt(); } if(reader.IsStartElement("level")) { current.Level = reader.ReadElementContentAsInt(); } } } if (current != null) { entities.Add(current); } return entities.ToArray(); }
private static void PlaceBuilding() { GameObject newBuilding = GameObject.CreatePrimitive(PrimitiveType.Cube); newBuilding.transform.position = _building.transform.position; StaticEntityProperties properties = EntitiesHolder.LoadEntityById(_buildingId) as StaticEntityProperties; print(newBuilding); print(properties.scriptInfo); newBuilding.AddComponent(properties.scriptInfo.script); for (int i = 0; i < properties.scriptInfo.arguments.Length; i++) { print(properties.scriptInfo.arguments[i]); } (newBuilding.GetComponent(properties.scriptInfo.script) as BaseUnit).OnCreated(properties.scriptInfo.arguments); DestroyCurrent(); }
private static void PlaceBuilding() { GameObject newBuilding = GameObject.CreatePrimitive(PrimitiveType.Cube); newBuilding.transform.position = _building.transform.position; StaticEntityProperties properties = EntitiesHolder.LoadEntityById(_buildingId) as StaticEntityProperties; print(newBuilding); print(properties.scriptInfo); Construction c = newBuilding.AddComponent <Construction>(); c.OnCreated(new string[1] { properties.Id.ToString() }); _villager.ActionCallback(c); DestroyCurrent(); }
public static StaticEntityProperties[] ParseBuildings(string content) { XmlReader reader = XmlReader.Create(new StringReader(content)); List <StaticEntityProperties> entities = new List <StaticEntityProperties> (); StaticEntityProperties current = null; while (reader.Read()) { if (reader.IsStartElement("building")) { if (current != null) { entities.Add(current); } current = new StaticEntityProperties(); } if (current != null) { if (reader.IsStartElement("id")) { current.Id = reader.ReadElementContentAsInt(); } if (reader.IsStartElement("name")) { current.Name = reader.ReadElementContentAsString(); } if (reader.IsStartElement("resources")) { int food, wood, gold = 0; food = int.Parse(reader.GetAttribute("food")); gold = int.Parse(reader.GetAttribute("gold")); wood = int.Parse(reader.GetAttribute("wood")); current.NecessaryResources = new ResourceSet(wood, food, gold); } if (reader.IsStartElement("description")) { current.Description = reader.ReadElementContentAsString(); } if (reader.IsStartElement("availableOn")) { current.AvailableOn = reader.ReadElementContentAsInt(); } if (reader.IsStartElement("level")) { current.Level = reader.ReadElementContentAsInt(); } if (reader.IsStartElement("script")) { Debug.Log(reader.AttributeCount); current.scriptInfo = new StaticUnitScriptInfo(string.Empty, new string [reader.AttributeCount]); for (int i = 0; i < reader.AttributeCount; i++) { Debug.Log(reader.GetAttribute("arg" + i)); current.scriptInfo.arguments[i] = reader.GetAttribute("arg" + i); } current.scriptInfo.script = reader.ReadElementContentAsString(); } } } if (current != null) { entities.Add(current); } return(entities.ToArray()); }
public static StaticEntityProperties[] ParseBuildings(string content) { XmlReader reader = XmlReader.Create (new StringReader (content)); List<StaticEntityProperties> entities = new List<StaticEntityProperties> (); StaticEntityProperties current = null; while (reader.Read()) { if(reader.IsStartElement("building")) { if(current != null) { entities.Add(current); } current = new StaticEntityProperties(); } if(current != null) { if(reader.IsStartElement("id")) { current.Id = reader.ReadElementContentAsInt(); } if(reader.IsStartElement("name")) { current.Name = reader.ReadElementContentAsString(); } if(reader.IsStartElement("resources")) { int food, wood, gold = 0; food = int.Parse(reader.GetAttribute("food")); gold = int.Parse(reader.GetAttribute("gold")); wood = int.Parse(reader.GetAttribute("wood")); current.NecessaryResources = new ResourceSet(wood, food, gold); } if(reader.IsStartElement("description")) { current.Description = reader.ReadElementContentAsString(); } if(reader.IsStartElement("availableOn")) { current.AvailableOn = reader.ReadElementContentAsInt(); } if(reader.IsStartElement("level")) { current.Level = reader.ReadElementContentAsInt(); } if (reader.IsStartElement("hp")) { current.Hp = reader.ReadElementContentAsInt(); } if (reader.IsStartElement("script")) { Debug.Log (reader.AttributeCount); current.scriptInfo = new StaticUnitScriptInfo (string.Empty, new string [reader.AttributeCount]); for (int i = 0; i < reader.AttributeCount; i++) { Debug.Log (reader.GetAttribute ("arg" + i)); current.scriptInfo.arguments[i] = reader.GetAttribute ("arg" + i); } current.scriptInfo.script = reader.ReadElementContentAsString(); } } } if (current != null) { entities.Add(current); } return entities.ToArray(); }