CRIWARE Unity Plugin Manual  Last Updated: 2024-07-12
[CriAtom] In-game preview (pinball demo)

Description of the sample

Overview

cri4u_samples_criatom_scene07_game_mini.png

Demo of the in-game preview in CRI ADX.
It is a pinball game demo.
You can change the background music and the sound effects in Setting.

In-game preview

From Unity Editor, you can connect to an in-game preview from CRI Atom Craft to check the number of sounds playing.
You can also change the location and parameters of the playback.
Although re-sending the data is required if its size is changed by an edit, you can also replace a waveform (up to the in-game padding size).
For more details about the in-game preview, also see " In-game preview ".

Data for an in-game preview

If you want to build the ACF and ACB again, make sure to select the in-game preview option and copy the files to Asset.

Note
ACF and ACB files that were not specifically built for an in-game preview will not work with tools via the in-game connection.
You can only establish a connection with a CRI Atom Craft project for which the ACF and ACB files were built using the in-game preview option.

Central control of sounds

CriAtomSource components are pasted in the editor. The number of operations required to play a sound can make the process cumbersome when there are many sound assets.
Therefore, this sample encapsulates the playback functions into a programmer-friendly call.
Example: PlayBGM() ... Play background music

Dynamic change of sounds

You can change the background music and the sound effects in Setting.
You can change sounds dynamically because playback is also performed indirectly.
For example, click on Setting on the screen to change the sound effects and the background music.

Advantage of the sound system wrapper

By hiding the sound system, it is possible to correct/improve the sounds with only minimal changes in the script.

