コード例 #1
0
        // -------------------------------------------------------------------------------
        //
        // -------------------------------------------------------------------------------
        protected override void TemplateInitialize(GameObject templateInstance, T item)
        {
            PanelSlot panel = templateInstance.GetComponent <PanelSlot>();

            panel.Content            = item;
            panel.imgIcon.sprite     = GetIcon(item);
            panel.imgCurrency.sprite = GetCurrencyIcon(item);
            if (panel.imgCurrency.sprite == null)
            {
                panel.imgCurrency.enabled = false;
            }
            else
            {
                panel.imgCurrency.enabled = true;
            }
            panel.txtCost.text  = GetCost(item);
            panel.txtCost.color = GetTextColor(item);
            panel.txtName.text  = GetName(item);
            panel.txtName.color = GetTextColor(item);

            panel.btnTooltip.interactable = (item is MockEquipmentSlot) ? false : true;
            panel.btnAction.interactable  = CanActivate(item);
            panel.btnUpgrade.gameObject.SetActive(CanUpgrade(item));
            panel.btnTrash.gameObject.SetActive(CanTrash(item));
            panel.btnAction.UpdateText(GetActionText(item));

            panel.OnTooltipRequested += TooltipRequestedHandler;
            panel.OnActionRequested  += ActionRequestedHandler;
            panel.OnUpgradeRequested += UpgradeRequestedHandler;
            panel.OnTrashRequested   += TrashRequestedHandler;
        }
コード例 #2
0
        // -------------------------------------------------------------------------------
        // DisposeItem
        // -------------------------------------------------------------------------------
        protected override void DisposeItem(Transform item)
        {
            PanelSlot panel = item.GetComponent <PanelSlot>();

            if (panel != null)
            {
                panel.OnTooltipRequested -= TooltipRequestedHandler;
                panel.OnActionRequested  -= ActionRequestedHandler;
                panel.OnUpgradeRequested -= UpgradeRequestedHandler;
                panel.Content             = null;
            }
        }
コード例 #3
0
        // -------------------------------------------------------------------------------
        // Refresh
        // -------------------------------------------------------------------------------
        public void Refresh()
        {
            foreach (Transform t in content)
            {
                Destroy(t.gameObject);
            }

            if (loot != null)
            {
                foreach (InventorySlot instance in loot)
                {
                    GameObject newObj = (GameObject)Instantiate(slotPrefab, content);
                    PanelSlot  slot   = newObj.GetComponent <PanelSlot>();

                    if (slot != null)
                    {
                        if (instance is InstanceResource)
                        {
                            slot.txtName.text   = Finder.txt.getCurrencyName(((InstanceResource)instance).currencyType, false);
                            slot.imgIcon.sprite = Finder.txt.getCurrencyIcon(((InstanceResource)instance).currencyType);
                        }
                        else
                        {
                            slot.txtName.text   = instance.fullName;
                            slot.imgIcon.sprite = instance.icon;
                        }

                        if (instance.Quantity > 0)
                        {
                            slot.txtCost.text = "x" + instance.Quantity.ToString();
                        }
                        else
                        {
                            slot.txtCost.text = " ";
                        }

                        slot.imgCurrency.gameObject.SetActive(false);
                        slot.btnAction.gameObject.SetActive(false);
                        slot.btnUpgrade.gameObject.SetActive(false);
                        slot.btnTooltip.gameObject.SetActive(false);
                        slot.btnTrash.gameObject.SetActive(false);
                        slot.transform.SetParent(content, false);
                        slot.gameObject.SetActive(true);
                    }
                }
            }
        }
コード例 #4
0
 // -------------------------------------------------------------------------------
 //
 // -------------------------------------------------------------------------------
 protected void RemoveItem(T tmpl)
 {
     foreach (Transform child in panel.transform)
     {
         if (child != null)
         {
             PanelSlot panel = child.GetComponent <PanelSlot>();
             if (panel != null)
             {
                 if (panel.Content == tmpl)
                 {
                     GameObject.Destroy(child.gameObject);
                 }
             }
         }
     }
 }