Example #1
0
        void Update()
        {
            // also quite suspicios around here.....
            if (timer + 1 < Time.time)
            {
                someHugeDataPackage = new System.Object[1000000];
                timer = Time.time;
            }

            if (Input.GetKeyDown(KeyCode.Escape) && !_inventoryUI.IsActive())
            {
                ShowPauseMenu();
            }

            if ((Input.GetKeyDown(KeyCode.I) || Input.GetKeyDown(KeyCode.Tab)) && !_showingMenu)
            {
                _inventoryUI.Toogle();
            }

            if (_showingMenu || _inventoryUI.IsActive())
            {
                return;
            }

            //Enter the Crafting Mode
            if (Input.GetKeyDown(KeyCode.B))
            {
                _craftingMode = !_craftingMode;
                if (_itemObj == null)
                {
                    _itemObj = Manager.GetCraftableItem(_craftTypeIdx, _itemIdx);
                }
                if (_itemObj != null)
                {
                    _itemObj.SetActive(_craftingMode);
                    _actionText.Text = "";
                    _craftCostUI.gameObject.SetActive(_craftingMode);
                    _currCraftItem = _itemObj.GetComponent <CraftableItem> ();
                    _craftCostUI.DrawCostView(_currCraftItem, _inventory);
                    _craftCostUI.setTypeText(_craftTypeIdx);
                }
            }

            if (Input.GetKeyDown(KeyCode.G))
            {
                if (_toolHandler.CurrentTool != null)
                {
                    _currItem = _toolHandler.CurrentTool.ItemName;
                    Drop();
                    _currItem = "";
                }
            }

            if (_craftingMode)
            {
                OnCraftingMode();
            }
            else
            {
                if (Input.GetMouseButtonDown(0) && _toolHandler.CurrentTool != null)
                {
                    _toolHandler.Attack();
                }

                //Perform some action when E is pressed
                if (Input.GetKeyDown(KeyCode.E) && _interactionObj != null)
                {
                    if (_interaction == Interaction.GrabTool)
                    {
                        Tool tool = _interactionObj.GetComponent <Tool> ();
                        _inventory.Add(tool.ItemName, tool.Amount, this);
                        if (_toolHandler.CurrentTool == null)
                        {
                            _toolHandler.ChangeTool(_interactionObj);
                        }
                        else
                        {
                            Destroy(_interactionObj);
                        }
                        _interactionObj = null;
                    }
                    else if (_interaction == Interaction.GrabItem)
                    {
                        Item  item        = _interactionObj.GetComponent <Item> ();
                        float amountTaken = _inventory.Add(item.ItemName, item.Amount, this);

                        if (amountTaken == item.Amount)
                        {
                            Destroy(_interactionObj);
                        }
                        else
                        {
                            item.Amount -= amountTaken;
                        }
                    }
                    else if (_interaction == Interaction.OpenContainer)
                    {
                        //get the container inventory
                        Inventory inventory = _interactionObj.GetComponent <Inventory> ();
                        //draw the player's inventory
                        _inventoryUI.Draw(_inventory);
                        //draw the container inventory
                        _inventoryUI.Draw(inventory);
                    }
                }

                CheckPlayerFocus();
            }
        }
Example #2
0
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Escape) && !_inventoryUI.IsActive())
            {
                ShowPauseMenu();
            }

            if ((Input.GetKeyDown(KeyCode.I) || Input.GetKeyDown(KeyCode.Tab)) && !_showingMenu)
            {
                _inventoryUI.Toogle();
                _trading = false;
            }

            if (_showingMenu || _inventoryUI.IsActive())
            {
                return;
            }

            //Enter/Exit the Crafting Mode
            if (Input.GetKeyDown(KeyCode.B) || Input.GetKeyDown(KeyCode.C))
            {
                _craftingMode = !_craftingMode;
                if (_itemObj == null)
                {
                    _itemObj = Manager.GetCraftableItemObj(_craftTypeIdx, _itemIdx);
                }
                if (_itemObj != null)
                {
                    _itemObj.SetActive(_craftingMode);
                    _actionText.Text = "";
                    _craftCostUI.gameObject.SetActive(_craftingMode);
                    _currCraftItem = Manager.GetCraftableItem(_craftTypeIdx, _itemIdx);
                    _craftCostUI.DrawCostView(_currCraftItem, _inventory);
                    _craftCostUI.setTypeText(_craftTypeIdx);
                }
            }

            if (Input.GetKeyDown(KeyCode.G))
            {
                if (_toolHandler.CurrentTool != null)
                {
                    _currItem = _toolHandler.CurrentTool;
                    Drop();
                    _currItem = null;
                }
            }

            if (_craftingMode)
            {
                OnCraftingMode();
            }
            else
            {
                if (Input.GetButtonDown("Fire1") && _toolHandler.CurrentTool != null)
                {
                    _toolHandler.Attack();
                }

                //Perform some action when E is pressed
                if ((Input.GetKeyDown(KeyCode.E) || Input.GetButton("Fire2")) && _interactionObj != null)
                {
                    if (_interaction == Interaction.GrabTool)
                    {
                        ItemReference tool = _interactionObj.GetComponent <ItemReference> () as ItemReference;
                        Tool          item = _interactionObj.GetComponent <ItemReference>().Data as Tool;
                        _inventory.Add(item, tool.Amount, this);
                        if (_toolHandler.CurrentTool == null)
                        {
                            _toolHandler.ChangeTool(item);
                            Destroy(_interactionObj);
                        }
                        else
                        {
                            Destroy(_interactionObj);
                        }
                        _interactionObj = null;
                    }
                    else if (_interaction == Interaction.GrabItem)
                    {
                        ItemReference item        = _interactionObj.GetComponent <ItemReference> ();
                        float         amountTaken = _inventory.Add(item.Data, item.Amount, this);

                        if (amountTaken == item.Amount)
                        {
                            Destroy(_interactionObj);
                        }
                        else
                        {
                            item.Amount -= amountTaken;
                        }
                    }
                    else if (_interaction == Interaction.OpenContainer)
                    {
                        //get the container inventory
                        Inventory inventory = _interactionObj.GetComponent <Inventory> ();
                        //draw the player's inventory
                        _inventoryUI.Draw(_inventory);

                        _trading = (inventory.InvType == Inventory.Type.Store);

                        //draw the container inventory
                        _inventoryUI.Draw(inventory);
                    }
                }
                CheckPlayerFocus();
            }
        }