Reputation: 48636
I am using scriptable objects to define an achievement object and an achievementsList(array of achievements) object with data that i can pretty much define through the Unity editor.
Those achievements are strictly static in nature, they just define the content of those achievements but do not store any user related data.
For user related storage, I am using serialization instead, through a Player class. Now, I want to come up with the best way of saving achievements related state through a serializable class.
My initial idea would be to use something like :
[Serializable]
public class PlayerAchievements {
public List<PlayerAchievement> achievements;
}
public class PlayerAchievement {
public Achievement achievement;
public bool isCompleted;
}
Achievement is the Scriptable object and PlayerAchievement is pretty much used to store the state in relation to a specific statically defined Achievement. The problem I am seeing with this approach is that I would have to search the static AchievementList each time and recreate PlayerAchievement objects for each achievement. This doesn't look very efficient to me.
How are people handling such cases ? Is it possible to extend the scriptable object to another class in a more efficient way ?
Upvotes: 0
Views: 439
Reputation: 367
Try something like static list of achievements, where you will have achievement id, name, description etc. Each player should have list of achievements done (by i.e. id) or bool array where id=index of that array. That's easiest way I can think of.
Upvotes: 1