hey there,
Does anyone know if unity can read in and categorize text from an external file?
thanks!
CPCP
hey there,
Does anyone know if unity can read in and categorize text from an external file?
thanks!
CPCP
Not sure what you mean by categorize but the answer is yes. Create a folder named Resources. You can than add a text file which will be a TextAsset. You can then easily load it up and access the .text property which is a string containing the text of the file.
That wouldn’t be an external file though; use the WWW class for external files.
–Eric
hey thats great. Thanks lots.
What i meant by categorize is to receive the text in groups ie
1.flowers ( group )
a. rose
b. iris
then
There is no “categorize this text for me” function. You’ll have to do the parsing yourself. I do have some code that I just finished which would actually make it a little easier. I was planning on posting it soon. Basically, given a text file that looks something like:
Student
{
name : Fred
age : 20
GPA : 2.4
}
it would instantiate a Student object and set the fields appropriately and all dynamically. Without changing the code, you could create another class and then add that data to the text file and it would work. The corresponding class above would be:
public class Student : IAction
{
public string name;
public int age;
public float GPA;
etc…
}
When I post it on the wiki, it’ll probably make more sense. My chaining these together, I’ve created an Action system. My Unity scene never changes, so by creating this dynamic actions I can create a logical game progression.
In your case, you would be able to easily adapt it to do what you want (I think).
this is great.
i will try it out asap.
thanks again.
would it be much easier to do things like this if unity read in xml?
thanks again,
cp
The only reason XML would have been nicer is that I wouldn’t have to manually parse that file.
Also, not sure if I understand what you’re saying but you realize that to “try it out” you have to create a bit of code to read that file in and instantiate the object yourself. Unity doesn’t have any of that built in (externally at least but I’m willing to bet the editor does something similar in order to build up the property list for a behavior).