示例#1
0
    void StopDrag()
    {
        if (DraggedLoot != this)
        {
            return;
        }

        //Debug.Log("StopDrag " + gameObject.name);
        DraggedLoot = null;

        SoundsManager.PlayRandomClip(DropSounds);


        //GetComponent<CanvasGroup>().interactable = true;
        //GetComponent<CanvasGroup>().blocksRaycasts = true;


        // Do a raycast to see what's under the mouse and find stuff that
        // implements OnDrop

        PointerEventData pointerData = new PointerEventData(EventSystem.current)
        {
            pointerId = -1,
        };

        pointerData.position = Input.mousePosition;

        List <RaycastResult> results = new List <RaycastResult>();

        EventSystem.current.RaycastAll(pointerData, results);

        foreach (RaycastResult rr in results)
        {
            BagSlot bs = rr.gameObject.GetComponent <BagSlot>();
            if (bs != null)
            {
                bs = bs.CanDropHere(this);

                // bs might be changed or could be null now

                if (bs != null)
                {
                    bs.DroppedLoot(this);
                }
                else
                {
                    ResetToLootArea();
                }

                return;
            }
        }



        // If we get here, we didn't hit a slot
        ResetToLootArea();
    }