- Home /
Populating Dictionary at run-time from .txt file on imported asset bundle
I have created a software that will create a dictionary in C# structure for unity.....or any other format .
I came across a problem right away when trying to implement a similar method od creating a dictionary in unity.
if(GameObject.Find("ImportedBundle"))// This is the bundle that was imported and instantiated
{
string thetext;
thetext = GameObject.Find("ImportedBundle").GetComponent<txtFile>().text;
foreach(string line in thetext )
{
}
}
seeing as 'txtFile' or 'ImportedBundle' wont exist until the bungle is imported i end up getting an error which seems almost inevitable.
i wrote a code in .net which takes in lines of string like this
'hello this is my shoes_up_car_van_truck' 'hello who are you_aHand_pen_comb_fork'
and using this.net code
For Each line As String In Text1.Lines
For Each st As String In line.Split("_")
TextBox1.Text = ReplaceFirst(TextBox1.Text, "_", st)
Next st
Text2.Text += TextBox1.Text + _
Environment.NewLine
Next
I will get this result
dictionary.Add("hello this is my shoes", new string[] {"up", "car","van(A)","truck"});
dictionary.Add("hello who are you", new string[] {"aHand", "pen","comb","fork"});
i will get this result which works fine for C# .
but now I need to populate the dictionary directly from a .txt file at runtime from a instantiated asset bundle which has a .txt file attached to it
needless to say I NEED help . how can i get this to work ?
Defining new script classes in an AssetBundle is difficult (read: not quite impossible). In your case, it seems like it would be much easier to embed a TextAsset and work with the file's contents directly.