<aside> <img src="/icons/reorder_gray.svg" alt="/icons/reorder_gray.svg" width="40px" />

Navigation

</aside>

🏠 Home Page

Getting Started

Architecture

Level System

Characters & Vehicles

Run Mechanics

World Objects

Boosters & Modifiers

Progression & Economy

UI

Save & Debugging

Modules

Publishing

Reference

💰 Monetization (Ads & IAP)

<aside> 💡 UISettings is a popup with the sound and haptic toggles and the link buttons. Each button is a small component derived from SettingsButtonBase.

</aside>

Subsystems

The prefab is UI Game Settings in Assets/Project Files/Game/Prefabs/UI/Canvas.

page-settings.png

UISettings

UISettings is a popup (IsPopup is true). It has a fade background and a scaled panel. A tap on the background or on the close button closes it. UISettings.Show() opens the page.

The page can be opened from the game page while the game is paused, so the animations run on unscaled time.

SettingsPanelButton

Add the component to any button that opens the settings. It calls UIController.ShowPage<UISettings>() and plays the button sound. The settings button of the start screen is handled by UIStartScreen, so use this component for buttons on other pages.

Buttons

Class Behavior
SettingsSoundToggleButton Toggles an audio type or all audio types. The Universal flag selects all types. Otherwise, set the Type (sound or music).
SettingsHapticToggleButton Toggles the haptic feedback through Haptic.IsActive.
SettingsLinkButton Opens the Url field in the browser.
SettingsPrivacyButton Opens the privacy link from Ads Settings. The button is hidden when the link is empty or when the Advertisement module is not installed.
SettingsTermsButton Opens the terms of use link from Ads Settings. The button is hidden when the link is empty.
SettingsRestoreButton Restores in-app purchases. The button is hidden when the Purchasing module is not initialized.

SettingsButtonBase

Derive from the class to add a button. It caches the Button in Start, adds the click listener and calls Init().

using UnityEngine;

namespace Watermelon
{
    public class SettingsRateButton : SettingsButtonBase
    {
        [SerializeField] string storeUrl;

        public override void Init()
        {
            // Hide the button when the url is empty
            gameObject.SetActive(!string.IsNullOrEmpty(storeUrl));
        }

        public override void OnClick()
        {
            Application.OpenURL(storeUrl);

            AudioController.PlaySound(AudioController.GetClip("button_sound"));
        }
    }
}

Select() and Deselect() are virtual and support gamepad or keyboard navigation.

How to add a button

  1. Create the script. Derive from SettingsButtonBase.
  2. Duplicate a button. Duplicate a button object in the UI Game Settings prefab and replace the component.
  3. Place it. Put the button inside a SettingsElementsGroup to hide the whole group when all of its buttons are inactive.