CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
Loading a regular file

Data flow

Like any normal file system, FileMajik PRO can access individual files that are not packed.

crifs2_tutor01_dataflow_small.png

Overview of loading a file

When a file is loaded, a loader object is automatically created to load it.
The same API can be used, not only to load local files, but also files stored on a remote server.

fmpu_keys_fileload_file_system_mini.png

Process flow

A coroutine is used to load a file.
The yield statement is used to wait for the completion of the loading operation.
When using the CriWare.CriFsUtility.LoadFile function to load a file, you can specify the path like this:
  • Loading a local file
    CriFsLoadFileRequest request = CriFsUtility.LoadFile("StreamingAssets/sample_text.txt");

  • Loading an image file from a remote server
    CriFsLoadFileRequest request = CriFsUtility.LoadFile("http://crimot.com/sdk/sampledata/crifilesystem/sample_image2.png");
A file loading request is issued and the file is loaded asynchronously in the background.
The yield statement waits for the completion of the loading.
If the error returned is null, the file was loaded successfully.
As an example, the following code shows the processing of a text file which was loaded.

yield return request.WaitForDone(this);
if (request.error == null) { // The file is loaded successfully
// Obtain a buffer from the request object and process the data
Encoding enc = Encoding.GetEncoding("utf-8");
this.loadedText = enc.GetString(request.bytes);
}

[Note]
For the actual code, see the " [CriFs] Loading a file " sample.