CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
[CriAtom] Background loading

Sample description

Overview

cri4u_samples_criatom_adv01_game_mini.png

This sample plays BGM while loading a file in the background.

How to use

  • [Playback Streaming BGM] button
    Starts the streaming playback of the BGM.

  • [Load Image File (Local)] button
    Loads and displays a local image file.

  • [Delete Images] button
    Deletes all the displayed image files.

Scene information


Middleware CRI ADX (CRI Atom)
Sample Advanced samples
Location /CRIWARE/SDK/unity/samples/UnityProject/Assets/Scenes/criatom/advanced/
Scene file Scene_01_BackgroundLoadData.unity


Description of the program

Loading an image file

CriFsUtility is used to load an image file without stopping the sound.
By using the CRI File System, the flow of data is properly managed, resulting in playback with no sound or movie interruption,
even if, for example, the streaming load fluctuates when playing audio (with CRI Atom) or movies (with CRI Mana) during the game.
(Note) Even if the available bandwidth is very low, no time management for the movie playback is lost.

/* Load an image file */
private IEnumerator LoadImageFile(string path, int request_index)
{
lockLoadImageFile++;
/* Request to load a file */
var request = CriFsUtility.LoadFile(path);
/* Wait until the loading is complete */
yield return request.WaitForDone(this);
lockLoadImageFile--;
if (request.error == null) {
/* If the loading has been successful, create a texture from a byte string */
this.textures[request_index] = new Texture2D(0, 0);
this.textures[request_index].LoadImage(request.bytes);
} else {
Debug.LogWarning("Failed to load image file.");
}
}
...
if (GUI.Button(new Rect(Screen.width - 280, 90, 240, 40), "Load Image File (Local)")) {
/* Set the path to the local image file */
dir = CriWare.streamingAssetsPath;
/* Remember that the GUI button for loading an image file was clicked */
requestLoadImage = true;
}
...
if (requestLoadImage) {
/* If a request to load an image file is received, load the file */
/* This sample loads multiple times to increase the workload of the I/O. */
int i = 0;
StartCoroutine(this.LoadImageFile(Path.Combine(dir, "criware.png"), i++));
StartCoroutine(this.LoadImageFile(Path.Combine(dir, "sample_image1.png"), i++));
StartCoroutine(this.LoadImageFile(Path.Combine(dir, "sample_image2.png"), i++));
}