[Example]
You can switch to Unity's standard sound system.
(This sample does not include Unity's standard playback process.)

Procedure for in-game preview

  • (1) Start "CRI Atom Craft".
  • (2) From the File - Open project menu, open the following project file:
    • [CRI Atom Craft app folder]/example/pinball/Pinball.atmcproj
  • (3) Set the IP address of the PC that will run the sample.
    • (3-1) From the Tools -> Properties menu, call the Properties dialog box.
    • (3-2) In the Properties dialog box, select Target -> the PC tab.
    • (3-3) In Preview setting -> IP address, set the IP address of the PC that will run the sample.
  • (4) Press the F10 key to start the in-game preview.

    Note
    For more details about the in-game preview, see " In-game preview ".

Scene information


Middleware CRI ADX (CRI Atom) Remarks
Sample Basic sample
Location /CRIWARE/SDK/unity/samples/UnityProject/Assets/Scenes/criatom/basic/
Scene file Scene_07_Ingame_Pinball.unity
Script file Scene_07_Ingame_Pinball_PlayBounce.cs This script plays a sound when a physical collision is detected.
It calls a function in SoundManager.
Script file Scene_07_Ingame_Pinball_SoundManager.cs This script manages sound handling.
ACF file Pinball.acf
ACB file PinballMain.acb


Description of the program

One project manages the sound assets

It is recommended that one Unity project uses one CRI Atom Craft project.
Some extra configuration is required when a title uses multiple CRI Atom Craft projects.

This sample uses the ACF and ACB files (Pinball.acf and PinballMain.acb), which were built for an in-game in CRI Atom Craft.
It is using a different CRI Atom Craft project than the other samples.
(The other samples share DemoProj.acf and DemoProj.acb .)
It is also true when you want to replace both ACF and ACB by downloaded contents, for example.

The [SoundManager] object

It sets the CriAtom component that manages the ACF and ACB files.

The CriAtomSource component that manages sound playback is created in the Awake() function of the script.
By calling the PlayBounce() function, initialization (application of the category volume, configuration of the DSP bus, and playback of the background music) is performed.
This is called when the sizes of the ACF and ACB files were changed by an edit during the in-game connection and thus binaries must be updated, but you want to make sure that the music continues to play.
(* In future versions, we plan to provide appropriate callbacks, such as update events during the in-game preview.)

Obtaining ACB information from the script

This sample uses the script to obtain information on the ACB, while other samples use CriAtomProjInfo_Unity.cs (Unity information file) to do it.
The CriAtomProjInfo_Unity.cs file outputs information about one CRI Atom Craft project. It cannot have information about multiple projects.
(* There must be a one-to-one correspondence with the AtomCraft tool.)

Although this sample only retrieves the cue names, more information is available. Use the Awake() function to do it.

/* Get the Cue info by specifying the ACB file name (CueSheet name). */
CriAtomExAcb acb = CriAtom.GetAcb(cueSheetName);
/* Create a list of Cue names. */
CriAtomEx.CueInfo[] cueInfoList = acb.GetCueInfoList();
foreach(CriAtomEx.CueInfo cueInfo in cueInfoList){
cueNameList.Add(cueInfo.name);
}

Creating a CriAtomSource

This sample creates an CriAtomSource component from the script, while other samples specify it when it is generated in Unity Editor.

In Unity Editor, the necessary CriAtom component (CRIWARE object) is automatically created.
But when using a script, it is not automatically created. Therefore, you must add the CriAtom component and configure ACF and ACB in Unity Editor.
(* In future versions, we plan to provide a method to create the CriAtom component from a script.)

/* AtomSource for bouncing sound */
private CriAtomSource atomSourceBounce = null;
/* AtomSource for BGM */
private CriAtomSource atomSourceBGM = null;
...
/* Create the CriAtomSource for bouncing sound. */
atomSourceBounce = gameObject.AddComponent<CriAtomSource>();
atomSourceBounce.cueSheet = cueSheetName;
atomSourceBounce.cueName = cueNameList[(int)enumCueNameList.wood + seNo];
/* Create the CriAtomSource for BGM. */
atomSourceBGM = gameObject.AddComponent<CriAtomSource>();
atomSourceBGM.cueSheet = cueSheetName;
atomSourceBGM.cueName = cueNameList[(int)enumCueNameList.bgm0 + bgmNo];

Playing a CriAtomSource

The sound is played by calling the PlayBounce() function.
You can call it externally because it is a public function.
In this sample, it is called from Scene_07_Ingame_Pinball_PlayBounce.

[Source:Scene_07_Ingame_Pinball_SoundManager.cs]
/* Bouncing sound */
public void PlayBounce()
{
/* Specify a Cue name. */
atomSourceBounce.cueName = cueNameList[(int)enumCueNameList.wood + seNo];
/* Play */
atomSourceBounce.Play();
}

[Suorce:Scene_07_Ingame_Pinball_PlayBounce.cs]
#region Variables
private Scene_07_Ingame_Pinball_SoundManager soundManager = null;
#endregion
#region Functions
void Start()
{
/* Get the SoundManager. */
soundManager = FindObjectOfType(typeof(Scene_07_Ingame_Pinball_SoundManager)) as Scene_07_Ingame_Pinball_SoundManager;
}
/* Play at collision. */
void OnTriggerEnter(Collider other)
{
/* Play at collision hit. */
soundManager.PlayBounce();
/* If BGM is stopped, restore it. */
soundManager.ResumeBGM();
}
#endregion

Replacing the ACF and ACB files during in-game preview

If the ACF or ACB files are changed during the in-game preview, the sound that is being played is stopped, and the category volume is reset.
The background music must be resumed after it was stopped and this sample shows what must be done again in the application for that to happen.
It also updates the DSP bus setting and the flag to monitor the levels in the tool during in-game preview.

public void ResumeBGM()
{
/* Play when in the PLAYEND or in the STOP. */
/* (Automatically restore at the time of ACB update) */
CriAtomSource.Status status = atomSourceBGM.status;
if ((status == CriAtomSource.Status.Stop) || (status == CriAtomSource.Status.PlayEnd)) {
/* Play */
PlayBGM(); /* Change the volume of category [main]. */
CriAtom.SetCategoryVolume("main", mainVolume);
/* Add the feature of level monitor for in-game preview. */
CriAtom.SetBusAnalyzer(true);
}
}