示例#1
0
    public void Enable(Item item, Vector3 position)
    {
        this.GetComponent <RectTransform>().position = position;

        nameLabel.text = item.name;
        nameLabel.gameObject.SetActive(true);

        valueLabel.text = valueText + item.value;
        valueLabel.gameObject.SetActive(true);

        if (item.description != null || item.description != "")
        {
            descriptionLabel.text = item.description;
        }

        if (item is EquippableItem)
        {
            EquippableItem ei = (EquippableItem)item;

            strReqLabel.text = strReqText + ei.requirements.strength;
            strReqLabel.gameObject.SetActive(true);
            dexReqLabel.text = dexReqText + ei.requirements.dexterity;
            dexReqLabel.gameObject.SetActive(true);
            intReqLabel.text = intReqText + ei.requirements.intelligence;
            intReqLabel.gameObject.SetActive(true);

            requirementsLabel.gameObject.SetActive(true);
            requirementsParent.SetActive(true);
        }

        if (item is Weapon)
        {
            Weapon w = (Weapon)item;

            atkLabel.text = atkText + w.damage.ToString();
            atkLabel.gameObject.SetActive(true);

            foreach (ItemModifier mod in w.Modifiers)
            {
                TextMeshProUGUI modLabel = Instantiate(modifierExample, modifiersParent.transform).GetComponent <TextMeshProUGUI>();
                modLabel.text = mod.type.ToString() + " " + ItemModifier.CalculationMethodToString(mod.calculationMethod) + mod.Value;
                modifierObjects.Add(modLabel.gameObject);
                modLabel.gameObject.SetActive(true);
            }
            modifiersLabel.gameObject.SetActive(true);
            modifiersParent.SetActive(true);
        }

        if (item is Armor)
        {
            Armor a = (Armor)item;

            defLabel.text = defText + a.defence.ToString();
            atkLabel.gameObject.SetActive(true);
        }

        gameObject.SetActive(true);
    }