CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
CRI Mana component

CriManaMovieController

The "CriManaMovieController component" is used to control movie playback in CRI Sofdec.
In the Inspector, you can set the movie playback parameters for the CriWare.CriManaMovieController component.
For details about its parameters, please see the CriWare.CriManaMovieController .
Simple usage is shown below:
sfd2u_inspector_moviecontroller.png
Enter the name of a movie file from the Inspector in Unity Editor.
Note that only file name should be specified (without directory name), e.g., sample_256x256.usm. Then place the movie file in the StreamingAssets folder.

Using a custom shader

The CriManaMovieController can change the shader used for the movie playback. Use the CriManaMovieController.player.SetShaderDispatchCallback method to change the shader.
By using this method, a callback function for the shader allocation can be registered.
For example, attaching the following class to the object to which the CriManaMovieController component has been assigned is easy.
public class AttacheUserCustomShader : MonoBehaviour {
void OnEnable () {
CriManaMovieController controller = GetComponent<CriManaMovieController>();
controller.player.SetShaderDispatchCallback(ShaderDispatch);
}
// Function with two parameters (movieInfo and additiveMode) that returns a shader
static UnityEngine.Shader ShaderDispatch(MovieInfo movieInfo, bool additiveMode)
{
// Here, the shader is determined by the movieInfo and the additiveMode.
// Normally, the shader is determined by the movieInfo.codecType, the movieInfo.hasAlpha and the additiveMode.
// In this example, only the movieInfo.codecType and the additiveMode are referenced, and
// the custom shader for Sofdec.Prime codec is returned.
// Please see the related information if needed.
if (movieInfo.codecType != CodecType.SofdecPrime) {
Debug.LogError("Unknonw codec type");
return Shader.Find("VertexLit");
}
return Shader.Find(additiveMode ? "name of the shader used in additive blending" : "name of the shader not used in additive blending");
}
}
Please note that the registration must be done before playing the movie.
Creating a custom shader
Usethe ShaderLab language to describe a custom shader.
Default shaders can be found at the location below. Use them as a reference to create a custom shader.
For more information about the ShaderLab language, please see the Unity reference manual.
Location of the default shaders
  * Root

  \ * Assets

    \ * CRIMW

      \ * CriWare

        \ * Runtime

          \ * Scripts

            \ * CriMana

              \ * Resources

                \ * CriMana

                  o * SofdecPrimeRgb

                  o * *SofdecPrimeRgb.shader

                  o * SofdecPrimeYuv

                  \ * *SofdecPrimeYuv.shader

of the Unity project

 

 

 

 

 

 

 

 

 

: Shader for rendering RGB textures

 

: Shader for color conversion and rendering in RGB

 

CriManaMovieControllerForUI

This component is used for playing movies via the Unity UI. The basic usage is the same as the CriManaMovieController's, and the CriManaMovieControllerForUI.target doesn't receive the UnityEngine.Renderer but UnityEngine.UI.Graphic .

Attention when Destroying this Component

When Destroy is called on this component, a stop function is called internally. This function waits until the state’s transition is complete, and also supports the discarding during playback.
Note that if the destruction is performed while rendering the textures, an unexpected issue may occur depending on the timing.
Therefore, in order to destroy the component, we recommend to explicitly stop the playback, and to waiting until the state’s transition is complete to destroy the component.

Migration from the CriManaPlayer to the CriManaMovieController

This section explains notes about migration from the CriManaPlayer to the CriManaMovieController.

Migration in Unity Editor

  • Show the object to which the CriManaPlayer has been attached in the Inspector.
  • Remove the CriManaPlayer component.
  • Attach the CriManaMovieController component.

The CriManaMovieController component doesn't have the following properties of the CriManaPlayer component:

  • Flip Top/Bottom
  • Flip Top/Bottom
  • Volume

The Flip property can be replaced on a program by using the SetTextureOffset method of the Material class in Unity API.
The Volume property can be replaced with the SetVolume method of the CriMana.Player class.

Migration on script

Replace the CriManaPlayer component with the CriManaMovieController component.
The correspondence relationship of basic members in the methods and the properties are shown below:

Relationship between CriManaPlayer and CriManaMovieController
CriManaPlayer CriManaMovieController
SetFile player.SetFile
Play player.Start
Stop player.Stop
status player.status

An example of script replacement is shown below.
Please use it for your reference.

  • CriManaPlayer (before replacement)
    public GameObject movieObject;
    private CriManaPlayer moviePlayer;
    /* Binder handle */
    private CriFsBinder binder;
    /* Perform the AddComponent of CriManaPlayer to movieObject. */
    moviePlayer = movieObject.AddComponent<CriManaPlayer>();
    /* Set the binder and the file name. */
    moviePlayer.SetFile(binder, "sample.usm");
    /* Start a playback. */
    moviePlayer.Play();
  • CriManaMovieController (after replacement)
    public GameObject movieObject;
    private CriManaMovieController moviePlayer;
    /* Binder handle */
    private CriFsBinder binder;
    /* Perform the AddComponent of CriManaPlayer to movieObject. */
    moviePlayer = movieObject.AddComponent<CriManaMovieController>();
    moviePlayer.useOriginalMaterial = true;
    /* Set the binder and the file name. */
    moviePlayer.player.SetFile(binder, "sample.usm");
    /* Start a playback. */
    moviePlayer.player.Start();