/// <summary>
    /// 穿戴装备
    /// </summary>
    /// <param name="itemUI"></param>
    public void PutOn(ItemUI itemUI)
    {
        Item exitItem = null;

        foreach (Slot slot in Inventory.Instance.slotArr)
        {
            if (slot is EquipmentSlot)
            {
                EquipmentSlot equipmentSlot = (EquipmentSlot)slot;
                if (equipmentSlot.IsRightItem(itemUI.item))
                {
                    if (equipmentSlot.transform.childCount > 0)
                    {
                        exitItem = equipmentSlot.transform.GetChild(0).GetComponent <ItemUI>().item;
                    }
                    equipmentSlot.StoreItem(itemUI.item);
                    break;
                }
            }
        }
        if (exitItem != null)
        {
            Inventory.Instance.StoreItem(exitItem);
        }
    }
    /// <summary>
    /// 穿上装备
    /// </summary>
    /// <param name="item"></param>
    public void PutOn(Item item)
    {
        Item exitItem = null; // 如果槽里已有装备了,要卸下

        foreach (Slot slot in slotList)
        {
            EquipmentSlot equipmentSlot = (EquipmentSlot)slot;
            // 找到合适的槽
            if (equipmentSlot.IsRightItem(item))
            {
                // 槽里有装备了
                if (equipmentSlot.transform.childCount > 0)
                {
                    ItemUI currentItemUI = equipmentSlot.transform.GetChild(0).GetComponent <ItemUI>();
                    exitItem = currentItemUI.Item;  // 卸下的装备
                    currentItemUI.SetItem(item, 1); // 放入新装备
                }
                // 槽里没装备,直接穿上
                else
                {
                    equipmentSlot.StoreItem(item);
                }
                break;
            }
        }
        // 将卸下的装备放入背包中
        if (exitItem != null)
        {
            Knapsack.Instance.StoreItem(exitItem);
        }
        UpdatePropertyText();
    }
Example #3
0
    /// <summary>
    /// 穿上
    /// </summary>
    /// <param name="item"></param>
    public void PutOn(Item item)
    {
        Item exitItem = null;

        foreach (Slot slot in slots)
        {
            EquipmentSlot equipmentSlot = (EquipmentSlot)slot;
            if (equipmentSlot.IsRightItem(item))
            {
                if (equipmentSlot.transform.childCount > 0)
                {
                    ItemUI currentItemUI = equipmentSlot.transform.GetChild(0).GetComponent <ItemUI>();
                    exitItem = currentItemUI.Item;
                    currentItemUI.SetItem(item, 1);
                }
                else
                {
                    equipmentSlot.StoreItem(item);
                }
                break;
            }
        }
        if (exitItem != null)
        {
            Knapsack.Instance.StoreItem(exitItem);
        }

        UpdatePropertyText();
    }
Example #4
0
    //直接穿戴功能(不需拖拽)
    public void PutOn(Item item)
    {
        Item exitItem = null;            //临时保存需要交换的物品

        foreach (Slot slot in slotArray) //遍历角色面板中的物品槽,查找合适的的物品槽
        {
            EquipmentSlot equipmentSlot = (EquipmentSlot)slot;
            if (equipmentSlot.IsRightItem(item))            //判断物品是否合适放置在该物品槽里
            {
                if (equipmentSlot.transform.childCount > 0) //判断角色面板中的物品槽合适的位置是否已经有了装备
                {
                    ItemUI currentItemUI = equipmentSlot.transform.GetChild(0).GetComponent <ItemUI>();
                    exitItem = currentItemUI.Item;
                    currentItemUI.SetItem(item, 1);
                }
                else
                {
                    equipmentSlot.StoreItem(item);
                }
                break;
            }
        }
        if (exitItem != null)
        {
            Knapscak.Instance.StoreItem(exitItem); //把角色面板上是物品替换到背包里面
        }
        UpdatePropertyText();                      //更新显示角色属性值
    }
Example #5
0
 /**
  * 穿戴装备功能
  * */
 public void PutOn(ItemDetail item)
 {
     foreach (Slot slot in slotArray)
     {
         EquipmentSlot equipmentSlot = (EquipmentSlot)slot;
         if (equipmentSlot.IsRightItem(item))
         {
             if (equipmentSlot.transform.childCount > 0)
             {
                 ItemUI     currentItemUI = equipmentSlot.transform.GetChild(0).GetComponent <ItemUI>();
                 ItemDetail exitItem      = currentItemUI.ItemDetail;
                 Remove((Equipment)exitItem);
                 Equip((Equipment)item);
                 currentItemUI.SetItem(item, 1);
                 Knapscak.Instance.StoreItem(exitItem);
             }
             else
             {
                 equipmentSlot.StoreItem(item);
                 Equip((Equipment)item);
             }
             break;
         }
     }
     UpdatePropertyText();
 }
