Exemple #1
0
        private void Update()
        {
            for (int i = 0; i < Keys.Length; i++)
            {
                if (Input.GetKeyDown(Keys[i]))
                {
                    // Try to equip the i'th item.
                    int found = 0;
                    for (int j = 0; j < equippedItems.Length; j++)
                    {
                        if (equippedItems[j] == null)
                        {
                            continue;
                        }

                        if (found == i && found != currentIndex)
                        {
                            SetActiveItem(j);
                        }
                        found++;
                    }
                    break;
                }
            }

            if (hotbar == null)
            {
                hotbar = GlobalUIElement.Get <UI_Hotbar>();
            }

            if (hotbar != null)
            {
                hotbar.UpdateIcons(this);
            }
        }
Exemple #2
0
        private void UpdateUI()
        {
            var block = GlobalUIElement.Get <UI_BlockIndicator>();

            if (block == null)
            {
                return;
            }

            block.Active         = Block;
            block.BlockDirection = BlockDirection;
        }
Exemple #3
0
        /*
         * Items can be in 3 states:
         * 1. Dropped. Dropped items have physics, they are always in the 'Dropped' animation state.
         * 2. Equipped. Equipped items are parented to the holding transform, but are not visible or animated.
         * 3. Active. Active items are equipped and also held in the hands, visible and animated.
         */

        private void Awake()
        {
            // Make sure equipped items have correct initial state.
            for (int i = 0; i < MaxEquippedItems; i++)
            {
                var item = equippedItems[i];
                if (item != null)
                {
                    item.gameObject.SetActive(true);
                    item.Animation.gameObject.SetActive(false);
                    //StartCoroutine(Disable(item));
                    item.Manager = this;
                    item.UponEquip();
                }
            }

            // Setup input.
            Player.Player.Input.actions["Drop"].performed += ctx =>
            {
                Dequip(currentIndex);
            };
            Player.Player.Input.actions["Next Item"].performed += ctx =>
            {
                bool found    = false;
                int  newIndex = currentIndex + 1;
                for (int i = 0; i < MaxEquippedItems; i++)
                {
                    if (newIndex >= MaxEquippedItems)
                    {
                        newIndex = 0;
                    }
                    if (newIndex < 0)
                    {
                        newIndex = 0;
                    }

                    if (equippedItems[newIndex] != null)
                    {
                        found = true;
                        break;
                    }
                    else
                    {
                        newIndex++;
                    }
                }
                if (found)
                {
                    SetActiveItem(newIndex);
                }
            };
            Player.Player.Input.actions["Previous Item"].performed += ctx =>
            {
                bool found    = false;
                int  newIndex = currentIndex - 1;
                for (int i = 0; i < MaxEquippedItems; i++)
                {
                    if (newIndex >= MaxEquippedItems)
                    {
                        newIndex = 0;
                    }
                    if (newIndex < 0)
                    {
                        newIndex = MaxEquippedItems - 1;
                    }

                    if (equippedItems[newIndex] != null)
                    {
                        found = true;
                        break;
                    }
                    else
                    {
                        newIndex--;
                    }
                }
                if (found)
                {
                    SetActiveItem(newIndex);
                }
            };
            Player.Player.Input.actions["Empty Hands"].performed += ctx =>
            {
                SetActiveItem(-1);
            };
            Player.Player.Input.actions["Interact"].performed += ctx =>
            {
                if (pickup == null)
                {
                    pickup = GlobalUIElement.Get <UI_PickupInfo>();
                }

                if (pickup.CurrentlyHighlightedItem != null)
                {
                    int index = Equip(pickup.CurrentlyHighlightedItem);
                    if (index != -1)
                    {
                        SetActiveItem(index);
                    }
                }
            };
        }
Exemple #4
0
        private void UIBlockHit()
        {
            var block = GlobalUIElement.Get <UI_BlockIndicator>();

            block.BlockHit();
        }