Saving Color with EditorPrefs

How to save non-primitive types (Color for example) with EditorPrefs?

It’s a pain, but you could save them as an R/G/B/A string (like “1/0/0/0” for red), and then parse them back into colors.

The simplest way would be to simply store the subdata and reconstruct it on load:

C#

void OnSave()
{
   EditorPrefs.SetFloat("PlayerColor_R", myColor.r);
   EditorPrefs.SetFloat("PlayerColor_G", myColor.g);
   EditorPrefs.SetFloat("PlayerColor_B", myColor.b);
   EditorPrefs.SetFloat("PlayerColor_A", myColor.a);
}

void OnLoad()
{
   myColor = new Color(
      EditorPrefs.GetFloat("PlayerColor_R", 1.0f),
      EditorPrefs.GetFloat("PlayerColor_G", 0.0f),
      EditorPrefs.GetFloat("PlayerColor_B", 1.0f),
      EditorPrefs.GetFloat("PlayerColor_A", 1.0f)
   );
}

Note: The above will set myColor to bright magenta if no data was found