コード例 #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);
            }
        }
    }
コード例 #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);
            }
        }
    }
コード例 #3
0
    public void OnDrop(PointerEventData eventData)
    {
        Debug.Log("OnDrop");

        if (!itemObj)
        {
            itemObj = DragHandler.objBeingDragged;
            itemObj.transform.SetParent(transform);
            itemObj.transform.position = transform.position;

            Crafter.instance.AddItem(DragHandler.GetItemBeingDragged(), slot);
        }
    }
コード例 #4
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;
            }
        }
    }
コード例 #5
0
    public void OnDrop(PointerEventData eventData)
    {
        if (DragHandler.objBeingDragged == null)
        {
            return;
        }

        DragHandler.objBeingDragged.transform.SetParent(transform);

        Item item = DragHandler.GetItemBeingDragged();

        if (!Inventory.instance.HasItem(item))
        {
            Inventory.instance.AssignItem(item);
        }
    }
コード例 #6
0
    public void OnDrop(PointerEventData eventData)
    {
        Debug.Log("OnDrop");

        if (itemObj != null)
        {
            Inventory.instance.ReturnItem(itemObj);
            Crafter.instance.RemoveItem(slot);
            itemObj = null;
        }

        itemObj = DragHandler.objBeingDragged;
        itemObj.transform.SetParent(transform);
        itemObj.transform.position = transform.position;

        Crafter.instance.AddItem(DragHandler.GetItemBeingDragged(), slot);
    }