Example #6
0
    public void PutOn(Item item)
    {
        Item exitItem = null;

        foreach (Slot slot in slotList)
        {
            EquipmentSlot equipmentSlot = (EquipmentSlot)slot;
            if (equipmentSlot.IsRightItem(item))
            {
                if (equipmentSlot.transform.childCount > 0)
                {
                    ItemUI currentItemUI = equipmentSlot.transform.GetChild(0).GetComponent <ItemUI>();
                    exitItem = currentItemUI.Item;
                    currentItemUI.SetItem(item, 1);
                    inventoryMng.knapsackPanel.StoreItem(exitItem);
                }
                else
                {
                    equipmentSlot.StoreItem(item);
                }
                break;
            }
        }
        if (exitItem != null)
        {
            //view.knapsackPanel.StoreItem(exitItem); //TODO

            UpdatePropertyText();
        }
    }
Example #7
0
    public void PutOn(Item item)
    {
        Item exitItem = null;

        foreach (Slot slot in slotArray)
        {
            EquipmentSlot equipSlot = (EquipmentSlot)slot;
            if (equipSlot.IsRightItem(item))
            {
                if (equipSlot.transform.childCount > 0)
                {
                    exitItem = equipSlot.transform.GetChild(0).GetComponent <ItemUi>().ItemObject;
                    equipSlot.transform.GetChild(0).GetComponent <ItemUi>().SetItem(item);
                }
                else
                {
                    equipSlot.StoreItem(item);
                }
                break;
            }
        }
        if (exitItem != null)
        {
            Knapasck.Instance.StoreItem(exitItem);
        }
    }
 /// <summary>
 /// 将相同类型的装备/武器放入对应的装备/武器物品槽中
 /// </summary>
 /// <param name="item"></param>
 public void PutOn(ItemUI itemUI)
 {
     foreach (Slot slot in slots)
     {
         EquipmentSlot equipmentSlot = (EquipmentSlot)slot;
         if (equipmentSlot.IsRightItem(itemUI.item))
         {
             if (equipmentSlot.transform.childCount > 0)
             {
                 Item   tempItem;
                 ItemUI currentItem = equipmentSlot.transform.GetChild(0).GetComponent <ItemUI>();
                 tempItem = currentItem.item;
                 currentItem.SetItem(itemUI.item);
                 DestroyImmediate(itemUI.gameObject);
                 KnapsackPanel.Instance.StoreItem(tempItem);
             }
             else
             {
                 equipmentSlot.CreateItem(itemUI.item);
                 DestroyImmediate(itemUI.gameObject);
             }
             //break;
         }
     }
 }
Example #9
0
    public void Equip(Item item)
    {
        //从物品栏直接点击装备物品
        Item exitItem = null;

        foreach (Slot slot in SlotList)
        {
            EquipmentSlot equipmentSlot = (EquipmentSlot)slot;
            if (equipmentSlot.IsRightItem(item))
            {
                if (equipmentSlot.transform.childCount > 0)
                {
                    ItemUI currentItem = equipmentSlot.transform.GetChild(0).GetComponent <ItemUI>();
                    exitItem = currentItem.Item;
                    currentItem.SetItemUI(item, 1);
                }
                else
                {
                    equipmentSlot.SetItem(item);
                }
                EquipItem(item, true);
                equipmentSlot.CheckEquipSlot();
                break;
            }
        }
        if (exitItem != null)
        {
            BackPack.Instance.SetItem(exitItem);
        }
    }
    public void PutOn(Item item)
    {
        Item exitItem = null;

        foreach (Slot slot in slotList)
        {
            EquipmentSlot equipmentSlot = (EquipmentSlot)slot;
            if (equipmentSlot.IsRightItem(item))
            {
                if (equipmentSlot.transform.childCount > 0)
                {
                    ItemUI currentItemUI = equipmentSlot.transform.GetChild(0).GetComponent <ItemUI>();
                    exitItem = currentItemUI.Item;
                    currentItemUI.SetItem(item, 1);
                }
                else
                {
                    equipmentSlot.StoreItem(item);
                }
                break;
            }
        }
        if (exitItem != null)
        {
            Knapsack.Instance.StoreItem(exitItem);
        }
        AudioSvc.instance.PlayUIAudio(Constants.uiExtenBtn);
        UpdateSkinned();
    }
Example #11
0
 public void SetEquipment(Item item)
 {
     foreach (Slot slot in SlotList)
     {
         if (slot is EquipmentSlot)
         {
             EquipmentSlot equipmentSlot = (EquipmentSlot)slot;
             if (equipmentSlot.IsRightItem(item))
             {
                 if (equipmentSlot.transform.childCount > 0)
                 {
                     ItemUI currentItem = equipmentSlot.transform.GetChild(0).GetComponent <ItemUI>();
                     currentItem.SetItemUI(item, 1);
                 }
                 else
                 {
                     equipmentSlot.SetItem(item);
                 }
                 equipmentSlot.CheckEquipSlot();
                 break;
             }
         }
     }
 }
