public void DrawCards()
{
int counter = 0;
string line;
char delimiter = ',';
DataTest asset = ScriptableObject.CreateInstance<DataTest>();
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader(@"C:\Users\Jason\OneDrive\Documents\Test1\Assets\ListOne.txt");
while ((line = file.ReadLine()) != null)
{
string[] substrings = line.Split(delimiter);
//if(counter != 0) { AssetDatabase.RenameAsset("Assets/" + asset.cardName + ".asset", substrings[1]); }
asset.deckName = substrings[0];
asset.cardName = substrings[1];
asset.cardEffectsDesc = substrings[2];
asset.cardHealth = Convert.ToInt32(substrings[3]);
asset.cardType = substrings[4];
asset.cardCost = Convert.ToInt32(substrings[5]);
asset.cardDescription = substrings[6];
asset.cardAttack = Convert.ToInt32(substrings[7]);
AssetDatabase.CreateAsset(asset, "Assets/" + substrings[1] + ".asset");
AssetDatabase.SaveAssets();
counter++;
}
file.Close();
Debug.Log("There were {0} lines." + counter);
// Suspend the screen.
System.Console.ReadLine();
}
This is my code for creating multiple assets, however, whenever the script gets to “AssetDatabase.CreateAsset(asset, “Assets/” + substrings[1] + “.asset”);” the second time through it breaks giving these two errors : http://imgur.com/a/sLtIN
Here are the first 3 lines from the text file :
Shauren,Draconian scouts,Gain +2/+1 when there’s a Dragon Commander or Emperor Dragon is on your side of the field,1,Minion,1,(None),1
Neutral,SaiMoh Guardian,(None),8,(None),6,“”“She guards the sacred mountain with the pigments in the breeze”“”,5
Shauren,Heralded Egg,“After this card has been on your side of field for 3 turns, add 1 draconian scouts from the deck to hand.”,5,Minion,2,(None),0
I’ve tried mixing the CreateAsset and SaveAsset around all in the loop but I still can’t seem to make it work