First of all, well done on extending the RPG to include a skill tree! Our hopes are that more students will go beyond the basics and introduce new concepts of their own.
As the PlayerSkills is a base class, not derived from MonoBehavior, I’m not sure of the mechanism you’re using to reference it in the game.
I’m going to assume it’s created in a class like PlayerController and work my example from there… if it’s too different from this, we’ll get more information and work from there…
PlayerSkills playerSkills=new PlayerSkills();
PlayerController doesn’t implement the ISaveable interface, but this actually works well for us… we’ll implement ISaveable and add the CaptureState and RestoreState methods…
We’re also going to implement ISaveable in the PlayerSkills class…
[System.Serializeable]
public struct SkillSavingStruct
{
public List<SkillType> skillList;
public int skillPoints;
}
public object CaptureState()
{
SkillSavingStruct savingStruct = new SkillSavingStruct();
savingStruct.skillList = unlockedSkillTypeList;
savingStruct.skillPoints = skillPoints;
return savingStruct;
}
public void RestoreState(object state)
{
SkillSavingStruct savingStruct = (SkillSavingStruct)state;
unlockedSkillTypeList = savingStruct.skillList;
skillPoints = savingStruct.skillPoints;
}
You may also need to add [System.Serializeable] above the SkillType enum for this to work properly.
Then the CaptureState and RestoreState for PlayerController (or whatever class has the PlayerSkills object) is a simple passthrough:
public object CaptureState()
{
return playerSkills.CaptureState();
}
public void RestoreState(object state)
{
playerSkills.RestoreState(state);
}