LoginSignup
2
3

More than 5 years have passed since last update.

UnityでADX2 LE用のSoundManagerを作成してみた

Last updated at Posted at 2016-08-12

ADX2 LEの音関係の管理はSoundManagerを作った方がやりやすいというものを見たため、作成してみた。

環境

・Windows 10
・Unity 5.4.0f3

SoundManager

SoundManager.cs
using UnityEngine;
using System.Collections;

public class SoundManager : MonoBehaviour {
    private string SESheetName = "CueSheet_0"; //SE用キューシート
    private string BGMSheetName = "CueSheet_1"; //BGM用キューシート
    private CriAtomSource atomSourceSE;
    private CriAtomSource atomSourceBGM;

    void Start () { //初期化
        atomSourceSE = gameObject.AddComponent<CriAtomSource>();
        atomSourceBGM = gameObject.AddComponent<CriAtomSource>();
        atomSourceSE.cueSheet = SESheetName;
        atomSourceBGM.cueSheet = BGMSheetName;
    }

    public void PlaySE(string cueName) { //SEを再生(引数:SE名)
        atomSourceSE.androidUseLowLatencyVoicePool = true; //Android用遅延対策
        atomSourceSE.Play(cueName);
    }

    public void PlayBGM(string cueName) { //BGMを再生(引数:BGM名)
        atomSourceBGM.Play(cueName);
    }

    public void StopBGM() { //BGMを停止
        atomSourceBGM.Stop();
    }

    public void PauseBGM() { //BGMを一時停止(ポーズ)
        atomSourceBGM.Pause(true);
    }

    public void ResumeBGM() { //BGMを再開
        atomSourceBGM.Pause(false);
    }

    public long GetBGMTime() { //BGMの再生時間を取得
        return atomSourceBGM.time;
    }

}

とりあえず、今使うものだけを羅列。
キューシート名や、その役割は作る人によって異なる。

使ってみる

音を使うオブジェクトに、SoundManager.csをアタッチ。
他のスクリプトから呼び出すときは、

hogehoge.cs
    private SoundManager sm;

    void Start() {
        sm = gameObject.GetComponent<SoundManager>();
        sm.PlayBGM("sample"); // カッコ内は曲名
    }

といった感じで使う。(ここでは、Start()内でBGMとしてsampleを流す)

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3