コード例 #1
0
    /* Called every time this panel is activated by the controller */
    public override void OnActivation()
    {
        //Clear old items
        for (int i = holdingPanel.childCount - 1; i >= 0; i--)
        {
            Destroy(holdingPanel.GetChild(i).gameObject);
        }

        //Set up new item displays
        displayed = examinedEquipment.equipmentSlots;
        switch (queuedAction)
        {
        case ItemAction.EQUIP:
            EquipableItem equip = queuedItem.held[0].equipable;
            displayed = displayed.FindAll(x => x.type.Contains(equip.primarySlot));
            if (displayed.Count == 0)
            {
                //TODO: Console log that you apparently can't wear this
                Debug.LogError($"Player can't equip, as they have no slots of type {equip.primarySlot}");
                return;
            }
            else if (displayed.Count == 1)
            {
                //You probably just want to equip this? We'll just go ahead and do it
                examinedEquipment.monster.SetAction(new EquipAction(queuedItem.position, displayed[0].position));
                //examinedEquipment.Equip(queuedItem.position, displayed[0].position);
                ExitAllWindows();
                break;
            }
            break;
        }

        //Sort the list into item types
        //ItemType currentType = ItemType.NONE;

        for (int i = 0; i < displayed.Count; i++)
        {
            GameObject     instance = Instantiate(EquipmentSlotPrefab);
            EquipSlotPanel current  = instance.GetComponent <EquipSlotPanel>();
            EquipmentSlot  slot     = displayed[i];

            //Set up item readout
            current.Setup(this, slot.position);
            current.RebuildGraphics();
            instance.transform.SetParent(holdingPanel);
        }
    }