Game Development Reference
In-Depth Information
Debug.Log (TextData.text);
}
}
//--------------------------------------------------
This code means you just need to drag-and-drop the TextAsset file onto the Text
Data slot in the Object Inspector, as shown here:
Accessing text file assets from script
Text Assets - loading from the local files
Another method to load in text data is externally from the project, that is, from
files on the local hard drive. Text Data loaded in this way is read into the project
dynamically from script, not necessarily at scene startup, but whenever you
execute the necessary code. This means that for longer text files that involve heavy
processing, lag becomes a serious consideration. In general, therefore, it is best
to prefer statically loaded Text Assets to dynamic forms. For any dynamic assets,
I recommend that you load and process them at scene startup to avoid in-game
lagging, as shown in the following code sample 6-26:
using UnityEngine;
using System.Collections;
using System.IO;
//Function to load text data from external file
public static string LoadTextFromFile(string Filename)
{
//If file does not exist on system, then return empty string
if(!File.Exists(Filename)) return string.Empty;
 
Search WWH ::




Custom Search