Esempio n. 1
0
    private void RemoveAssociatedItemFromHand(GameObject hand)
    {
        InventoryButtonScript script = hand.GetComponent <InventoryButtonScript>();

        script.SetAssociatedItem(null);
        hand.GetComponentInChildren <Text>().text = "hand";
    }
Esempio n. 2
0
    public void AssociateItemToHand(AbsItem item, string hand)
    {
        InventoryButtonScript leftHandScript  = leftHand.GetComponent <InventoryButtonScript> ();
        InventoryButtonScript rightHandScript = rightHand.GetComponent <InventoryButtonScript> ();

        switch (hand)
        {
        case LEFT:
            if (leftHandScript.GetAssociatedItem() == item)
            {
                RemoveAssociatedItemFromHand(leftHand);
                item.OnBeingRemovedFromHand();
            }
            else
            {
                if (rightHandScript.GetAssociatedItem() == item)
                {
                    RemoveAssociatedItemFromHand(rightHand);
                }
                if (leftHandScript.GetAssociatedItem() != null)
                {
                    leftHandScript.GetAssociatedItem().OnBeingRemovedFromHand();
                    if (leftHandScript.GetAssociatedItem().IsDoubleHanded())
                    {
                        RemoveAssociatedItemFromHand(rightHand);
                    }
                    RemoveAssociatedItemFromHand(leftHand);
                }
                item.OnBeingAssociatedToHand(LEFT);
                leftHandScript.SetAssociatedItem(item);
            }
            break;

        case RIGHT:
            if (rightHandScript.GetAssociatedItem() == item)
            {
                RemoveAssociatedItemFromHand(rightHand);
                item.OnBeingRemovedFromHand();
            }
            else
            {
                if (leftHandScript.GetAssociatedItem() == item)
                {
                    RemoveAssociatedItemFromHand(leftHand);
                }
                if (rightHandScript.GetAssociatedItem() != null)
                {
                    rightHandScript.GetAssociatedItem().OnBeingRemovedFromHand();
                    if (rightHandScript.GetAssociatedItem().IsDoubleHanded())
                    {
                        RemoveAssociatedItemFromHand(leftHand);
                    }
                    RemoveAssociatedItemFromHand(rightHand);
                }
                item.OnBeingAssociatedToHand(RIGHT);
                rightHandScript.SetAssociatedItem(item);
            }
            break;

        case BOTH:
            if (leftHandScript.GetAssociatedItem() == item || rightHandScript.GetAssociatedItem() == item)
            {
                RemoveAssociatedItemFromHand(leftHand);
                RemoveAssociatedItemFromHand(rightHand);
            }
            else
            {
                if (leftHandScript.GetAssociatedItem() != null)
                {
                    leftHandScript.GetAssociatedItem().OnBeingRemovedFromHand();
                    RemoveAssociatedItemFromHand(leftHand);
                }
                if (rightHandScript.GetAssociatedItem() != null)
                {
                    rightHandScript.GetAssociatedItem().OnBeingRemovedFromHand();
                    RemoveAssociatedItemFromHand(rightHand);
                }
                item.OnBeingAssociatedToHand(BOTH);
                leftHandScript.SetAssociatedItem(item);
                rightHandScript.SetAssociatedItem(item);
            }
            break;
        }
    }