Pro Only: Weaver Lite allows you to try out this feature in the Unity Editor, but it will not be available in a runtime build unless you purchase Weaver Pro.
Weaver's static dependency injection system is primarily used for asset references, but it can also be used for other things such as saving and loading simple values in
PlayerPrefs with the
[Pref] attribute and
EditorPrefs with the
- On startup (including in Edit Mode in the Unity Editor) the attributed value is immediately retrieved from the prefs.
- Then on shutdown its current value is saved back to the prefs.
- If you wish to save the prefs earlier you can call
- By default, each pref will use the
Namespace.DeclaringType.MemberNameas its key string, but you can specify a custom
Keyin the attribute's constructor.
- You can also specify an
OldKeyso that it can still load old values saved with a previous key (such as if you move or rename the field).
- The system currently supports
enumfields. Support for more types could be added, however Unity's prefs system is generally considered bad practice so it is recommended that you use a fully fledged serialization system such as ProtoBuf or Json for anything more complex.