Example #12
0
    public override void OnUpdate()
    {
        //if (isPickedItem)
        //{
        //    //如果我们捡起了物品,我们就要让物品跟随鼠标
        //    Vector2 position;
        //    RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out position);
        //    pickedItem.SetLocalPosition(position);
        //}

#if UNITY_EDITOR
        if (true)
        {
            if (isPickedItem)
            {
                //如果我们捡起了物品,我们就要让物品跟随鼠标
                Vector2 position;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform,
                                                                        Input.mousePosition, null, out position);
                pickedItem.SetLocalPosition(position);
                if (Input.GetMouseButtonUp(0))
                {
#else
        if (Input.touchCount > 0)
        {
            Touch myTouch = Input.touches[0];
            if (isPickedItem)
            {
                //if (myTouch.phase != TouchPhase.Ended && myTouch.phase != TouchPhase.Canceled)
                //{
                //如果我们捡起了物品,我们就要让物品跟随鼠标
                Vector2 position;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform,
                                                                        Input.touches[0].position, null, out position);
                pickedItem.SetLocalPosition(position);
                if (myTouch.phase == TouchPhase.Ended)
                {
#endif
                    isPickedItem = false;
                    PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
                    pointerEventData.position = Input.mousePosition;
                    GraphicRaycaster     gr      = canvas.GetComponent <GraphicRaycaster>();
                    List <RaycastResult> results = new List <RaycastResult>();
                    gr.Raycast(pointerEventData, results);
                    if (results.Count <= 0)
                    {
                        isPickedItem = false;
                        PickedItem.Hide();
                        return;
                    }
                    GameObject go = results[0].gameObject;
                    if (go.tag == "Slot")
                    {
                        Slot slot = go.GetComponent <Slot>();
                        if (slot is EquipmentSlot)
                        {
                            EquipmentSlot equipmentSlot = slot as EquipmentSlot;
                            if (equipmentSlot.IsRightItem(pickedItem.Item))
                            {
                                if (slot.transform.childCount > 0)
                                {
                                    int  amount = slot.transform.GetChild(0).GetComponent <ItemUI>().Amount;
                                    Item item   = slot.transform.GetChild(0).GetComponent <ItemUI>().Item;
                                    for (int i = 0; i < pickedItem.Amount; i++)
                                    {
                                        GameObject.DestroyImmediate(slot.transform.GetChild(0).gameObject);
                                        slot.StoreItem(pickedItem.Item);
                                    }

                                    for (int i = 0; i < amount; i++)
                                    {
                                        knapsackPanel.StoreItem(item);
                                    }
                                }
                                else
                                {
                                    slot.StoreItem(pickedItem.Item);
                                }
                            }
                            else
                            {
                                knapsackPanel.StoreItem(pickedItem.Item);
                            }

                            isPickedItem = false;
                            PickedItem.Hide();
                        }
                        else if (slot is ShopSlot)
                        {
                            knapsackPanel.GetComponent <KnapsackPanel>().SellItem(pickedItem);
                            isPickedItem = false;
                            pickedItem.Hide();
                        }
                        else
                        {
                            if (slot.transform.childCount > 0)
                            {
                                int  amount = slot.transform.GetChild(0).GetComponent <ItemUI>().Amount;
                                Item item   = slot.transform.GetChild(0).GetComponent <ItemUI>().Item;
                                for (int i = 0; i < pickedItem.Amount; i++)
                                {
                                    GameObject.DestroyImmediate(slot.transform.GetChild(0).gameObject);
                                    slot.StoreItem(pickedItem.Item);
                                }

                                for (int i = 0; i < amount; i++)
                                {
                                    knapsackPanel.StoreItem(item);
                                }

                                isPickedItem = false;
                                PickedItem.Hide();
                            }
                            else
                            {
                                for (int i = 0; i < pickedItem.Amount; i++)
                                {
                                    slot.StoreItem(pickedItem.Item);
                                }

                                isPickedItem = false;
                                PickedItem.Hide();
                            }
                        }
                    }
                    else
                    {
                        if (go.tag == "ShopPanel")
                        {
                            knapsackPanel.SellItem(pickedItem);
                        }
                        else
                        {
                            for (int i = 0; i < pickedItem.Amount; i++)
                            {
                                knapsackPanel.StoreItem(pickedItem.Item);
                            }
                        }
                        isPickedItem = false;
                        PickedItem.Hide();
                    }
                }
            }
        }
    }