Looking for better way to set up individual card stats

So I’m currently working in C# in unity for a card game. I’m at the point that I need to start loading in the cards and instead of making a script for every single card, one by one I want to know if there’s a way to minimize the time of all of that. In essence, I’m looking for a script that can have values taken from the inspector tab then use those values to make the C# script. I was thinking of creating the initial script to take the values in and then use this snippet (Editor script need to create Class Script automatically - Questions & Answers - Unity Discussions) in a function to use all of the values to put together this script. I am not sure if this is the best way or even a good way to do this. Im just wondering if there’s a way to do this with less hard coding?

EDIT
The information would be preferably taken in from the Inspector, but I am also open to more ideas such as Excel documents or even a non-unity affiliated window

Maybe you could have a Card Creation script that takes in all the data for a single card. Then you make a custom Editor for the script so that you can put in a button that creates the GameObject with a script that has the stats that was put in the Card Creator fields.

Have you looked into scriptable objects? You could even extend the editor with your own windows to create a factory for creating your cards.

Okay, I just looked into this and I see that this is really close to what I want. It’s an extra step, but would you happen to have any idea how to link this to an excel file? I just found out that the creator already has an excel document of these cards. Its not a MUST, but it would cut down a lot on time.

Using an Excel document is no problem. Provided your can export to XML and have your classes structured so minimal effort is needed to map the XML to your classes, this should be a good way forward…
http://answers.unity3d.com/questions/651714/learning-how-to-deserialize-xml-file.html

Of course, you can get fancy with custom editors and what-not, but one step at a time if you’re unsure. A custom editor will speed up your production… only after the time it takes to complete it.

did you ever here about Object Oriented Programming :wink:
Just make a Card class with public fields so you can set the value’s in the inspector?

off course if you wanna generate all you cards…
Serialize your Card class with [System.Serializable], make a CardGenerator script that reads in your XML or CSV file and create a new Card() with the data for that card…

Could you explain what serialize does? I saw it in a video, but he didnt go in depth

here are some links that explain it:

Maybe I’m missing something, but i don’t see what your problem is :slight_smile:

public class Card: MonoBehaviour
{
    public int level;
    public int health;
    public float mana;
    ...
}

just put something like that on a gameObject fill in the values in the inspector é voila you have a card…
need an other one with different value? take an other gameObject put the script on it and give the variables different values… save them as prefabs and load them in your game when needed…

but like i said, maybe I’m missing something, because I’m sure you knew that already

Okay, this looks a lot more like what I’m trying to do.
So, I’m looking to condense the “take an other gameObject put the script on it and give the variables different values… save them as prefabs and load them in your game when needed…” part to a script instead of doing each by hand. Going in the sequence of events : Read in card stats from a text file, do a bit of sorting, Create the 2D object (I’ll worry about how to script in the formatting for the card later), create a class based on the information brought in, apply the script to the card, make it a prefab.I want to do this all in one script and I feel as though this is the best sequence to do this in, but I am not sure. And just to make sure, the class you posted would be the class I serialize, correct?

use 1 prefab iterate trough your data and instantiate the prefab for ever card data? you could do an easy convert to a class if you would have your data as json’s

I have absolutely no experience with JSON, I just picked up C# a few days ago. Im honestly not even sure if the route that im going is correct. I just dont want to put in card by card all the stats

If you just want to define the cards somewhere in the game, IMO the easiest to understand yet efficient way would be to create a serialiazable class which @jister recommended earlier to store your card data, but make an array or list of them instead and define them in the inspector. The class should not extend from Monobehavior to be used in an array or list.

example card class:

[System.Serializable]
public class CardData
{
    public string name;
    public int level, health, mana;//or whatever you need
}

using the card class in an array

public class CardDataHolder: MonoBehaviour
{
    public CardData[] allCardData;
}

When you use the CardDataHolder in the scene you will be able to set the size of the array which would dictate the number of unique card datas your game will have, and the data in the individual cards themselves.