Exemplo n.º 1
0
    public void InitValues(int IndexInScrollList, MonsterScript newMonster, string btnAction)
    {
        btnIndex = IndexInScrollList;
        monster = newMonster;

        monsterImageObj = Instantiate(ImagePrefab, new Vector3(-120, 0, 0), new Quaternion(0, 0, 0, 0)) as GameObject;
        monsterImageObj.transform.SetParent(this.gameObject.transform, false);
        monsterImage = monsterImageObj.GetComponent<Image>();
        monsterImage.sprite = newMonster.GetSprite();

        nameTxtObj = Instantiate(TextPrefab, new Vector3(230, 25, 0), new Quaternion(0, 0, 0, 0)) as GameObject;
        nameTxtObj.transform.SetParent(this.gameObject.transform, false);
        nameTxt = nameTxtObj.GetComponent<Text>();

        StatsTxtObj = Instantiate(StatsPrefab, new Vector3(230, 0, 0), new Quaternion(0, 0, 0, 0)) as GameObject;
        StatsTxtObj.transform.SetParent(this.gameObject.transform, false);
        StatsTxt = StatsTxtObj.GetComponent<Text>();

        LevelTxtObj = Instantiate(TextPrefab, new Vector3(230, -25, 0), new Quaternion(0, 0, 0, 0)) as GameObject;
        LevelTxtObj.transform.SetParent(this.gameObject.transform, false);
        LevelTxt = LevelTxtObj.GetComponent<Text>();

        SliderObj = Instantiate(SliderPrefab, new Vector3(260, -25, 0), new Quaternion(0, 0, 0, 0)) as GameObject;
        SliderObj.transform.SetParent(this.gameObject.transform, false);
        slider = SliderObj.GetComponent<Slider>();

        CostTxtObj = Instantiate(TextPrefab, new Vector3(320, 25, 0), new Quaternion(0, 0, 0, 0)) as GameObject;
        CostTxtObj.transform.SetParent(this.gameObject.transform, false);
        CostTxt = CostTxtObj.GetComponent<Text>();

        if (btnAction != "MISSION")
        {
            ActionBtnObj = Instantiate(ActionBtnPrefab, new Vector3(330, 25, 0), new Quaternion(0, 0, 0, 0)) as GameObject;
            ActionBtnObj.transform.SetParent(this.gameObject.transform, false);
            ActionBtn = ActionBtnObj.GetComponent<Button>();
            ActionBtnTxt = ActionBtnObj.transform.GetChild(0).GetComponent<Text>();

            if (btnAction == "SELL") ActionBtnTxt.text = "FIRE";
        }
        else
        {
            ActionBtnObj = this.gameObject;
            ActionBtn = ActionBtnObj.GetComponent<Button>();
            ActionBtn.onClick.AddListener(() => gameManagerScript.SelectMonster(btnIndex));
        }

        nameTxt.text = monster.GetName();
        LevelTxt.text = monster.GetLevel().ToString();
        StatsTxt.text = "Stats: " + monster.GetStr().ToString() + " " + monster.GetAgi().ToString() + " " + monster.GetWill().ToString();
        CostTxt.text = "£" + monster.GetPrice().ToString();
        slider.maxValue = monster.GetXPReq();
        slider.value = monster.GetXP();

        GameManager = GameObject.FindGameObjectWithTag("GameManager");
        gameManagerScript = GameManager.GetComponent<GameManagerScript>();

        if (btnAction == "BUY") ActionBtn.onClick.AddListener(() => gameManagerScript.Buy(btnIndex));

        if (btnAction == "SELL") ActionBtn.onClick.AddListener(() => gameManagerScript.Sell(btnIndex));
    }