I have a gameobject with several child objects that carry the component. Some are enabled some arent. The ones that are enabled are in an array. Basically im trying to figure out the best way to save them to player prefs.
.
.
.
- Edit
***I solved it… Solution is below. FYI you must first search google for playerprefsX, find the script on github, import that script into your project and then you can access the playprefsX class. Hope this helps someone!
public component[] allComponents;
public list<string> componentNames;
public void Save()
{
foreach (component c in allComponents)
{
if (c.isenabled)
{
if (!componentNames.Contains(c.name))
componentNames.Add(c.name);
}
else
{
if (componentNames.Contains(c.name))
{
componentNames.Remove(c.name);
}
}
}
saveArray= componentNames.ToArray();
PlayerPrefsX.SetStringArray("savedComponents", saveArray);
}
public void Load()
{
foreach (component c in allComponents)
{
c.isenabled = false;
}
loadedArray = PlayerPrefsX.GetStringArray("savedComponents");
foreach (string s in loadedArray)
{
foreach (component c in allComponents)
{
if (c.name == s)
{
c.isenabled = true;
}
}
}
}