UWCharacter.PickupMode C# (CSharp) Method

PickupMode() public method

public PickupMode ( int ptrId ) : void
ptrId int
return void
    public override void PickupMode(int ptrId)
    {
        //Picks up the clicked object in the view.
        PlayerInventory pInv = this.GetComponent<PlayerInventory>();
        if (InvMarker==null)
        {
            InvMarker=GameWorldController.instance.InventoryMarker;//InvMarker=GameObject.Find ("InventoryMarker");
        }
        if (pInv.ObjectInHand=="")//Player is not holding anything.
        {//Find the object within the pickup range.
            Ray ray ;
            if (MouseLookEnabled==true)
            {
                ray =Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            }
            else
            {
                ray= Camera.main.ScreenPointToRay(Input.mousePosition);
            }
            RaycastHit hit = new RaycastHit();
            if (Physics.Raycast(ray,out hit,GetPickupRange()))
            {
                ObjectInteraction objPicked;
                objPicked=hit.transform.GetComponent<ObjectInteraction>();
                if (objPicked!=null)//Only objects with ObjectInteraction can be picked.
                {
                    if (objPicked.CanBePickedUp==true)
                    {
                        //check for weight
                        if (objPicked.GetWeight() > playerInventory.getEncumberance())
                        {//000~001~095~That is too heavy for you to pick up.
                            UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1,95));
                            return;
                        }
                        if (ptrId==-2)
                        {
                            //right click check for quant.
                            //Pickup if either not a quantity or is a quantity of one.
                            if ((objPicked.isQuant ==false) || ((objPicked.isQuant)&&(objPicked.Link==1)) || (objPicked.isEnchanted))
                            {
                                objPicked=Pickup(objPicked,pInv);
                            }
                            else
                            {
                                //Debug.Log("attempting to pick up a quantity");

                                UWHUD.instance.MessageScroll.Set ("Move how many?");
                                InputField inputctrl =UWHUD.instance.InputControl;//UWHUD.instance.MessageScroll.GetComponent<UIInput>();
                                inputctrl.gameObject.SetActive(true);
                                //inputctrl.GetComponent<GuiBase>().SetAnchorX(0.3f);
                                inputctrl.gameObject.GetComponent<InputHandler>().target=this.gameObject;
                                inputctrl.gameObject.GetComponent<InputHandler>().currentInputMode=InputHandler.InputCharacterQty;

                                //TODO: Fix me inputctrl.eventReceiver=this.gameObject;
                                                                //TODO: Fix me inputctrl.type=UIInput.KeyboardType.NumberPad;
                                inputctrl.text="1";
                                                                //TODO: Fix me inputctrl.label.text="1";
                                                                //TODO: Fix me inputctrl.selected=true;
                                inputctrl.Select();
                                QuantityObj=objPicked;
                                Time.timeScale=0.0f;
                                WindowDetect.WaitingForInput=true;
                            }
                        }
                        else
                        {//Left click. Pick them all up.
                            objPicked=Pickup(objPicked,pInv);
                        }
                    }
                    else
                    {//000~001~096~You cannot pick that up.
                        //Object cannot be picked up. Try and use it instead
                        if (objPicked.CanBeUsed)
                        {
                            UseMode();
                            UWHUD.instance.window.UWWindowWait (1.0f);
                        }
                        else
                        {
                            UWHUD.instance.MessageScroll.Add(StringController.instance.GetString(1,96));
                        }
                    }
                }
            }
        }
    }

Usage Example

    void ClickEvent()
    {
        if (playerUW.PlayerMagic.ReadiedSpell != "")
        {
            Debug.Log("player has a spell to cast");
            return;
        }

        switch (UWCharacter.InteractionMode)
        {
        case UWCharacter.InteractionModeOptions: //Options mode
            return;                              //do nothing

            break;

        case UWCharacter.InteractionModeTalk:        //Talk
            playerUW.TalkMode();
            break;

        case UWCharacter.InteractionModePickup:        //Pickup
            if (playerUW.gameObject.GetComponent <PlayerInventory>().ObjectInHand != "")
            {
                JustClicked = true;              //Prevent catching something I have just thrown.
                Invoke("ResetClick", 0.2f);
                ThrowObjectInHand();
            }
            else
            {
                playerUW.PickupMode();
            }

            break;

        case UWCharacter.InteractionModeLook: //look
            playerUW.LookMode();              //do nothing
            break;

        case UWCharacter.InteractionModeAttack:         //attack
            playerUW.PlayerCombat.AttackModeMelee();    //do nothing
            break;

        case UWCharacter.InteractionModeUse:        //Use
            if (playerUW.gameObject.GetComponent <PlayerInventory>().ObjectInHand != "")
            {
                //UseObjectInHand ();
                playerUW.UseMode();
            }
            else
            {
                playerUW.UseMode();
            }
            break;
        }
    }