CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
Simple sound test

Description of the sample

Overview

This sample script displays a button for each Cue in the CueSheet file (ACB file). By clicking on a button, the corresponding Cue can be played.
This script can be used as a simple sound test.

cri4u_samples_criatom_script02_main.png

Operations

  • Click a button with a Cue name to the right of the screen.
    The sound of the clicked button is played. If another sound is being played, it is stopped and the sound of the clicked button is played.

Scene information


Middleware CRI ADX (CRI Atom)
Sample Script sample: Simple sound test
Location /CRIWARE/SDK/unity/samples/UnityProject/Assets/Scenes/criatom/script/ScriptSample02_SoundTest
Scene file ScriptSample02_scene_SoundTest.unity
Original ADX data Data: Pinball


Description of the program

This project contains only an empty object to which the SoundTest.cs script is added.
When the program is executed, SoundTest.cs obtains the list of Cues (sounds) from the CueSheet (ACB file) and displays them as buttons.
It can be used as a simple sound test feature because the sounds from the CueSheet can be played quickly from the list.

Description of the sound test script

The Start function obtains a list of Cues from the CueSheet and stores them in an array.
The name of the CueSheet is described in the script.
The OnGUI function displays each Cue name from the Cue list as a button.
When one of the buttons is clicked, any playback still in progress is stopped, and the Cue corresponding to the button is played.

Script file Scripts/SoundTest.cs
using System.Collections;
using System.Collections.Generic; // for an array
public class SoundTest : MonoBehaviour {
private List<string> cueNameList = new List<string> ();
private string cueSheetName = "PinballMain"; // CueSheet name
CriAtomSource atomSourceSe;
void Awake ()
{
}
CriAtomEx.CueInfo[] cueInfoList;
void Start ()
{
atomSourceSe = gameObject.AddComponent<CriAtomSource> ();
atomSourceSe.cueSheet = cueSheetName;
CriAtomExAcb acb = CriAtom.GetAcb (cueSheetName);
cueInfoList = acb.GetCueInfoList ();
foreach (CriAtomEx.CueInfo cueInfo in cueInfoList) {
cueNameList.Add (cueInfo.name);
}
CriAtomEx.AttachDspBusSetting("DspBusSetting_0");
CriAtom.SetBusAnalyzer(true); // Enable the level meter
}
public bool soundDebug = true;
void OnGUI()
{
if (Scene_00_SampleList.ShowList == true) {
return;
}
Scene_00_GUI.BeginGui("01/SampleMain");
/* Set UI skin. */
GUI.skin = Scene_00_SampleList.uiSkin;
if(soundDebug){
GUILayout.BeginArea(new Rect(Screen.width - 150, 0, 150, 300));
foreach (CriAtomEx.CueInfo cueInfo in cueInfoList) {
if(Scene_00_GUI.Button(cueInfo.name)){
atomSourceSe.Stop();
atomSourceSe.Play(cueInfo.name);
}
}
GUILayout.EndArea();
}
Scene_00_GUI.EndGui();
}
}

Features and extension of the SoundTest script

Since simple implementation was more important, this sample script lacks some features to be considered as an actual sound testing script.
For example, if there are too many Cues, buttons may not fit on the screen.
The script cannot play sound effects over music because it has no feature to play multiple Cues at the same time.
Try improving the script: it is easy by just making a few small incremental changes.

Note: Registering the ACF and ACB files (1)

You must register the ACF and ACB files with the Unity project before you can run this sample script.
As a simple way to register an ACF or ACB, select a cue from the relevant Cue Sheet in the Atom Browser window , and create a game object by pressing "CreateObject".
A game object with a CriAtomSource will be generated, but you can delete it immediately.
Check the object named CRIWARE that was created at the same time with the Inspector,
and you will notice that the registration of the ACF and ACB files is complete.

cri4u_samples_criatom_script02_criware.png

Note: Registering the ACF and ACB files (2)

To register an ACF/ACB without using Atom Browser window , follow the procedure below to create and set up an object.
  1. Create a CRIWARE Library Initializer and a CRIWARE Error Handler from the CRIWARE menu of the Unity Editor.
  2. Create a GameObject.
  3. In the Hierarchy window, select the GameObject created in Step 2, then select CRIWARE->CRI Atom from the Component menu.

    cri4u_samples_criatom_script02_component_atom.png

  4. The CRI Atom component is added to the new GameObject in the Inspector.
  5. In the Inspector, type the name of the ACF file located in StreamingAssets in the "ACF File" field of the CRI Atom component.

    cri4u_samples_criatom_script02_acf.png

  6. In the Inspector, press the "Add CueSheet" button on the CRI Atom component and enter the following information.
    See CRI Atom for a detailed description of the parameters.
  • "Name": the name of the Cue Sheet
  • "ACB File": the name of the ACB file located in StreamingAssets
  • "AWB File": the name of the AWB file located in StreamingAssets (if it exists)
    cri4u_samples_criatom_script02_criware.png

    Now the setup of the ACF and ACB is completed.
    Add SoundTest.cs to an appropriate GameObject and run it to see the cue list.