I'm creating a multiplayer game, including different heros with different values (e.g. health, damage). I initially fetch these values from a database and store them into a struct.
-> I have little to no knowledge about structs
-> and got told this is probably a performance loss / bad approach
Storing the values in the struct and creating a dictionary (int, my-struct) to obtain the values worked perfectly fine before.
I've come to the point where I want to store specific sprites for each hero inside this struct. I consider fetching these sprites through Resources.Load (which I guess is the most simple way)
public struct data
{
public string Name;
public int ID, hp, dmg, range, magazin;
public float tbtwb, rltime;
public Sprite heroSprite; //Structs don't seem to like Unity's sprite type
}
public Dictionary<int, data>_HeroDict;
This is how I feed the struct and add an entry into the dictionary.
while (rdr.Read())
{
//Store it into the Dictionary
data itm = new data();
itm.Name = rdr["Name"].ToString();
itm.ID = int.Parse (rdr["ID"].ToString());
itm.hp = int.Parse (rdr["Hp"].ToString());
itm.dmg = int.Parse (rdr["Dmg"].ToString());
itm.magazin = int.Parse (rdr["Magazin"].ToString());
itm.range = int.Parse (rdr["Range"].ToString());
itm.tbtwb = float.Parse(rdr["Tbtwb"].ToString());
itm.rltime = float.Parse(rdr["Rltime"].ToString());
//What I thought of:
itm.heroSprite = Resources.Load ("Sprites/Sprite1", typeof(Sprite)) as Sprite;
_HeroDict.Add(itm.ID, itm);
}
My issue: I can't store sprites inside a struct and don't know about a workaround.
I've been told I could/should use a class instead of a struct, but I couldn't store a Sprite as well, not knowing why.
Can you point me into the right direction and give me an example approach?
Thanks in advance, Csharpest