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

Description of the sample

Overview

cri4u_samples_crifs_scene04_game_mini.png
In this sample, multiple CPK files are bound to one binder. This is called multi-binding .
Difference between normal binding and multi-binding
Normally, when loading a file through the binder, the file will be searched for inside the bound CPK. In the case of multi-binding, it will be searched for across all the CPKs.
Examples of multi-binding
For example, by multi-binding a new CPK that includes only the differences of the old CPK instead of updating the old CPK entirely, operating cost can be reduced.
This sample uses two CPK files.
Here, one is regarded as the update pack (difference file) of the other. The base CPK file is packed with two character image files. Only one character image file is packed in the difference CPK file. This image file is assumed to be an "updated image file".
To be loaded from the update pack
To load the files, the updated CPK file (difference file) must be loaded first. Therefore, CriFsBinder.SetPriority() is used to set the priority of each CPK binding ID.
Like in this sample, by putting all the files required for the application in a local CPK, packing difference files in an updated CPK, and then performing multi-binding, the loading section of the application can use the same code to load both original files and updated files.
The updated CPK file only contains the new version of the "sample_image2.png" file. Therefore, when other files are accessed, they are loaded from the local CPK file.

Operations

  • Step1: Multi Bind CPK File
    • Bind Base CPK File button
      Binds the local Base CPK file.

    • Bind Update CPK File button
      Binds the local difference CPK file.

    • Unbind CPK File button
      Unbinds the CPK file.

  • Step2: Load File
    • Load Image File 1 button
      Loads the image file 1 from multi-bound CPK file.

    • Load Image File 2 button
      Loads the image file 2 from multi-bound CPK file.

  • 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_04_MultiBind.unity


Description of the program

this.binder = new CriFsBinder();

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

/* Request a CPK binding. */
/* Assign the content of the CPK to the specified binder handle. */
var request = CriFsUtility.BindCpk(this.binder, null, path);

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

/* Wait until binding is complete */
yield return request.WaitForDone(this);
if (request.error == null) {
:
:

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

/* If successful, store the binder ID on the application side. */
/* It is used for the release processing etc. */
this.bindId[bind_index] = request.bindId;
/* Assign the search priority.
/*
* The larger the value is , the higher the priority is.
* This sample always searches the updated CPK before the local CPK.
*/
CriFsBinder.SetPriority(this.bindId[bind_index], bind_index);

If binding was successful, the application must store the binding ID, which is a member of the "request" object.
Specify this binding ID and set the search priority with CriFsBinder.SetPriority().
By performing the binding multiple times for one binder, multi-binding is achieved.

/* Issue a request for the file loading to the CPK-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 CPK files bound are searched in order of priority, and the file is loaded.