Ejemplo n.º 1
0
        /// <summary>
        /// 背包中单个物品按钮的初始化方法,序号-1代表添加到背包尾部
        /// </summary>
        /// <param name="item">Item.</param>
        /// <param name="btn">Button.</param>
        public void AddBagItem(Item item, int atIndex = -1, bool forceAdd = false)
        {
            // 如果当前背包已满
            if (bagItemsContainer.childCount == singleBagItemVolume && !forceAdd)
            {
                return;
            }

            if (player.allItemsInBag.Count <= minItemIndexOfCurrentBag)
            {
                tintHUD.SetUpTintHUD(string.Format("已自动加入背包{0}", currentBagIndex), null);
                return;
            }

            if (item is Equipment && (item as Equipment).equiped)
            {
                Debug.LogError("已装备的物品不应该出现在背包物品列表中" + item.itemName);
                return;
            }

            if (item is UnlockScroll && (item as UnlockScroll).unlocked)
            {
                Debug.LogError("已解锁的卷轴不应该出现在背包物品列表中" + item.itemName);
                return;
            }

            Transform bagItem = bagItemsPool.GetInstance <Transform> (bagItemModel.gameObject, bagItemsContainer);

            ItemInBagDragControl dragItemScript = bagItem.GetComponent <ItemInBagDragControl> ();

            dragItemScript.item = item;

            bagItem.GetComponent <ItemInBagCell> ().SetUpItemInBagCell(item);

            if (atIndex >= 0)
            {
                bagItem.SetSiblingIndex(atIndex - minItemIndexOfCurrentBag);
            }
        }
Ejemplo n.º 2
0
        //public void AddSequenceItemsIfBagNotFull(){


        //	if (minItemIndexOfCurrentBag + bagItemsContainer.childCount >= Player.mainPlayer.allItemsInBag.Count) {
        //		return;
        //	}

        //	for (int i = minItemIndexOfCurrentBag + bagItemsContainer.childCount; i <= maxItemIndexOfCurrentBag; i++) {

        //		if (i >= Player.mainPlayer.allItemsInBag.Count) {
        //			return;
        //		}

        //		AddBagItem (Player.mainPlayer.allItemsInBag [i]);

        //	}

        //}

        /// <summary>
        /// 背包中单个物品按钮的初始化方法,序号-1代表添加到背包尾部
        /// </summary>
        /// <param name="item">Item.</param>
        /// <param name="btn">Button.</param>
        public void AddBagItem(Item item, int atIndex = -1, bool forceAdd = false)
        {
            // 如果当前背包已满
            if (bagItemsContainer.childCount == CommonData.singleBagItemVolume && !forceAdd)
            {
                return;
            }


            Transform bagItem = bagItemsPool.GetInstance <Transform> (bagItemModel.gameObject, bagItemsContainer);

            ItemInBagDragControl dragItemScript = bagItem.GetComponent <ItemInBagDragControl> ();

            dragItemScript.InitItemDragControl(item, itemClickCallBack);


            bagItem.GetComponent <ItemInBagCell> ().SetUpItemInBagCell(item);


            if (atIndex >= 0)
            {
                bagItem.SetSiblingIndex(atIndex - minItemIndexOfCurrentBag);
            }
        }
Ejemplo n.º 3
0
        protected override void OnUserDrop(PointerEventData eventData)
        {
            GameObject draggedObject = GetDraggedObject(eventData);
            // 获取拖拽物体中的物品信息
            Item draggedItem = GetDraggedItem(eventData);

            // 如果拖拽游戏图中没有物品
            if (draggedItem == null)
            {
                SetDropResult(eventData, false);
                tintImage.enabled = false;
                return;
            }

            // 如果拖拽中的物品类型不对
            if (!CheckDraggedItemValid(draggedItem))
            {
                SetDropResult(eventData, false);
                tintImage.enabled = false;
                return;
            }

            //bagCanvas.GetComponent<BagViewController>().itemForSpecialOperation = draggedItem;

            // 装备面板内的装备
            if (draggedObject.GetComponent <EquipedItemDragControl> () != null)
            {
                EquipedItemDragControl dc = draggedObject.GetComponent <EquipedItemDragControl> ();

                soDragControl.itemImage.sprite  = dc.itemImage.sprite;
                soDragControl.itemImage.enabled = true;

                soDragControl.item = draggedItem;

                SetDropResult(eventData, true);
            }

            //从背包内拖拽出得物品
            else if (draggedObject.GetComponent <ItemInBagDragControl> () != null)
            {
                ItemInBagDragControl dc = draggedObject.GetComponent <ItemInBagDragControl> ();

                soDragControl.itemImage.sprite  = dc.itemImage.sprite;
                soDragControl.itemImage.enabled = true;

                if (draggedItem.itemType == ItemType.Equipment)
                {
                    soDragControl.item = draggedItem;
                }
                else
                {
                    soDragControl.item = Item.NewItemWith(draggedItem.itemId, 1);
                }

                SetDropResult(eventData, true);
            }



            if (dropSucceedCallBack != null)
            {
                dropSucceedCallBack(draggedItem);
            }

            tintImage.enabled = false;
        }