I'm extremely new to Unity, and I'm trying to figure out if this design makes sense. I'm creating a card game in which multiple instances of the same card will exist. I'm trying to determine if the "idiomatic" way to do this is as follows:
- Create a Scriptable Object to contain card metadata.
- Then create specific Scriptable Objects for each card.
- Then at runtime, whenever I need a specific card, I create a gameObject add the (simple for example purposes)
IsCardMonoBehavior and associateIsCardwith whateverScriptableObjectcorresponds to the specific card in question to extract/assign metadata.
Does this make sense or is there a more performant/idiomatic way to do this?
This is my current implementation of the above solution.
using UnityEngine;
using UnityEngine.UI;
[CreateAssetMenu(fileName = "CardSO", menuName = "ScriptableObjects/Card")]
public class CardSO : ScriptableObject
{
public string cardName;
public Image cardImage;
// There could be more specific SOs for creatures, spells, etc.
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Image))]
public class IsCard : MonoBehaviour
{
public CardSO cardSO;
// Start is called before the first frame update
void Start()
{
if (cardSO == null)
{
return;
}
Image image = GetComponent<Image>();
image.sprite = cardSO.cardImage.sprite;
//Reference/Utilize other properties when applicable.
//If this were a creature, perhaps we could have a mono behavior that stores power/toughness, etc.
//public int power;
//power = creatureCardSO.power;
}
}
```