Replies: 3 comments 1 reply
-
Hi! Awesome lib! Do I have to add a second argument every time when I want to load a safe file object like this? In my project I initialized an object Settings() in Start() method and created a method update a specific field of that class, this field is a class as well. But this method doesnt change the value for some reason. Other methods did change the values but this doesn't. Could it be because the other methods updated simple Integers and the new one operates with complex objects field? Here's 3 methods I used.
Theme() is a struct and looks like this:
|
Beta Was this translation helpful? Give feedback.
-
Hi
first: the second argument "new Settings()" is the default value in case
there is nothing saved in playerPrefs you can use your default settings
object instead of new Settings()
the second thing I guess when you deal with complex object you need to save
both classes or structs (I will give you an example:)
class Point {
public float x;
public float y;
}
class Line {
public Point pt1;
public Point pt2;
}
suppose we have an object of type Line
Line line = new Line();
Point a = new Point();
Point b = new Point();
line.pt1=a ; line.pt2=b;
// save :
PlayerPrefsExtra.SetObject("_line",line);
PlayerPrefsExtra.SetObject("_a",a);
PlayerPrefsExtra.SetObject("_b",b);
//load :
line=PlayerPrefsExtra.GetObject<Line>("_line",line);
a=PlayerPrefsExtra.GetObject<Point>("_a",a);
b=PlayerPrefsExtra.GetObject<Point>("_b",b);
line.pt1=a; line.pt2=b;
…On Sun, Nov 27, 2022, 16:06 dmitrikar713 ***@***.***> wrote:
Hi! Awesome lib!
I have a question. Please help :)
Do I have to add a second argument every time when I want to load a safe
file object like this?
Settings settings = PlayerPrefsExtra.GetObject<Settings>("settings", new
Settings());
Or do I add this "new Settings()" argument only when initializing this
object in PlayerPrefsExtra memory?
And then, do I need to add the Generic brackets when i SetObject? Cause in
your readme.md you didn't.
In my project I initialized an object Settings() in Start() method and
created a method update a specific field of that class, this field is a
class as well. But this method doesnt change the value for some reason.
Other methods did change the values but this doesn't. Could it be because
the other methods updated simple Integers and the new one operates with
complex objects 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;
}
—
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AINUP2VOZLLL2MLCU36MNMLWKN2HZANCNFSM4XHPGPWA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
I guess that its working with complex objects too because it's already
tested Vectors inside a custom object and it works . Vector is a complex too
…On Sun, Nov 27, 2022, 18:32 Hamza Herbou ***@***.***> wrote:
Hi
first: the second argument "new Settings()" is the default value in case
there is nothing saved in playerPrefs you can use your default settings
object instead of new Settings()
the second thing I guess when you deal with complex object you need to
save both classes or structs (I will give you an example:)
class Point {
public float x;
public float y;
}
class Line {
public Point pt1;
public Point pt2;
}
suppose we have an object of type Line
Line line = new Line();
Point a = new Point();
Point b = new Point();
line.pt1=a ; line.pt2=b;
// save :
PlayerPrefsExtra.SetObject("_line",line);
PlayerPrefsExtra.SetObject("_a",a);
PlayerPrefsExtra.SetObject("_b",b);
//load :
line=PlayerPrefsExtra.GetObject<Line>("_line",line);
a=PlayerPrefsExtra.GetObject<Point>("_a",a);
b=PlayerPrefsExtra.GetObject<Point>("_b",b);
line.pt1=a; line.pt2=b;
On Sun, Nov 27, 2022, 16:06 dmitrikar713 ***@***.***> wrote:
> Hi! Awesome lib!
> I have a question. Please help :)
>
> Do I have to add a second argument every time when I want to load a safe
> file object like this?
> Settings settings = PlayerPrefsExtra.GetObject<Settings>("settings", new
> Settings());
> Or do I add this "new Settings()" argument only when initializing this
> object in PlayerPrefsExtra memory?
> And then, do I need to add the Generic brackets when i SetObject? Cause
> in your readme.md you didn't.
>
> In my project I initialized an object Settings() in Start() method and
> created a method update a specific field of that class, this field is a
> class as well. But this method doesnt change the value for some reason.
>
> Other methods did change the values but this doesn't. Could it be because
> the other methods updated simple Integers and the new one operates with
> complex objects 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;
> }
>
> —
> Reply to this email directly, view it on GitHub
> <#1 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AINUP2VOZLLL2MLCU36MNMLWKN2HZANCNFSM4XHPGPWA>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***
> com>
>
|
Beta Was this translation helpful? Give feedback.
-
👋 Welcome!
We’re using Discussions as a place to connect with other members of our community. We hope that you:
build together 💪.
To get started, comment below with an introduction of yourself and tell us about what you do with this community.
Beta Was this translation helpful? Give feedback.
All reactions