Extending and API

Everything is in the RareGeometry.Shipready.Settings namespaces. Shipready's public API won't break in 1.x updates (an automated test checks every public type, member, serialized field, script GUID, menu item and setting id against the released version).

Read a setting #

using RareGeometry.Shipready.Settings;

var settings = SettingsRuntime.Current;              // created by the front end or a Settings Bootstrap
float shake = settings.GetFloat("gameplay.camera-shake", 1f);
bool hints = settings.GetBool("gameplay.hints");
string difficulty = settings.GetValue("gameplay.difficulty");

Ids are listed in the Settings reference.

React when settings change #

// Connect tier: called now and after every Apply that changes it.
SettingsRuntime.Current.Connect("gameplay.field-of-view", v => cam.fieldOfView = float.Parse(v, System.Globalization.CultureInfo.InvariantCulture));

// Any tier: an event per applied setting.
SettingsRuntime.Current.ValueApplied += d => Debug.Log($"{d.Id} is now {SettingsRuntime.Current.GetValue(d.Id)}");

No code: add a Setting Event Binder component (UnityEvents for float, int, bool and string values).

A connector component #

public sealed class LightIntensityTarget : SettingConnector
{
    [SerializeField] Light target;
    protected override void OnValue(string value) =>
        target.intensity = float.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
}

Your own Auto setting #

Derive a definition (for example from FloatSettingDefinition) and an applier, and register the applier once:

public sealed class GammaApplier : SettingApplier
{
    public override bool Handles(SettingDefinition d) => d is GammaSettingDefinition;
    public override void Apply(SettingsController c, IReadOnlyList<SettingDefinition> changed)
    {
        foreach (var d in changed) MyPostStack.SetGamma(c.GetFloat(d.Id, 1f));
    }
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
static void Register() => SettingsAppliers.Register(() => new GammaApplier());

Change settings from code #

var c = SettingsRuntime.Current;
c.SetPendingFloat("audio.music-volume", 0.5f);
c.Apply();                 // or c.Cancel()

Where settings are saved #

Implement ISettingsStorage (Load, Save, Delete) to keep settings in a cloud save, a console save system or your own save file. Use it before the menu starts:

public sealed class CloudSettingsStorage : ISettingsStorage
{
    public SettingsLoadResult Load()
    {
        var json = MyCloud.Read("settings");
        return json != null && SettingsStore.TryFromJson(json, out var data, out _)
            ? new SettingsLoadResult(SettingsLoadStatus.Loaded, data, false, "")
            : new SettingsLoadResult(SettingsLoadStatus.NotFound, new SettingsData(), false, "");
    }
    public bool Save(SettingsData data) => MyCloud.Write("settings", SettingsStore.ToJson(data));
    public void Delete() => MyCloud.Delete("settings");
}

// In a bootstrap that runs before the front end (or turn off Menu Root > Initialize Settings On Awake):
SettingsRuntime.Initialize(profile, new SettingsRuntimeOptions { Storage = new CloudSettingsStorage() });

PlayerPrefsSettingsStorage and the default file (SettingsStore) are ready-made storages.

Export, import, presets, reset one #

var c = SettingsRuntime.Current;
string json = c.ExportJson();                      // the applied values (settings file format)
int count = c.ImportJson(json, out var error);     // pending values; -1 when the text isn't settings JSON
c.ApplyPreset(myPreset);                           // a SettingsPreset asset
c.ResetToDefault("audio.music-volume");            // one setting back to its default
c.Apply();
c.RestartRequired += changed => MenuRoot.Instance.ShowToast("Restart to finish");

Settings from your code ([GameSetting]) #

public static class MyGameSettings
{
    [GameSetting("gameplay.hints", "Tutorial Hints", Help = "Shows tips about the controls.")]
    public static bool Hints = true;

    [GameSetting("gameplay.hud-scale", "HUD Size", Min = 0.5f, Max = 2f)]
    public static float HudScale = 1f;

