-
-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hi! Awesome lib!
I have a question. Please help :)
In my project I initialized an object Settings() in Start() method. Settings() is a class that has a "theme" field with Theme type in it, it's initial value is an object of Theme type too. I then created a method setTheme() to update this field. But the value doesn't change for some reason. Other methods do change the Settings() fields values but the new one doesn't.
Any idea why my new method doesn't work? Can using/not using generics in GetObject/SetObject methods be important and when do I need to put a second new Theme() argument, any time I want to load it or only when I initialize it? Could it be because the other methods update simple Integers and the new one operates with complex class type field?
Here's 3 methods I used.
//////////////////////// FIRST 2 DO WORK
public static void ToggleSpwnBlcVal(int val) {
Settings settings = PlayerPrefsExtra.GetObject<Settings>("settings", new Settings());
if (settings.newBlocksValue.Contains(val)) settings.newBlocksValue.Remove(val);
else settings.newBlocksValue.Add(val);
PlayerPrefsExtra.SetObject("settings", settings);
UpdateOptionsUI(settings);
}
public static void SetSpwnAmmount(int val) {
Settings settings = PlayerPrefsExtra.GetObject<Settings>("settings", new Settings());
settings.spwnAmmount = val;
PlayerPrefsExtra.SetObject("settings", settings);
UpdateOptionsUI(settings);
}
///////////////////// THIS ONE DOESNT WORK
public void setTheme(string mystringname) {
Settings settings = PlayerPrefsExtra.GetObject<Settings>("settings", new Settings());
settings.theme = Themes.list.Find(x => x.name == "cacao");
PlayerPrefsExtra.SetObject("settings", settings);
// Camera.main.backgroundColor = settings.theme.bodyBg;
}
Theme() is a struct and looks like this:
public struct Theme
{
public string name;
public ButtonsPalette btns;
public BlocksPalette blcks;
public Color32 bodyBg;
public Color32 statsBg;
public Color32 statsTxt;
public Color32 titles;
}
Settings is a class
public class Settings {
public int spwnAmmount = 1;
public List<int> newBlocksValue = new List<int> { 2, 4 };
public Theme theme = Themes.list.Find(e => e.name == "classic");
}