// Use this for initialization. private void Start() { tileTypes = TileType.LoadedTileTypes; BuildModeController bmc = WorldController.Instance.buildModeController; // For each furniture prototype in our world, create one instance // of the button to be clicked! foreach (TileType type in tileTypes) { GameObject go = (GameObject)Instantiate(buildFurnitureButtonPrefab); go.transform.SetParent(this.transform); TileType tileType = type; go.name = "Button - Build " + tileType.Type; // TODO: Not a elegant solution! Find a better way. if (type == TileType.Empty) { go.name = "Button - Remove " + tileType.Type; go.GetComponentInChildren <TextLocalizer>().defaultText = "remove"; } go.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(tileType.LocalizationCode) }; Button b = go.GetComponent <Button>(); b.onClick.AddListener(delegate { bmc.SetModeBuildTile(tileType); }); } lastLanguage = LocalizationTable.currentLanguage; }
private void RenderTileButtons() { tileItems = new List <GameObject>(); UnityEngine.Object buttonPrefab = Resources.Load("UI/MenuLeft/ConstructionMenu/Button"); Transform contentTransform = this.transform.Find("Scroll View").Find("Viewport").Find("Content"); BuildModeController buildModeController = WorldController.Instance.BuildModeController; foreach (TileType item in PrototypeManager.TileType.Values) { TileType tileType = item; string key = tileType.LocalizationName; GameObject gameObject = (GameObject)Instantiate(buttonPrefab); gameObject.transform.SetParent(contentTransform); tileItems.Add(gameObject); gameObject.name = "Button - Build Tile " + key; gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(key) }; Button button = gameObject.GetComponent <Button>(); button.onClick.AddListener(delegate { buildModeController.SetModeBuildTile(tileType); menuLeft.CloseCurrentMenu(); }); LocalizationTable.CBLocalizationFilesChanged += delegate { gameObject.transform.GetComponentInChildren <TextLocalizer>().formatValues = new string[] { LocalizationTable.GetLocalization(key) }; }; Image image = gameObject.transform.GetChild(0).GetComponentsInChildren <Image>().First(); image.sprite = SpriteManager.GetSprite("Tile", tileType.Type); } }