Exemplo n.º 1
0
    public void OnDrop(PointerEventData eventData)
    {
        Debug.Log("OnDrop");

        //如果物品槽为空,而且物品是可放进锅里的,则放进锅里
        if (!itemObj & DragHandler.GetItemBeingDragged().isCookable)
        {
            itemObj = DragHandler.objBeingDragged;
            //如果拖拽的物品不止一个,则保留itembeingdragged,并将其数量减1,并产生一个新的prefab在那里(更新数量及腐烂程度);
            if (itemObj.GetComponent <ItemDisplay>().Amount > 1)
            {
                itemObj.GetComponent <FoodDisplay>().Amount -= 1;
                InstantiateFoodDisplay(DragHandler.GetItemBeingDragged());
                itemObj.GetComponent <ItemDisplay>().Amount     = 1;
                itemObj.GetComponent <FoodDisplay>().freshStart = false;
                itemObj.GetComponent <FoodDisplay>().perishTime = DragHandler.GetFoodDisplay().perishTime;
                ResetTransform();
                FoodCrafter.instance.AddItem(DragHandler.GetFoodBeingDraged(), slot);
            }
            else
            {
                itemObj.transform.SetParent(transform);
                itemObj.transform.position = transform.position;
                ResetTransform();
                FoodCrafter.instance.AddItem(DragHandler.GetFoodBeingDraged(), slot);
            }
        }
    }
Exemplo n.º 2
0
    public void OnDrop(PointerEventData eventData)
    {
        Debug.Log("OnDrop");
        bool stackable        = false;
        Item itemBeingDragged = DragHandler.GetItemBeingDragged();
        Item itemBeingDropped = ScriptableObject.CreateInstance <Item>();

        if (itemObj)
        {
            stackable        = itemObj.GetComponent <ItemDisplay>().item.isStackable;
            itemBeingDropped = itemObj.GetComponent <ItemDisplay>().item;
        }
        if (itemObj == null || (itemObj != null & stackable == true & itemBeingDragged.name == itemBeingDropped.name))
        {
            //假如物品是食物,则将其重置其腐烂程度
            if (itemObj)
            {
                if (itemObj.GetComponent <FoodDisplay>())
                {
                    itemObj.GetComponent <FoodDisplay>().AveragePerish(DragHandler.GetFoodDisplay());
                }


                //假如物品可堆叠,则将数量进行堆叠
                if (itemObj.GetComponent <ItemDisplay>().item.isStackable)
                {
                    itemObj.GetComponent <ItemDisplay>().Stack(DragHandler.GetItemDisplay().Amount);
                }
            }

            itemObj = DragHandler.objBeingDragged;
            itemObj.transform.SetParent(transform);
            itemObj.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
            itemObj.transform.position = transform.position;
            if (itemObj)
            {
                itemObj.GetComponent <FoodDisplay>().EnableBackFrame();
            }
            Inventory.instance.AddItem(DragHandler.GetItemBeingDragged(), slot);

            //假如有两个child在transform里
            if (transform.childCount > 1)
            {
                Destroy(itemObj);
                itemObj = transform.GetChild(0).gameObject;
            }
        }
    }