Example #1
0
        private void CreateFlowerButtons(List <Flower> flowers)
        {
            GridObjectCollection      buttonCollection       = commandPanel.GetComponentInChildren <GridObjectCollection>();
            ScrollingObjectCollection buttonCollectionScroll = commandPanel.GetComponentInChildren <ScrollingObjectCollection>();
            float n = 0.0f;

            foreach (Flower flower in flowers)
            {
                GameObject button = GameObject.Instantiate <GameObject>(flowerButtonPrefab, buttonCollection.transform.position, Quaternion.identity);
                button.transform.parent = buttonCollection.transform;
                FlowerProperties buttonFlowerProperties = button.GetComponentInChildren <FlowerProperties>();
                buttonFlowerProperties.Name           = flower.Name;
                buttonFlowerProperties.PlantingRadius = flower.PlantingRadius;
                TextMeshPro[] buttonText = button.GetComponentsInChildren <TextMeshPro>();
                foreach (TextMeshPro text in buttonText)
                {
                    text.text = flower.Name;
                }
                Interactable buttonInteractable = button.GetComponentInChildren <Interactable>();
                buttonInteractable.OnClick.AddListener(() => SelectRadius(button));
                n += 0.05f;
            }
            buttonCollection.UpdateCollection();
            buttonCollectionScroll.UpdateContent();
            buttonCollectionScroll.gameObject.SetActive(false);
        }
Example #2
0
        public void SelectRadius(GameObject button)
        {
            FlowerProperties buttonFlowerProperties = button.GetComponentInChildren <FlowerProperties>();

            this.currentPlantRadius = buttonFlowerProperties.PlantingRadius;
            ScrollingObjectCollection buttonCollectionScroll = commandPanel.GetComponentInChildren <ScrollingObjectCollection>();

            buttonCollectionScroll.gameObject.SetActive(false);
        }