예제 #1
0
    public override void Revert()
    {
        //Get whether the item is currently in the player's inventory
        bool curItemState = myData.curItemState;

        if (inInventory == false && curItemState == false)
        {
            //If item was picked up and thrown somewhere else, place it back (or recreate it if it was destroyed)
            base.Revert();
        }
        else if (inInventory == false && curItemState == true)
        {
            //Get item out of inventory and create at position/in hand of pickedUp
            Instantiate(Inventory.instance.GetItem(myData.inventoryIndex).concreteObject, position, Quaternion.identity).GetComponent <Material>().PickedUp(parent.gameObject);
            Inventory.instance.Remove(myData.inventoryIndex);
        }
        else if (inInventory == true && curItemState == false)
        {
            //Destroy memento and place back in inventory
            ConcreteItem itemParent = parent as ConcreteItem;
            if (itemParent)
            {
                itemParent.EmptyMemento();
            }
            Inventory.instance.TransferIn(myData.inventoryIndex, parent);
        }
    }
예제 #2
0
    //Takes the object and places it in the inventory, destroying the concrete object
    //@error: Method raises an error if the concreteObject parameter is not compatible with the inventory
    public void TransferIn(int index, Material concreteObject)
    {
        Debug.Log("Transferring object back in!");
        ConcreteItem itemToRevert = concreteObject as ConcreteItem;

        if (itemToRevert)
        {
            itemToRevert.EmptyMemento();
            AddAt(index, itemToRevert);
            //Destroy the concreteObject version
            concreteObject.Destroy();
            //Update UI
            UpdateUI();
        }
        else
        {
            Debug.LogException(new Exception("Inventory Revert method expected a ConcreteItem object"), this);
        }
    }