/// <summary>
 /// On start, we grab references and prepare our hotbar list
 /// </summary>
 protected virtual void Start()
 {
     _currentInventoryDisplay = TargetInventoryDisplay;
     InventoryOpen            = false;
     _targetInventoryHotbars  = new List <InventoryHotbar> ();
     _canvasGroup             = GetComponent <CanvasGroup> ();
     foreach (InventoryHotbar go in FindObjectsOfType(typeof(InventoryHotbar)) as InventoryHotbar[])
     {
         _targetInventoryHotbars.Add(go);
     }
     if (HideContainerOnStart)
     {
         if (TargetInventoryContainer != null)
         {
             TargetInventoryContainer.alpha = 0;
         }
         if (Overlay != null)
         {
             Overlay.alpha = 0;
         }
         EventSystem.current.sendNavigationEvents = false;
         if (_canvasGroup != null)
         {
             _canvasGroup.blocksRaycasts = false;
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// If possible, returns the focus to the current return inventory focus (after equipping an item, usually)
 /// </summary>
 public virtual void ReturnInventoryFocus()
 {
     if (ReturnInventory == null)
     {
         return;
     }
     else
     {
         ResetDisabledStates();
         ReturnInventory.Focus();
         ReturnInventory = null;
     }
 }
        /// <summary>
        /// Handles the inventory related inputs and acts on them.
        /// </summary>
        protected virtual void HandleInventoryInput()
        {
            // if we don't have a current inventory display, we do nothing and exit
            if (_currentInventoryDisplay == null)
            {
                return;
            }

            // if the user presses the 'toggle inventory' key
            if (Input.GetKeyDown(ToggleInvKey) || Input.GetKeyDown(ToggleInvAltKey))
            {
                // if the inventory is not open
                if (!InventoryOpen)
                {
                    OpenInventory();
                }
                // if it's open
                else
                {
                    CloseInventory();
                }
            }

            // if we've only authorized input when open, and if the inventory is currently closed, we do nothing and exit
            if (InputOnlyWhenOpen && !InventoryOpen)
            {
                return;
            }

            // previous inventory panel
            if (Input.GetKeyDown(PrevInvKey) || Input.GetKeyDown(PrevInvAltKey))
            {
                if (_currentInventoryDisplay.GoToInventory(-1) != null)
                {
                    _currentInventoryDisplay = _currentInventoryDisplay.GoToInventory(-1);
                }
            }

            // next inventory panel
            if (Input.GetKeyDown(NextInvKey) || Input.GetKeyDown(NextInvAltKey))
            {
                if (_currentInventoryDisplay.GoToInventory(1) != null)
                {
                    _currentInventoryDisplay = _currentInventoryDisplay.GoToInventory(1);
                }
            }

            // move
            if (Input.GetKeyDown(MoveKey) || Input.GetKeyDown(MoveAltKey))
            {
                if (CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Move();
                }
            }

            // equip or use
            if (Input.GetKeyDown(EquipOrUseKey) || Input.GetKeyDown(EquipOrUseAltKey))
            {
                EquipOrUse();
            }

            // equip
            if (Input.GetKeyDown(EquipKey) || Input.GetKeyDown(EquipAltKey))
            {
                if (CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Equip();
                }
            }

            // use
            if (Input.GetKeyDown(UseKey) || Input.GetKeyDown(UseAltKey))
            {
                if (CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Use();
                }
            }

            // drop
            if (Input.GetKeyDown(DropKey) || Input.GetKeyDown(DropAltKey))
            {
                if (CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Drop();
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets the return inventory display
 /// </summary>
 /// <param name="inventoryDisplay">Inventory display.</param>
 public virtual void SetReturnInventory(InventoryDisplay inventoryDisplay)
 {
     ReturnInventory = inventoryDisplay;
 }