private void Start() { // Get the parent as an ISelectionBar. ISelectionBar <ToolIcon> selectionBar = GetComponentInParent <ISelectionBar <ToolIcon> >(); // When this button is clicked, invoke the event on the parent selection bar. button.onClick.AddListener(() => selectionBar.OnButtonSelected(this)); }
public void InitialiseFromCrop(ModalWindowController modalWindowController, ISelectionBar <SeedGeneration> selectionBar, Tooltip tooltip, CropTile cropTile) { // Set dependencies. this.modalWindowController = modalWindowController; seedListController = selectionBar; this.tooltip = tooltip; // NOTE: You may think that it would be easier to use GetComponentInParent, however, this returns the vertical layout group that's part of this object instead. parentList = transform.parent.GetComponent <VerticalLayoutGroup>(); // Set label and icon. generationName.text = cropTile.Name; cropIcon.sprite = cropTile.Icon; }
private void Start() { // Get the parent as an ISelectionBar. ISelectionBar <TileIcon> selectionBar = GetComponentInParent <ISelectionBar <TileIcon> >(); // Get the toggle component of the GameObject. Toggle toggle = GetComponent <Toggle>(); // When the value changes and this toggle becomes selected, call the function on the selection bar. toggle.onValueChanged.AddListener((selected) => { if (selected) { selectionBar.OnButtonSelected(this); } }); // Set the toggle group of the toggle. toggle.group = GetComponentInParent <ToggleGroup>(); }
public void InitialiseFromGeneration(ModalWindowController modalWindowController, ISelectionBar <SeedGeneration> selectionBar, Tooltip tooltip, SeedGeneration seedGeneration) { // Set the seed generation. this.seedGeneration = seedGeneration; // Bind the main button to select this generation. selectionButton.onClick.AddListener(() => selectionBar.OnButtonSelected(seedGeneration)); // Bind the filter button to create a new filter window. filterButton.onClick.AddListener(() => { FilterWindowController filterWindowController = modalWindowController.CreateModalWindow <FilterWindowController>(filterWindowPrefab.gameObject); filterWindowController.CreateFrom(modalWindowController, this.seedGeneration); }); // Hide the filter button if the generation is 0, as that's the infinite pool of seeds. if (this.seedGeneration.Generation == 0) { filterButton.gameObject.SetActive(false); } // Set the tooltip object of anything that needs it. foreach (TooltipActivator tooltipActivator in GetComponentsInChildren <TooltipActivator>()) { tooltipActivator.Tooltip = tooltip; } // Refresh the display. Refresh(); }