Search Unity

Adding Image to List for creating Cards for TCG

Discussion in 'Scripting' started by Malixx, May 4, 2018.

  1. Malixx

    Malixx

    Joined:
    Oct 30, 2016
    Posts:
    1
    Hi, I hate being that guy who asks the same question everyone else already has but I can't seem to find my solution anywhere online for part of a TCG.
    I have created a csv file containing all the potential stats for each cards, such as item game, description, to hit & kill modifiers, etc. They all also have a Card Branch ID and Card Leaf ID for quickly finding a card by sorting through categories and then the individual card without using tags or strings.
    What I want to do now is to be able to load an image onto the card by refering to the Card Branch & Leaf ID when it is drawn without going through a huge "If this card is correct then load image & return, else next card" as there are over 50 cards for the system to sort through.
    What I am wanting to do is add the image, or at least a path to the image, to a list so I can refer to the universal Card Branch & Leaf ID numbers.
    Currently my code is looking like this.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class LoadCards : MonoBehaviour {
    6.  
    7.     public List<Card> Cards = new List<Card>();
    8.     void Start()
    9.     {
    10.         TextAsset CardData = Resources.Load<TextAsset>("Cards_UnityVersion1");
    11.         string[] data = CardData.text.Split(new char[]{'\n'});
    12.         for (int i = 1; i < data.Length; i++)
    13.         {
    14.             string[] row = data.Split(new char[] { ',' });
    15.  
    16.             Card c = new Card();
    17.             int.TryParse(row[0], out c.CardBranchId);
    18.             int.TryParse(row[1], out c.CardLeafId);
    19.             c.Item = row[2];
    20.             c.Description = row[3];
    21.             int.TryParse(row[4], out c.AntimatterRecipe);
    22.             int.TryParse(row[5], out c.R1Ingredient1);
    23.             int.TryParse(row[6], out c.R1Ingredient2);
    24.             int.TryParse(row[7], out c.R1Ingredient3);
    25.             int.TryParse(row[8], out c.R1CraftedItem);
    26.             int.TryParse(row[9], out c.R2Ingredient1);
    27.             int.TryParse(row[10], out c.R2Ingredient2);
    28.             int.TryParse(row[11], out c.R2Ingredient3);
    29.             int.TryParse(row[12], out c.R2CraftedItem);
    30.             int.TryParse(row[13], out c.R3Ingredient1);
    31.             int.TryParse(row[14], out c.R3Ingredient2);
    32.             int.TryParse(row[15], out c.R3Ingredient3);
    33.             int.TryParse(row[16], out c.R3CraftedItem);
    34.             c.Effect = row[17];
    35.             int.TryParse(row[18], out c.ToHit);
    36.             int.TryParse(row[19], out c.ToKill);
    37.             int.TryParse(row[20], out c.Loud);
    38.             int.TryParse(row[21], out c.Melee);
    39.             int.TryParse(row[22], out c.Noticeability);
    40.             c.Trigger = row[23];
    41.  
    42.             //here is where I want the image to go. I can't convert string to texture.
    43.             row[24] = GetComponent<LoadMainImage>().Food_And_Water.gameObject;
    44.  
    45.             Cards.Add(c);
    46.         }
    47. }

    All of this data gets saved here below which I can refer to whenever with these ID numbers and is running smoothly.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Card
    6. {
    7.     public int CardBranchId;
    8.     public int CardLeafId;
    9.     public int CardId;
    10.     public string Item;
    11.     public string Description;
    12.     public int AntimatterRecipe;
    13.     public int R1Ingredient1;
    14.     public int R1Ingredient2;
    15.     public int R1Ingredient3;
    16.     public int R1CraftedItem;
    17.     public int R2Ingredient1;
    18.     public int R2Ingredient2;
    19.     public int R2Ingredient3;
    20.     public int R2CraftedItem;
    21.     public int R3Ingredient1;
    22.     public int R3Ingredient2;
    23.     public int R3Ingredient3;
    24.     public int R3CraftedItem;
    25.     public string Effect;
    26.     public int ToHit;
    27.     public int ToKill;
    28.     public int Loud;
    29.     public int Melee;
    30.     public int Noticeability;
    31.     public string Trigger;
    32.     public Texture Image;
    33. }
    How can I add an image to each card at "public Texture Image"? Should I create another script and put all of the images there for the script to refer to? And if so how do I get a texture in the list.
    HELP ME INTERNET, YOU'RE MY ONLY HOPE.
     
    Last edited: May 5, 2018
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    Use code tags, it's your only hope!