Skip to content

Dutchskull/Unity.Configuration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Unity.Configuration

A flexible configuration system for Unity that brings the power of Microsoft.Extensions.Configuration to your Unity projects — supporting JSON, environment variables, command-line arguments, and custom configuration sources.

Easily view and edit configuration directly in Project Settings, with real-time resolution of all merged configuration values.

🚀 Features

  • 🔧 Editable configuration in Project Settings
  • 🧩 Multiple configuration sources — JSON, environment variables, command line, or custom sources
  • 🪄 Custom source registration (works both in runtime and editor contexts)
  • 🧠 Automatically merges and displays all sources in one resolved configuration view
  • 🧰 Works with or without DI containers (like Reflex)

📦 Installation

You can install this package directly from GitHub using Unity’s Package Manager.

  1. Open Unity and go to
    Window → Package Manager

  2. Click the + button → Add package from Git URL...

  3. Paste the following URL: https://github.com/Dutchskull/Unity.Configuration.git?path=/Unity.Configuration/Packages/Unity.Configuration

  4. Click Add — Unity will automatically download and install the package.

🧭 Where to Find It

Once installed, open:

Edit → Project Settings → Configuration

You’ll see a new Configuration section where you can:

  • Edit your local JSON configuration (ConfigsAsset.environment)
  • See all registered configuration sources (with their JSON content)
  • View the resolved configuration, showing final merged values from all sources

🧰 Example Usage

🧩 Register a Configuration Source (Runtime)

Add this MonoBehaviour to any GameObject:

using UnityEngine;
using Microsoft.Extensions.Configuration;

public class RegisterRuntimeConfigSource : MonoBehaviour
{
 [TextArea(3, 10)]
 public string runtimeJson = "{ \"Gameplay:Speed\": 1.5 }";

 private void Awake()
 {
     ConfigSourceRegistry.RegisterSource(
         builder => builder.AddJson(runtimeJson),
         "Runtime JSON (from RegisterRuntimeConfigSource)",
         runtimeJson
     );
 }
}

When you enter Play mode, this source will appear in Project Settings → Configuration, and its values will merge into the final resolved configuration.

🧰 Register a Source in the Editor (Auto-loaded)

For editor-only configuration or mock data, you can register a source automatically when Unity loads:

#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;

[InitializeOnLoad]
public static class EditorConfigSourceRegistration
{
    static EditorConfigSourceRegistration()
    {
        string editorJson = "{ \"Editor:Mode\": \"DevTools\" }";

        ConfigSourceRegistry.RegisterSource(
            builder => builder.AddJson(editorJson),
            "Editor JSON (from EditorConfigSourceRegistration)",
            editorJson
        );
    }
}
#endif

This will automatically appear as a source in the Configuration window after every recompile.

⚙️ How It Works

  1. ConfigsAsset stores your editable JSON environment.

  2. ConfigSourceRegistry builds the final IConfigurationRoot using:

    • JSON from ConfigsAsset
    • Environment variables
    • Command line arguments
    • Any custom registered sources
  3. ProjectConfigSettingsProvider displays:

    • Editable JSON for ConfigsAsset
    • All registered configuration sources (with content)
    • The resolved merged configuration

🧩 Example Output (in Project Settings)

Configuration Sources
• ConfigsAsset.environment (inline JSON)
  {
    "App": { "Mode": "Local" }
  }

• Editor JSON (from EditorConfigSourceRegistration)
  {
    "Editor:Mode": "DevTools"
  }

• Runtime JSON (from RegisterRuntimeConfigSource)
  {
    "Gameplay:Speed": 1.5
  }

Resolved Configuration
{
  "App:Mode": "Local",
  "Editor:Mode": "DevTools",
  "Gameplay:Speed": 1.5
}

🧪 Compatibility

  • Unity 2021.3 LTS or newer
  • Works in both Editor and Runtime
  • Compatible with Reflex, Zenject, or plain MonoBehaviour setup

💬 Feedback & Contributions

Pull requests, suggestions, and issues are welcome! If you find this useful, feel free to ⭐ the repository or share it.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •