Example #1
0
    public override void Open()
    {
        if (spawnedButtons.Count > 0)
        {
            for (int i = spawnedButtons.Count - 1; i >= 0; i--)
            {
                Destroy(spawnedButtons[i]);
            }
        }
        spawnedButtons.Clear();

        IInteractable[] interactions = target.GetComponents <IInteractable>();
        for (int i = 0; i < interactions.Length; i++)
        {
            if (!interactions[i].IsEnabled())
            {
                continue;
            }
            InteractionButton interactionButton = Instantiate(interactionButtonPrefab, transform);
            spawnedButtons.Add(interactionButton.gameObject);
            string interactionName = interactions[i].GetName();
            int    index           = i;
            interactionButton.button.onClick.AddListener(() =>
            {
                InteractionSystem.SendInteraction(interactions[index]);
                Close();
            });

            interactionButton.text.enabled = interactions[i].GetIcon() == null;
            interactionButton.icon.enabled = interactions[i].GetIcon();

            interactionButton.text.SetText(interactions[i].GetName());
            interactionButton.icon.sprite = interactions[i].GetIcon();

            interactionButton.info = interactions[i].GetName();
        }

        gameObject.SetActive(true);
        float duration = .5f;

        open = true;
        tweener.Kill();
        canvasGroup.alpha = 1;
        tweener           = DOTween.To(x => SetRadius(x), 0f, openRadius, duration).SetEase(Ease.OutElastic);
    }