Config Assets
Simple & Lightweight solution for managing configuration assets in Unity projects
Install
The package is available on the openupm registry. It's recommended to install it via openupm-cli.
openupm add me.caneva20.config-assets
Usage
First create a partial class
and add the Config
attribute to it
[Config]
public partial class MyConfig {
// Your fields & attributes
}
Then add as many fields as you need, note that it must be Serializable by Unity for it to save. Anything that is valid for a ScriptableObject
is valid here as well.
[Config]
public partial class MyConfig {
[SerializeField] private string _myString;
[SerializeField] private bool _myBool = true;
//This also works
public int myInt;
}
Your class is now accessible through a direct static access.
To use it just call YOUR_CLASS_NAME.YOUR_FIELD
int valueFromConfig = MyConfig.myInt;
- Whenever you get back to Unity, a new
.asset
file will be created for your configuration and it will be added toPreloaded assets
under the player settings. - You can access your configuration through Unity's
Project Settings
underEdit>Project Settings...
in the toolbar, and then selecting the desired configuration under theConfig assets
section.
Customization
The [Config]
attribute has some properties to allow you to customize you configuration a bit:
Attribute | Description | Default |
---|---|---|
FileName |
The name of the generated file | null (Will use the namespace instead) |
DisplayName |
The name used under Project Settings |
null (Will use the type name instead) |
EnableProvider |
Whether or not to generate a SettingsProvider |
true |
Scope |
The scope used by the SettingsProvider |
SettingsScope.Project |
Keywords |
The keywords used by the SettingsProvider |
none/empty |
GenerateSingleton |
Whether or not to generate the .Instance property |
true |