What is the most efficient method of saving a class?

Hi guys, I have a custom class which I need to save individually across 5 characters and 5 different jobs which can be equipped to any character.

    [System.Serializable]
    public string char;
    public string job;
     
    public class Skill{
     
    public bool     crush;
    public bool     parry;
    public bool     slam;
    public bool     magic;
    public bool     evadeUp;
     
    }
     
    public Skill[] allSkills;

Question is, how do I save this class or array?

The following is my previous attempt:

void SaveSkill ()
    {
    if (char == "FirstChar"  job == "Warrior")
    {
         if (crush == true)
             PlayerPrefs.setInt("FirstcharWarriorCrush", 1);

         if (parry== true)
             PlayerPrefs.setInt("FirstcharWarriorParry", 1);
    }
    }

Which will require me to cycle through every combination of character and job and skill. About 100 playerprefs…

Please do help. Thank you!

Frankly… I would turn that object into a JSon and save it as a String.

I never used it, but there’s a free JSon parser here: http://wiki.unity3d.com/index.php/SimpleJSON

Another way would be by reflection and building prefs from the reflected values.

I see… Thanks! I’ve read through that wiki and I like what I see. Though it didn’t specifically mention how to convert stuff into JSon.

Though you’ve never used it, I still have to ask if you have any ideas…

If you can’t answer this, no problem. I hope someone who has used it may be able to help.

The “Unity way” would probably be to use a ScriptableObject. Here’s a good tutorial: http://www.jacobpennock.com/Blog/?p=670

We are talking about runtime serialization. Like which job a player took, or his current stats. AssetDatabase is Editor only.

I read the question as a design-time thing, but if it’s runtime then you’re certainly right.

Go with the JSON approach. It looks like what you’re trying to serialize is pretty simple and my JSON .NET asset is way overkill for what you’re needing to do. You should take a look at JSON Object which is free on the asset store, documented and pretty simple to use for cases like yours:

https://www.assetstore.unity3d.com/#/content/710

Edit: Documentation is on the Wiki:
http://wiki.unity3d.com/index.php/JSONObject