private void RenderUtilityButtons() { utilityItems = new List <GameObject>(); UnityEngine.Object buttonPrefab = Resources.Load("UI/MenuLeft/ConstructionMenu/Button"); Transform contentTransform = this.transform.FindChild("Scroll View").FindChild("Viewport").FindChild("Content"); BuildModeController buildModeController = WorldController.Instance.buildModeController; // For each furniture prototype in our world, create one instance // of the button to be clicked! foreach (string utilityKey in PrototypeManager.Utility.Keys) { if (PrototypeManager.Utility.Get(utilityKey).HasTypeTag("Non-buildable") && showAllFurniture == false) { continue; } GameObject gameObject = (GameObject)Instantiate(buttonPrefab); gameObject.transform.SetParent(contentTransform); furnitureItems.Add(gameObject); Utility proto = PrototypeManager.Utility.Get(utilityKey); string objectId = utilityKey; gameObject.name = "Button - Build " + objectId; gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(proto.LocalizationCode) }; Button button = gameObject.GetComponent <Button>(); button.onClick.AddListener(delegate { buildModeController.SetMode_BuildUtility(objectId); menuLeft.CloseMenu(); }); // http://stackoverflow.com/questions/1757112/anonymous-c-sharp-delegate-within-a-loop string utility = utilityKey; LocalizationTable.CBLocalizationFilesChanged += delegate { gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(PrototypeManager.Utility.Get(utility).LocalizationCode) }; }; Image image = gameObject.transform.GetChild(0).GetComponentsInChildren <Image>().First(); image.sprite = WorldController.Instance.utilitySpriteController.GetSpriteForUtility(utilityKey); } }