private void PrepareToBuy() { var king = King.dict[currentCastle.army.color]; // Calculate canBuyList var tmp = new List <Unit.Name>(); foreach (var name in allNormalNamesCanBuy) { if (currentCastle.CanBuy(name)) { tmp.Add(name); } } castleKingName = king.name; if (currentCastle.CanBuy(castleKingName)) { tmp.Add(castleKingName); } canBuyList = tmp; if (!king.gameObject.activeSelf) { kingButton.gameObject.SetActive(true); kingButton.image.sprite = canBuyList.Contains(castleKingName) ? R.asset.prefab.units[castleKingName].spriteRenderer.sprite : king.sleepSprite; } else { kingButton.gameObject.SetActive(false); } // Modify all buttons by current battle conditions foreach (var name in allNormalNamesCanBuy) { buttons[name].image.sprite = canBuyList.Contains(name) ? R.asset.sprite.units[name][currentCastle.army.color] : R.asset.prefab.units[name].sleepSprite; } }