Skip to content

SST-Systems/ConfigProvider

Repository files navigation

ConfigProvider

release release date last commit license

English | Русский


Reach any ScriptableObject config by type.

Central, type-safe access to your ScriptableObject configs. Author configs as Config subclasses, gather them into a single ConfigCollection asset (auto-collected in the editor), place it in a Resources folder, call Initialize() once when you're ready, and ConfigProvider hands back any config via Get<T>().

Table Of Contents

Details

Installation

  1. .unitypackageReleases
  2. UPMWindow → Package Manager+Add package from git URL: https://github.com/SST-Systems/ConfigProvider.git Append #tag to pin a version.
  3. Manual — clone or download, copy to Assets/.

Unity 2021.3+

Standalone — no package dependencies beyond Unity.


Classes

Type Purpose
Config Abstract ScriptableObject base for every config.
ConfigCollection ScriptableObject holding the list of configs. In the editor it can auto-collect every Config asset (toggle + Find Force button).
IConfigProvider void Initialize() + T Get<T>() where T : Config.
ConfigProvider Loads the collection when you call Initialize(), then serves configs by type.

Usage

// 1. Author configs
[CreateAssetMenu(menuName = "Config/PlayerConfig")]
public class PlayerConfig : Config
{
    public int StartingHealth = 100;
}

// 2. Create a ConfigCollection asset:
//    Create → Config → ConfigCollection, and put it in a Resources folder
//    named "ConfigCollection". Enable "Auto Collect" (or press "Find Force")
//    to gather every Config asset in the project.

// 3. Create the provider and initialize it yourself, whenever you're ready:
public class Game
{
    private readonly IConfigProvider _configProvider = new ConfigProvider();

    public void Boot()
    {
        _configProvider.Initialize();          // loads ConfigCollection from Resources

        int hp = _configProvider.Get<PlayerConfig>().StartingHealth;
    }
}

Notes

  • Call Initialize() once before the first Get<T>() — the provider is standalone, so you decide when to run it (a bootstrap step, a scene load, your own init pipeline, …).
  • The collection asset must be named ConfigCollection and live in a Resources folder — it is loaded via Resources.Load<ConfigCollection>("ConfigCollection").
  • With Auto Collect on, an AssetPostprocessor refreshes the list whenever assets change; otherwise press Find Force in the inspector.
  • Get<T>() logs an error and returns null if the requested config isn't in the collection.
  • Editor tooling (auto-collect, Find Force) is guarded by #if UNITY_EDITOR and stripped from builds.

License

Distributed under the MIT License. Free for personal and commercial use.

Author — Egor Shesterikov.

About

Type-safe access to ScriptableObject configs for Unity.

Topics

Resources

Stars

Watchers

Forks

Releases

Contributors

Languages