CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
[CriFs] Directory binding

Description of the sample

Overview

cri4u_samples_crifs_scene05_game_mini.png
This sample uses the directory binding feature.
The directory binding feature binds the files under a specific directory. When the directory is bound, no files are opened. Files are opened and file sizes are obtained only when they are accessed, for example to load them.
This process is much more inefficient than using a CPK file, where files can be opened and file sizes can be obtained beforehand.
This is why it is recommended that you pack files in the more efficient CPK files before releasing an application. However, using directory binding can be used during development.
In this sample, directories in different hierarchies under StreamingAssets are multi-bound. Here we assume that data files prepared in the early stages of development are placed in StreamingAssets, and data updates are placed in another directory.
The data creator should put the latest file in a given directory, after which the game can update the data file without making any changes to itself.

How to use the sample

  • Step1: Bind Directory
    • Bind Base Directory button
      Bind the base directory.

    • Bind Update Directory button
      Bind the directory where you want to place the update file.

    • Unbind Directory button
      Unbinds the directory.

  • Step2: Load File
    • Load Text File button
      Loads a text file from the directory.

    • Load Image File 1 button
      Loads and displays an image file in either directory.

    • Load Image File 2 button
      Loads and displays another image file in either directory.
  • Reset button
    Resets the settings.


Scene information


Middleware FileMajik PRO (CRI File System)
Sample Basic samples
Location /CRIWARE/SDK/unity/samples/UnityProject/Assets/Scenes/crifilesystem/basic/
Scene file Scene_05_BindDirectory.unity


Description of the program

/* Create a binder. */
this.binder = new CriFsBinder();

First, create a binder in the application.
Bind regular files, CPK files etc... to this binder.

/* Request a directory binding. */
/*
* Actually, the multi-binding of directory is performed.
* For details about multi-binding, please see Scene_04_MultiBind.
*/

Request the binding of the directory. Binding is executed asynchronously in the background.
Specify the target binder. Use the path of the directory to bind.

/* Wait for the completion of directory binding. */
yield return request.WaitForDone(this);
this.lockBindDirectoryButton = false;
if (request.error == null) {
/* If successful, store the binder ID on the application side. */
this.bindId[bind_index] = request.bindId;
:
:

Wait until the binding of the CPK file is complete.
If the error returned is null, the binding was successful.

/* If the binding was successful, store the binding ID in the application */
/* The binding ID will be used later for unbinding */
this.bindId[bind_index] = request.bindId;
/* Assign the search priority */
/* The larger the value, the higher the priority. */
/* In this sample, the CPK on the update file side is always searched before the base CPK. */
CriFsBinder.SetPriority(this.bindId[bind_index], bind_index);

If binding was successful, the application must remember the binding ID, which is a member of the "request" object.
Specify this binding ID and set the search priority with CriFsBinder.SetPriority().
This sample uses multi-binding to bind a local directory and a directory on a remote host.
For more about multi-binding, see [CriFs] Directory binding .

/* Issue a request for the file loading to the directory-bound binder. */
var request = CriFsUtility.LoadFile(this.binder, path);
/* Wait for the completion of loading. */
yield return request.WaitForDone(this);

When loading a file, specify the multi-bound binder.
The directories bound are searched in order of priority, and the file is loaded.
In this sample, because the target directory for the update file has high search priority set, if the file in this directory is updated, the application will load the file from here first.