Example #1
0
    public void DroppedLoot(Loot l)
    {
        //Debug.Log("DroppedLoot: " + l.gameObject.name);

        if (Backpack != null)
        {
            Loot[] loots = Backpack.GetLootsInArea(PosX, PosY, l.GridWidth, l.GridHeight);
            if (loots.Length > 0)
            {
                if (loots.Length > 1)
                {
                    Debug.LogError("MORE THAN ONE LOOT?!?!?!?");
                    return;
                }

                loots[0].RemoveFromSlot();
                loots[0].StartDrag(true);
            }
        }
        else if (MyLoot != null)
        {
            Loot mine = MyLoot;
            mine.RemoveFromSlot();
            mine.StartDrag(true);
        }


        l.AddToSlot(this);

        Vector3 offset = Vector3.zero;

        if (Backpack != null)
        {
            offset = new Vector3(
                this.GetComponent <RectTransform>().sizeDelta.x / 2f,
                -this.GetComponent <RectTransform>().sizeDelta.y / 2f,
                0
                );
        }
        else
        {
            // Center in inventory slot (mostly for weapon)
            offset = new Vector3(
                -this.GetComponent <RectTransform>().sizeDelta.x / 2f + MyLoot.GetComponent <RectTransform>().sizeDelta.x / 2f,
                -this.GetComponent <RectTransform>().sizeDelta.y / 2f +
                MyLoot.GetComponent <RectTransform>().sizeDelta.y / 2f
                );
        }

        offset *= GetComponentInParent <Canvas>().scaleFactor;


        MyLoot.GetComponent <RectTransform>().position =
            this.GetComponent <RectTransform>().position
            - offset;
    }