Esempio n. 1
0
 void Start()
 {
     _ImgHoverOverlay = transform.Find("Hover Overlay").GetComponent <Image>();
     _ImgIcon         = transform.Find("Icon").GetComponent <Image>();
     _Amount          = transform.Find("Amount").GetComponent <Text>();
     pickupItemSlot   = Ctrl_TootipManager.Instance.PickUp.GetComponent <Ctrl_PickUp>();
 }
    /// <summary>
    /// 只能拿取 不能拖放
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerDown(PointerEventData eventData)
    {
        //手上的物品
        Ctrl_PickUp pickUp = Ctrl_TootipManager.Instance.PickUpItem.GetComponent <Ctrl_PickUp>();

        if (eventData.button == PointerEventData.InputButton.Right)
        {
            //手上无物品
            if (pickUp.Item == null)
            {
                pickUp.Item = Item;
                Item        = null;
            }
        }
    }
Esempio n. 3
0
    /// <summary>
    /// 同背包物品交换 这里做了限制 只有食材才能替换或者添加
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerDown(PointerEventData eventData)
    {
        //手上的物品
        Ctrl_PickUp pickUp = Ctrl_TootipManager.Instance.PickUp.GetComponent <Ctrl_PickUp>();

        if (eventData.button == PointerEventData.InputButton.Left)
        {
            //如果手上有物品
            if (pickUp.Item != null)
            {
                //如果当前格子没有物品
                if (Item == null)
                {
                    //只有食材可以替换
                    if (pickUp.Item.materialType == "Ingredients")
                    {
                        //按住CTRL键,一下添加一个
                        if (Input.GetKey(KeyCode.LeftControl))
                        {
                            Item = Ctrl_InventoryManager.Instance.NewItem(pickUp.Item.id);

                            /* Item = new Model_Item
                             * {
                             *   id = pickUp.Item.id,
                             *   itemName = pickUp.Item.itemName,
                             *   itemType = pickUp.Item.itemType,
                             *   materialType = pickUp.Item.materialType,
                             *   equipmentType = pickUp.Item.equipmentType,
                             *   maxStack = pickUp.Item.maxStack,
                             *   currentNumber = 1,
                             *   buyPriceByGold = pickUp.Item.buyPriceByGold,
                             *   buyPriceByDiamond = pickUp.Item.buyPriceByDiamond,
                             *   sellPriceByGold = pickUp.Item.sellPriceByGold,
                             *   sellPriceByDiamond = pickUp.Item.sellPriceByDiamond,
                             *   minLevel = pickUp.Item.minLevel,
                             *   sellable = pickUp.Item.sellable,
                             *   tradable = pickUp.Item.tradable,
                             *   destroyable = pickUp.Item.destroyable,
                             *   description = pickUp.Item.description,
                             *   sprite = pickUp.Item.sprite,
                             *   useDestroy = pickUp.Item.useDestroy,
                             *   useHealth = pickUp.Item.useHealth,
                             *   useMagic = pickUp.Item.useMagic,
                             *   useExperience = pickUp.Item.useExperience,
                             *   equipHealthBonus = pickUp.Item.equipHealthBonus,
                             *   equipManaBonus = pickUp.Item.equipManaBonus,
                             *   equipDamageBonus = pickUp.Item.equipDamageBonus,
                             *   equipDefenseBonus = pickUp.Item.equipDefenseBonus,
                             *   equipSpeedcBonus = pickUp.Item.equipSpeedcBonus,
                             *   modelPrefab = pickUp.Item.modelPrefab
                             * };*/
                            //如果手上的物品数量只剩一个
                            if (pickUp.Item.currentNumber - 1 == 0)
                            {
                                pickUp.Item = null;
                            }
                            else
                            {
                                pickUp.Item.currentNumber -= 1;
                                pickUp.UpdateAmount();
                            }

                            return;
                        }

                        Item        = pickUp.Item;
                        pickUp.Item = null;
                    }
                }
                else
                {
                    //如果手上的物品跟燃烧的物品一样
                    if (pickUp.Item.id == Item.id)
                    {
                        //按住CTRL键,一下添加一个
                        if (Input.GetKey(KeyCode.LeftControl))
                        {
                            //当前燃料格子未满
                            if (Item.currentNumber < Item.maxStack)
                            {
                                item.currentNumber++;
                                UpdateAmount(); //更新个数UI显示
                                //如果手上的物品数量只剩一个
                                if (pickUp.Item.currentNumber - 1 == 0)
                                {
                                    pickUp.Item = null;
                                }
                                else
                                {
                                    pickUp.Item.currentNumber -= 1;
                                    pickUp.UpdateAmount();
                                }
                            }

                            return;
                        }

                        //如果燃烧的材料达到上限的个数大于手上物品的个数
                        if (Item.maxStack - Item.currentNumber > pickUp.Item.currentNumber)
                        {
                            Item.currentNumber += pickUp.Item.currentNumber;
                            UpdateAmount(); //更新个数UI显示
                            pickUp.Item = null;
                        }
                        else
                        {
                            pickUp.Item.currentNumber -= (Item.maxStack - Item.currentNumber);
                            Item.currentNumber         = Item.maxStack;
                            UpdateAmount();        //更新个数UI显示
                            pickUp.UpdateAmount(); //更新UI显示
                        }
                    }
                    else
                    {
                        //如果都有物品,交换
                        Model_Item tempItem;
                        tempItem    = Item;
                        Item        = pickUp.Item;
                        pickUp.Item = tempItem;
                    }
                }
            }
        }

        if (eventData.button == PointerEventData.InputButton.Right)
        {
            //手上无物品
            if (pickUp.Item == null)
            {
                pickUp.Item = Item;
                Item        = null;
            }
        }
    }