    [GameSetting("gameplay.crosshair", Category = "gameplay")]
    public static CrosshairStyle Crosshair = CrosshairStyle.Dot;   // an enum becomes a choice
}

Kit window > Settings > Custom setting > Create settings from [GameSetting] fields creates a setting for each one (bool: toggle, float: slider, int: whole number, enum: choice). While the game runs, the fields always hold the applied values: read MyGameSettings.Hints anywhere.

Visual Scripting #

With Unity's Visual Scripting package installed, the node library gets Get Setting, Set Setting (optionally applying) and the event On Setting Applied (category Rare Geometry). Regenerate the nodes once (Project Settings > Visual Scripting > Regenerate Nodes) after importing Shipready.

Your save system #

public sealed class MySaves : ISaveGameBridge
{
    public bool HasSave() => MySaveSystem.Any();
    public void Continue() { MySaveSystem.LoadNewest(); MenuRoot.Instance.EnterGameplay(); }
    public void OpenLoad() => myLoadWindow.Open();
    public void OpenSave() => mySaveWindow.Open();
    public bool IsOpen => myLoadWindow.IsOpen || mySaveWindow.IsOpen;
    public bool HandleCancel() { myLoadWindow.Close(); mySaveWindow.Close(); return true; }
}

MenuRoot.Started += menu => menu.SaveBridge = new MySaves();   // or set it once the front end exists

The menu #

var menu = MenuRoot.Instance;
menu.SetHasSave(true);                 // shows Continue
menu.EnterGameplay();                  // hide menus; Esc / Start pauses
menu.ShowFrontEnd();                   // back to the main menu
menu.Pause(); menu.Resume();
menu.SetTheme(myTheme);
menu.ShowToast("Settings imported");     // a short message at the bottom
menu.ShowMessage("Saved", "Your game was saved.");
menu.OpenScreen("BrightnessScreen");     // any screen by name
menu.LoadScene("Level1", MenuMode.Gameplay);   // with the loading screen

Styles, backgrounds, logo and the Menu Camera #

var menu = MenuRoot.Instance;
menu.SetDisplayAs(DisplayAs.IconAndShortText);      // null: back to the theme's
menu.SetPromptDisplay(PromptDisplay.KeyOnly);
menu.SetFillStyle(FillStyle.Radial);
menu.SetMessagePosition(MessagePosition.TopCenter);
menu.HoldToConfirm = true;
menu.ShowToast("Saved", "Saved", MessageKind.Saving, 2f);

menu.SetBackgroundMode(BackgroundSlot.Pause, BackgroundMode.BlurredGame);   // null: the theme's
menu.SetBackground(BackgroundSlot.MainMenu, new MenuBackgroundStyle { mode = BackgroundMode.Image, image = mySprite, panAndZoom = true });
menu.SetOpacity(0.85f, null, 0.85f);                // panels, dim, buttons (null: the theme's)
menu.Logo = myLogo;
menu.LogoPlacement = LogoPlacement.ReplacesTitle;
menu.LogoOffset = new Vector2(0f, 20f);             // and TitleOffset
menu.PortraitLayout = myTallLayout;                 // and UltrawideLayout, UltrawideAspect; ActiveLayout says which is in use

// A video background (a clip, or videoUrl: a file in StreamingAssets or a full URL), and this menu's own opacity.
menu.SetBackground(BackgroundSlot.Pause, new MenuBackgroundStyle { mode = BackgroundMode.Video, videoClip = myClip, ownOpacity = true, panelOpacity = 0.7f });

var music = menu.GetComponent<MenuMusic>();         // MainMenuMusic, PauseMusic, SettingsMusic, CreditsMusic, LoadingMusic, Volume, FadeSeconds, Output
music.PauseMusic = myClip;

var moved = myButton.gameObject.AddComponent<ElementPlacement>();   // moves or scales one element; remove it to put it back
moved.MoveBy = new Vector2(40f, 0f);
moved.Scale = 1.2f;

menu.LoadingScreen.ProgressStyle = LoadingProgressStyle.Spinner;    // and Pictures
menu.CreditsScreen.OwnTransition = true;                            // any screen: Transition, TransitionSeconds
menu.CreditsScreen.Transition = SettingsMenuTheme.ScreenTransition.SlideFromLeft;
menu.TitleScreen.PromptAnimation = PromptAnimation.Pulse;

var director = MenuCameraDirector.Active;           // the Menu Camera showing now, or null
director?.NextShot();
// Manual control: director.ActiveWhen = MenuCameraActivation.Manual; director.Activate(); director.Deactivate();
// Events: director.onActivated, onDeactivated, onShotChanged(int)
float worst = ContrastCheck.WorstMenuText(menu.Theme, menu);   // WCAG ratio over a black and a white game

Accessibility, subtitles, languages #

SubtitleDisplay.Show("Over here!", 3f, "Mara");
float shake = AccessibilityState.CameraShakeScale;   // 0 with Reduce Motion
bool reduced = AccessibilityState.ReducedMotion;
string label = MenuLocalization.Get("mygame.hud.ammo", "Ammo");

Optional integrations #

URP, the Input System, Post Processing v2, Cinemachine and Unity's Localization package are detected with assembly versionDefines: their code compiles only when the package is installed, and nothing is required.

Something unclear or wrong? Tell us · Get help