示例#1
0
    private EnemyButtonUI InsertNewButton(GameObject btnGO, int index)
    {
        EnemyButtonUI btn = new EnemyButtonUI(btnGO, index);

        btn.button.onClick.AddListener(() => { this.OnTargetButtonClick(btn.index); });

        this.buttons.Add(btn);

        return(btn);
    }
示例#2
0
    void Awake()
    {
        this.targets = new List <Fighter>();
        this.buttons = new List <EnemyButtonUI>();

        this.rectTransform = this.GetComponent <RectTransform>();
        this.baseHeight    = this.rectTransform.rect.height;

        // Añadimos el botón de ejemplo como el primer botón disponible
        EnemyButtonUI btn = this.InsertNewButton(this.sampleButton, 0);

        btn.Hide();

        this.Hide();
    }
示例#3
0
    public void Show(PlayerFighter playerFighter, Fighter[] targets)
    {
        this.gameObject.SetActive(true);

        this.targetFighter = playerFighter;

        int btnIndex = 0;

        foreach (var target in targets)
        {
            EnemyButtonUI btn = this.ActivateNextButton(btnIndex);
            btn.SetText(target.idName);

            this.targets.Add(target);

            btnIndex++;
        }

        this.rectTransform.sizeDelta = new Vector2(
            this.rectTransform.rect.width,
            this.baseHeight * targets.Length
            );
    }
示例#4
0
    private EnemyButtonUI ActivateNextButton(int index)
    {
        foreach (var btn in this.buttons)
        {
            if (btn.index == index)
            {
                btn.Show();
                return(btn);
            }
        }

        // Clonamos el botón de ejemplo
        GameObject btnGO = Instantiate(this.sampleButton);

        btnGO.transform.SetParent(this.transform);
        btnGO.transform.localScale = Vector3.one;

        // Lo añadimos como nuevo botón disponible
        EnemyButtonUI but = this.InsertNewButton(btnGO, index);

        but.Show();

        return(but);
    }