// Start is called before the first frame update
    void Start()
    {
        localPlayer      = GameObject.FindGameObjectWithTag("LocalPlayer").GetComponent <Player>();
        scrollController = UIScrollable.GetComponent <UIScrollableController>();

        // adding onClick listener for UI buttons
        mainButton.onClick.AddListener(() =>
        {
            SoundManager.instance.PlaySingle(SoundManager.buttonconfirm);
            UICanvasHandler.instance.ActivateSpellbookButtons(false);
            SceneManager.LoadScene("MainPlayerScene");
        });

        settingsButton.onClick.AddListener(() =>
        {
            SoundManager.instance.PlaySingle(SoundManager.buttonconfirm);
            UICanvasHandler.instance.ActivateSpellbookButtons(false);
            SceneManager.LoadScene("SettingsScene");
        });

        foreach (Spell s in localPlayer.Spellcaster.chapter.spellsAllowed)
        {
            GameObject spellButton = Instantiate(spellButtonPrefab);
            UISpellButtonController buttonController = spellButton.GetComponent <UISpellButtonController>();
            buttonController.SetTitle(s.sSpellName);
            buttonController.SetText(s.sSpellInfo);

            // set button icons
            if (s.combatSpell)
            {
                buttonController.SetIcon(combatIcon);
            }
            else
            {
                buttonController.SetIcon(nonCombatIcon);
            }

            // set button colors
            if (s.iTier == 3)
            {
                buttonController.SetColor(tier3Color);
            }
            else if (s.iTier == 2)
            {
                buttonController.SetColor(tier2Color);
            }
            else
            {
                buttonController.SetColor(tier1Color);
            }

            scrollController.AddElement(spellButton);
            spellButton.GetComponent <Button>().onClick.AddListener(() => ShowSpellInfo(s));
        }

        // set panel holder as last sibling
        PanelHolder.instance.SetPanelHolderLast();
    }
    private void Start()
    {
        localPlayer      = GameObject.FindGameObjectWithTag("LocalPlayer").GetComponent <Player>();
        scrollController = UIScrollable.GetComponent <UIScrollableController>();

        if (localPlayer.Spellcaster.chapter.spellsCollected.Count > 0)
        {
            noSpellsText.text = "";
        }

        // disable spell cast/charge if not player's turn
        if (!localPlayer.bIsMyTurn)
        {
            castButton.interactable = false;
        }

        foreach (Spell s in localPlayer.Spellcaster.chapter.spellsCollected)
        {
            GameObject spellButton = Instantiate(spellButtonPrefab);
            UISpellButtonController buttonController = spellButton.GetComponent <UISpellButtonController>();
            buttonController.SetTitle(s.sSpellName);
            buttonController.SetText(s.sSpellInfo);

            // set button icons
            if (s.combatSpell)
            {
                buttonController.SetIcon(combatIcon);
            }
            else
            {
                buttonController.SetIcon(nonCombatIcon);
            }

            // set button colors
            if (s.iTier == 3)
            {
                buttonController.SetColor(tier3Color);
            }
            else if (s.iTier == 2)
            {
                buttonController.SetColor(tier2Color);
            }
            else
            {
                buttonController.SetColor(tier1Color);
            }

            scrollController.AddElement(spellButton);
            spellButton.GetComponent <Button>().onClick.AddListener(() => OpenSpellPanel(s));
        }

        // set panel holder as last sibling
        PanelHolder.instance.SetPanelHolderLast();
    }
Пример #3
0
    public void ConfigureSpellButton(GameObject instance)
    {
        UISpellButtonController controller = instance.GetComponent <UISpellButtonController>();

        if (controller != null)
        {
            controller.SetColor(Random.ColorHSV(0.5F, 1.0F, 0.8F, 1.0F));
            controller.SetIcon(Random.value > 0.5F ? combatSprite : nonCombatSprite);
            controller.SetTitle(string.Format("Spell {0}", _counter));
            controller.SetText(string.Format("Spell Description {0}", _counter));
            _counter += 1;
        }
    }