Flexy.GameSettings: Start Guide

Define settings tabs, read and update values, and subscribe to changes.

Supports:

You can create your own setting type by using Enum32Setting as a template

No need any additional initialisation it is initialized on first access.
Super simple and elegant code

Define settings like this:

public class SettingsTab_Audio : GameSettingsTab
{
    public SingleSetting    SoundVolume    = new( "AudioSettingsTab_SoundVolume", 1 );
    public SingleSetting    SfxVolume      = new( "AudioSettingsTab_SfxVolume", 1 );
}

and use like this:

var volume = GameSettings.Get<SettingsTab_Audio>().SfxVolume;
GameSettings.Get<SettingsTab_Audio>().SfxVolume.Set(0.5f);

or like this:

var audioSettings   = GameSettings.Get<SettingsTab_Audio>();
var volume          = audioSettings.SfxVolume;
audioSettings.SfxVolume.Set(0.5f);

or this:

var audioSettings = GameSettings.Get<SettingsTab_Audio>();
audioSettings.SoundVolume.Changed += UpdateVolume;

Note:

Each setting implemented as struct so dont cache setting itself, cache SettingTab_Class
Service_GameSettings is MonoBehaviour so GameSettings static acees dont exists. If you need it in singleton form, you need to create it like this:

public class GameSettings : Service_GameSettings
{
	private static	GameSettings	_ref = null!;
	private void	Awake	( ) =>	_ref = this;
	
	public static T Get<T>	( ) where T:GameSettingsTab, new() => ((Service_GameSettings)_ref).Get<T>();
}

And place on some GlobalManagers GameObject in your project

One more thing

PlayerPrefs can not be read from MonoBehaviour constructor
So if you use Setting struct directly on MonoBehaviour you need to readLater: true

private BooleanSetting _eulaAccepted = new("Boot_EulaAccepted", false, readLater:true);

and later in Enable, Awake or something call Read() to read and cache it for the first time

_eulaAccepted.Read();

See the Barley-Break template for a complete project using game settings.

Install

Open Unity Package Manager
Add package from git URL: https://github.com/FlexyTools/Flexy.GameSettings