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");

        //如果物品槽为空,而且可以吃,则吃掉
        if (!itemObj & DragHandler.GetItemBeingDragged().isEatable)
        {
            itemObj = DragHandler.objBeingDragged;
            Debug.Log(itemObj.GetComponent <ItemDisplay>().Amount);
            //如果食品不止一个,则直接减少一个
            if (itemObj.GetComponent <ItemDisplay>().Amount > 1)
            {
                Eat(DragHandler.GetFoodBeingDraged());
                itemObj.GetComponent <ItemDisplay>().Amount -= 1;
                itemObj = null;
            }
            else
            {
                itemObj.transform.SetParent(transform);
                itemObj.transform.position = transform.position;

                Eat(DragHandler.GetFoodBeingDraged());
                Destroy(itemObj);
            }
        }
    }