Game Development Reference
In-Depth Information
The following are the comments for code sample 6-24:
Line 04 : The member variable Search defines a regular expression
search pattern. The Search variable, in this case, is for all words prefixed
with female: . More than this, however, the prefix itself should not be
included in the resultant strings.
Line 07 : The member variable CSVData defines a complete CSV string with
both male and female names that are structured in the expected format.
This string essentially represents the database or data source.
Lines 10-11 : Here, Linq is used in conjunction with a regular expression
search to retrieve all female names from the CSV, minus the prefixes.
This list is then converted into a string array FemaleNames .
Strings and the @ symbol
Notice from line 04 of the code sample 6-24 that the regular expression
string is prefixed with the symbol @ . This is a C# convention that allows
you to write a string literal in a source file; this string literal can contain
escape sequences (such as \ ) without breaking or invalidating the
string itself.
Working with Text Data Assets
Throughout all examples so far, we've considered text directly stored in string
objects, but you can also work with text files in Unity. Specifically, you can load
in text from external sources. Here, I will demonstrate how.
Text Assets - static loading
The first method is to drag-and-drop a text file into a Unity project that imports
the text asset. The file is imported as a TextAssets type, as shown here:
 
Search WWH ::




Custom Search