- Home /
How can I save a deck of Cards (ScriptableObjects)?
I'm working on a card game that has ScriptableObjects for the cards. The cards contain different classes that make them difficult to serialize (AudioClips, other instances, etc...)
I've decided to pack all of my cards on an AssetBundle called "cards" in order to pull them back up when necessary.
I'd just like to know how I could store decks (a list of cards, simply put) in order to make their own collections and use them in my game. So far I've tried the JsonUtility API which only stored references that aren't persistent. From what I've understood, the BinaryFormatter won't be of any use for ScriptableObjects that contain these types of data. If you have a solution that doesn't include the use of an AssetBundle, I can get rid of it. Here is the card.
[Serializable]
public abstract class Card : ScriptableObject
{
[Header("Storage")]
[SerializeField]
private bool unobtainable;
[Header("Data")]
[SerializeField]
private string cardName;
[SerializeField]
private Sprite frontThumbnail;
[SerializeField]
[Range(0,10)]
private int energyCost;
[SerializeField]
private AudioClip actionSound;
[SerializeField]
private string description;
public bool Unobtainable => unobtainable;
public string CardName => cardName;
public Sprite FrontThumbnail => frontThumbnail;
public int EnergyCost => energyCost;
public AudioClip ActionSound => actionSound;
public string Description => description;
public abstract CardBehavior Initialize(Player player, Transform parent);
public abstract CardBehavior InitializeAsPreview(Transform parent);
}
Here's my attempt at creating the Deck Class. For the moment, the deck contains the bare minimum. I was thinking of maybe replacing it by a persistent ID instead of the card array directly.
[Serializable]
public class Deck : ScriptableObject
{
public Card[] cards;
public string deckName;
}
Thank you. If you need additionnal info, don't hesitate to ask.