How to Use?
Creating Settings
Section titled “Creating Settings”Create a ScriptableObject and add the [ProjectSettings] attribute.
using OneLastClick.ProjectSettings;using UnityEngine;
[ProjectSettings]public class ExampleProjectSettings : ScriptableObject{ [SerializeField] public int IntValue; [SerializeField] public GameObject Prefab; [SerializeField] public string Message = "Hello, World!";}The package automatically creates a corresponding entry under Edit → Project Settings.
Accessing Settings
Section titled “Accessing Settings”Runtime
Section titled “Runtime”Use ProjectSettingsDatabase.Get<T>() to access settings at runtime.
var settings = ProjectSettingsDatabase.Get<ExampleProjectSettings>();
Debug.Log(settings.Message);Non-editor-only settings are automatically made available to the runtime and within builds, so no asset references or manual initialization are required.
Editor
Section titled “Editor”Use ProjectSettingsEditorDatabase.GetOrCreateDefault<T>() to access settings from editor code.
var settings = ProjectSettingsEditorDatabase.GetOrCreateDefault<ExampleProjectSettings>();
Debug.Log(settings.Message);If the settings file does not exist, it is created automatically.
Modifying Settings
Section titled “Modifying Settings”Changes made through editor code can be persisted using SaveProjectSetting().
var settings = ProjectSettingsEditorDatabase.GetOrCreateDefault<ExampleProjectSettings>();
settings.IntValue = 42;
ProjectSettingsEditorDatabase.SaveProjectSetting(settings);Editor-Only Settings
Section titled “Editor-Only Settings”Settings that are only required by editor tooling can be marked with editorOnly.
[ProjectSettings(editorOnly: true)]public class BuildProjectSettings : ScriptableObject{ public string BuildOutputDirectory; public bool EnableDevelopmentBuild;}Editor-only settings:
- Are available through
ProjectSettingsEditorDatabase. - Appear in Project Settings.
- Are not included in runtime builds.
- Cannot be accessed through
ProjectSettingsDatabase.Get<T>().