public PieceConfig getConfig(int id) { if (cache.ContainsKey(id)) { return(cache [id]); } PieceConfig config = new PieceConfig(); config.id = id; XmlNode node = xml.SelectSingleNode("//piece[@id = '" + id + "']"); if (node == null) { Debug.LogError("Id:" + id + " piece not found!"); return(null); } XmlNodeList blocks = node.SelectNodes("blocks/block"); config.collision = getCollision(blocks); config.blockCount = blocks.Count; config.prefab = getPrefab(node.SelectSingleNode("prefab")); config.placeholder = getTexture(node.SelectSingleNode("placeholder")); cache.Add(id, config); return(config); }
private void calculateBlocks(Dictionary <int, int> blocks, Level level) { List <Block> block = new List <Block> (); PieceFactory factory = PieceFactory.getInstance(); foreach (KeyValuePair <int, int> entry in blocks) { PieceConfig config = factory.getConfig(entry.Key); if (config == null) { throw new System.InvalidOperationException("Piece is null"); } for (int i = 0; i < (entry.Value / config.blockCount); i++) { block.Add(makeBlock(config)); } } level.setBlocks(block.ToArray()); }
public static Block createFromConfig(PieceConfig config) { return(new Block(config.id, 0, config.collision, config.prefab, config.placeholder)); }
private Block makeBlock(PieceConfig config) { return(Block.createFromConfig(config)); }