コード例 #1
0
    /// <summary>
    /// Callback for "showUpgradeDialog" event. Generates content for the upgrade confirmation
    /// dialog and enables it.
    /// </summary>
    /// <param name="type"></param>
    public void ShowUpgradeDialog(ETowerType type)
    {
        currentType = type;
        DialogConfig config = new DialogConfig();

        int    cost = currentType.GetUpgradeCost();
        string messageString;

        if (cost > GameState.CurrentCash)
        {
            messageString = "You don't have enough cash. Required: " + cost + ". You have $" + GameState.CurrentCash;

            // As both buttons won't do anything special in this case, you could leave the callback
            config.OK = new DialogButton(
                interactable: false,
                text: "Upgrade"
                );
            config.Cancel = new DialogButton(
                text: "Cancel"
                );
        }
        else
        {
            messageString = "Upgrade to " + type.GetString() + " will cost $" + cost + ". You have $" + GameState.CurrentCash;
            config.OK     = new DialogButton(
                onClick: OnOKClickUpgrade,
                text: "Upgrade"
                );
            config.Cancel = new DialogButton(
                onClick: OnCancelClickUpgrade,
                text: "Cancel"
                );
        }

        config.Message = messageString;
        dialogSystem.Show(config);
    }
コード例 #2
0
 /// <summary>
 /// Passed as a callback for the OK button on the upgrade dialog.
 /// </summary>
 public void OnOKClickUpgrade()
 {
     GameState.CurrentCash -= currentType.GetUpgradeCost();
     createTower.Invoke(currentType);
 }