| ミドルウェア | CRI ADX2 (CRI Atom) |
| サンプル | Scriptサンプル:シーンを越えるサウンド制御 |
| 格納場所 | /cri/unity/samples/UnityProject/Assets/Scenes/criatom/script/ScriptSample03_OverSceneSound/Scenes |
| シーンファイル | ScriptSample03_TitleScene.unity ScriptSample03_GameScene.unity |
| ADX2データのオリジナル | データ:音楽の簡易クロスフェード |
using UnityEngine; using System.Collections; using System.Collections.Generic; public class ScriptSample03_SoundManager : MonoBehaviour { /* ACB file name (CueSheet name) */ public string cueSheetName = "CueSheet_0"; private CriAtomSource atomSourceMusic; static private ScriptSample03_SoundManager instance = null; void Awake () { if (instance != null) { GameObject.Destroy(this); return; } /* Create the CriAtomSource for BGM. */ atomSourceMusic = gameObject.AddComponent<CriAtomSource> (); atomSourceMusic.cueSheet = cueSheetName; /* Do not destroy the SoundManger when scenes are switched. */ GameObject.DontDestroyOnLoad(this.gameObject); instance = this; } static public void PlayCueId(int cueId){ instance.atomSourceMusic.Play(cueId); } void OnDestroy(){ if (instance == this) { instance = null; } } }
using UnityEngine; using System.Collections; public class ScriptSample03_TitleScene : MonoBehaviour { private int SceneMusicCueId = 1; private string nextSceneName = "ScriptSample03_GameScene"; /* Called before the first Update(). */ void Start () { /* Play BGM. */ ScriptSample03_SoundManager.PlayCueId(SceneMusicCueId); } /* Show and control the scene-switching GUI. */ void OnGUI(){ if (Scene_00_SampleList.ShowList == true) { return; } /* Set UI skin. */ GUI.skin = Scene_00_SampleList.uiSkin; Scene_00_GUI.BeginGui("01/SampleMain"); if (Scene_00_GUI.Button(new Rect(Screen.width-250,200,150,150), "change\nscene")) { Application.LoadLevel(nextSceneName); } Scene_00_GUI.EndGui(); } }