-
Notifications
You must be signed in to change notification settings - Fork 0
Settings.md
cfloutier edited this page Apr 27, 2024
·
4 revisions
Settings is used for 2 purposes :
- Save user preferences
- Bind the internal mod values with UI controls
All internal values of the mod could used one setting class to keep data saved and shared with UI.
this is a generic class that can be used for main primitives including :
stringbooleanintegerfloatdoubleColorVector3
other types could be added later if needed
public Setting(string key, T default_value)
- the
keyis used to define where the value will be saved in the settings file. If key is null or empty it just won't be saved, the default value will be the same on startup - the default_value, defines the initial value, it will be overloaded on settings first load.
ex : Define your setting value like that
public Setting<bool> bool_item = new Setting<bool>("my_settings.bool_item", true);the value is a property
ex:
bool_item.value = true;
if (bool_item.value) ...
the default value can be recovered using the Reset function
use the Bind function that can be found on all K2UI controls to bind values with the UI
ex :
// in your Window's constructor
// panel is the root VisualElement
// the K2Toggle is defined with the name `bool_settings`
panel.Q<K2Toggle>("bool_settings").Bind(bool_item);