Container.use C# (CSharp) Method

use() public method

public use ( ) : bool
return bool
    public override bool use()
    {
        GameObject ObjectInHand=GameWorldController.instance.playerUW.playerInventory.GetGameObjectInHand();
        //TODO:add object to container or open container.
        //Container cn = this.gameObject.GetComponent<Container>();
        if (ObjectInHand == null)
        {//Open the container
            OpenContainer();
            return true;
        }
        else
        {//Put the item in the container.
            bool Valid=true;
            if (ObjectInHand.GetComponent<Container>() != null)
            {
                if (this.gameObject.name == ObjectInHand.GetComponent<Container>().name)
                {
                    Valid=false;
                    Debug.Log ("Attempt to add a container to itself");
                }
            }
            //TODO:Do a test for Container capacity  here.
            //TODO:Do a test for item types accepted.
            if (Container.TestContainerRules(this,11)==false)
            {
                Valid=false;
                return true;
            }

            if (Valid)
            {
                if ((ObjectInHand.GetComponent<ObjectInteraction>().isQuant==false) || (ObjectInHand.GetComponent<ObjectInteraction>().isEnchanted))
                {
                    AddItemToContainer(GameWorldController.instance.playerUW.playerInventory.ObjectInHand);
                }
                else
                {
                    AddItemMergedItemToContainer(ObjectInHand.gameObject);
                }

                if (isOpenOnPanel == true)
                {//Container is open for display force a refresh.
                    OpenContainer();
                }
                GameWorldController.instance.playerUW.playerInventory.ObjectInHand= "";
                UWHUD.instance.CursorIcon= UWHUD.instance.CursorIconDefault;

                return true;
            }
            else
            {
                return false;
            }
        }
    }