Home

Awesome

Easy Project Settings

openupm

Easily create custom Project Settings by adding [ProjectSettings(...)] attribute to your ScriptableObject subclass!

using UnityEngine;
using Gilzoide.EasyProjectSettings;

[ProjectSettings("Assets/EasyProjectSettingsSamples/SampleSettings",
    SettingsPath = "Project/Easy Project Settings Samples/SampleSettings",
    Label = "Sample Label")]
public class SampleSettings : ScriptableObject
{
    public string SampleMessage;
}

Features

How to install

This package is available on the openupm registry and can be installed using the openupm-cli:

openupm add com.gilzoide.easy-project-settings

Otherwise, you can install directly using the Unity Package Manager with the following URL:

https://github.com/gilzoide/unity-easy-project-settings.git#1.1.0

How to use

When AssetPath is relative to the Assets folder, it can be referenced anywhere in project, just like any other ScriptableObject, and loaded using ProjectSettings.Load in editor code.

If you don't plan on loading settings at runtime code outside of the Unity editor, this is the recommended usage.

using UnityEngine;
using Gilzoide.EasyProjectSettings;

[ProjectSettings("Assets/EasyProjectSettingsSamples/SampleSettings",
    SettingsPath = "Project/Easy Project Settings Samples/SampleSettings")]
public class SampleSettings : ScriptableObject
{
    public string SampleMessage;
}

public class SampleMonoBehaviour : MonoBehaviour
{
    // set me up in the Inspector
    [SerializeField] private SampleSettings _sampleSettings;

    void Start()
    {
        Debug.Log($"Message from settings = '{_sampleSettings.SampleMessage}'");
    }
}

When AssetPath is relative to a Resources folder inside Assets folder, it can be loaded using ProjectSettings.Load both in editor and built players.

If you plan on loading settings at runtime code outside of the Unity editor, this is the recommended usage.

using UnityEngine;
using Gilzoide.EasyProjectSettings;

[ProjectSettings("Assets/EasyProjectSettingsSamples/Resources/SampleResourcesSettings",
    SettingsPath = "Project/Easy Project Settings Samples/SampleResourcesSettings")]
public class SampleResourcesSettings : ScriptableObject
{
    public string SampleResourcesMessage;
}

public class SampleMonoBehaviour : MonoBehaviour
{
    void Start()
    {
        SampleResourcesSettings settings = ProjectSettings.Load<SampleResourcesSettings>();
        Debug.Log($"Message from settings = '{settings.SampleResourcesMessage}'");
    }
}

When AssetPath is not relative to Assets folder, the asset is only usable by code running in editor, loaded using ProjectSettings.Load.

This may be useful for defining settings for editor-only tools.

using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
using Gilzoide.EasyProjectSettings;

[ProjectSettings("ProjectSettings/EasyProjectSettingsSamples/EditorOnlySettings",
    SettingsPath = "Project/Easy Project Settings Samples/EditorOnlySettings")]
public class EditorOnlySettings : ScriptableObject
{
    public string EditorOnlyMessage;
}

public static class SampleEditorOnlyPostProcessBuild
{
    [PostProcessBuild]
    public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
    {
        EditorOnlySettings settings = ProjectSettings.Load<EditorOnlySettings>();
        Debug.Log($"Built project, message from settings = '{settings.EditorOnlyMessage}'");
    }
}