コード例 #1
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the button this script is attached to is clicked on by a mouse.
    //  RMB - Deducts this object from the queue.
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerClick(PointerEventData eventData)
    {
        // Deduct item from queue if it exists
        if (eventData.button == PointerEventData.InputButton.Right && SelectionWheel != null)
        {
            // Check if the item exists in the building queue of the building
            // Deduct the last iterator of the abstraction type from the queue
            List <Abstraction> queue = SelectionWheel.GetBuildingSlotInstigator().GetBuildingOnSlot().GetBuildingQueue();
            for (int i = queue.Count - 1; i >= 0; i--)
            {
                // Matching type found
                if (queue[i].GetType() == _ObjectRefComponent.AbstractRef.GetType())
                {
                    // Add resources back to the player
                    Player player = GameManager.Instance.Players[0];
                    player.PopulationCount -= _ObjectRefComponent.AbstractRef.CostPopulation;
                    player.SuppliesCount   += _ObjectRefComponent.AbstractRef.CostSupplies;
                    player.PowerCount      += _ObjectRefComponent.AbstractRef.CostPower;

                    // Remove it
                    queue.RemoveAt(i);
                    break;
                }
            }
            SelectionWheel.UpdateButtonStates();
        }
    }
コード例 #2
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called each frame.
    /// </summary>
    void Update()
    {
        if (_Player != null)
        {
            if (_SupplyGenerators > 0)
            {
                // Keep generating supplies for the player
                if (_SupplyTimer < SupplyGenerator.GeneratorTickDelay / _SupplyGenerators)
                {
                    _SupplyTimer += Time.deltaTime;
                }
                else
                {
                    if ((_Player.SuppliesCount < _Player.MaxSupplyCount) && _SupplyGenerators >= 1)
                    {
                        _Player.SuppliesCount += 1;
                    }
                    // Reset timer
                    _SupplyTimer = 0f;
                }
            }

            if (_PowerGenerators > 0)
            {
                // Keep generating power for the player
                if (_PowerTimer < PowerStation.GeneratorTickDelay / _PowerGenerators)
                {
                    _PowerTimer += Time.deltaTime;
                }
                else
                {
                    if ((_Player.PowerCount < _Player.MaxSupplyCount) && _PowerGenerators >= 1)
                    {
                        _Player.PowerCount += 1;
                    }
                    // Reset timer
                    _PowerTimer = 0f;
                }
            }

            // Get selection wheel reference
            SelectionWheel selectionWheel = null;
            if (GameManager.Instance._IsRadialMenu)
            {
                selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>();
            }
            else
            {
                selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>();
            }
            selectionWheel.UpdateButtonStates();
        }
    }
コード例 #3
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called each frame.
    /// </summary>
    private void Update()
    {
        // Update slider progress value
        if (SliderBar != null)
        {
            SliderBar.value = _CurrentBuildProgress;
        }

        // Update queue counter text string
        if (_UnitCounter > 0 && QueueCounterTextComponent != null)
        {
            QueueCounterTextComponent.gameObject.SetActive(true);
            QueueCounterTextComponent.text = _UnitCounter.ToString();
        }
        else if (QueueCounterTextComponent != null)
        {
            QueueCounterTextComponent.gameObject.SetActive(false);
        }

        // PC hotkey visibility
        if (_Player == null)
        {
            _Player = GameManager.Instance.Players[0];
        }
        if (_Player != null && PCHotkeyObject != null)
        {
            // Set active based on whether the keyboard is the primary controller or not
            PCHotkeyObject.SetActive(_Player._KeyboardInputManager.IsPrimaryController);
        }

        // PC hotkey input for this button
        if (Input.GetKeyDown(PCShortcutKey))
        {
            // Check whether the button should be interactable or not
            Button button      = GetComponent <Button>();
            Player player      = GameManager.Instance.Players[0];
            bool   unlock      = player.Level >= AbstractRef.CostTechLevel;
            bool   purchasable = player.SuppliesCount >= AbstractRef.CostSupplies &&
                                 player.PowerCount >= AbstractRef.CostPower &&
                                 (player.MaxPopulation - player.PopulationCount) >= AbstractRef.CostPopulation;
            button.interactable = unlock && purchasable;

            // 'Buy' the item if the button is interactable
            if (button.IsInteractable())
            {
                button.onClick.Invoke();
            }

            // Get selection wheel reference
            SelectionWheel selectionWheel = null;
            if (GameManager.Instance._IsRadialMenu)
            {
                selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>();
            }
            else
            {
                selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>();
            }
            selectionWheel.UpdateButtonStates();
        }
    }