0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Unity】効果音を簡単に再生できる SEManager と SEClip の紹介

Last updated at Posted at 2021-09-28

SEManager v2 を作りました

v2 の方がシンプルかつ柔軟に実装できます。
https://qiita.com/Yamara/items/91f19eef6297d9c8fc87

⚙️SEManager

SEManager は、AudioSource を意識しないで効果音を再生できる便利なパッケージです。
SEManager をプロジェクトに導入し、下記のようなコードを書くだけで、効果音を再生できます。
SEManager のリポジトリはこちら

サンプルコード.cs
[SerializeField] AudioClip clip;

// 再生
clip.Play();
// 音量,優先度を設定して遅延再生
clip.Play(1f, 127, 0.5f);
// 複数の効果音,音量,ピッチ,ピッチのブレ幅,優先度を設定して再生
new SEClip(clips, 0.5f, 1f, 0.1f, 127).Play();

🧮関数

関数名 説明
audioClip.Play()
audioClip.Play(float volume, byte priority, float delay)
seClip.Play()
seClip.Play(float delay)
再生
seClip.Play(AudioSource audioSource)
seClip.Play(AudioSource audioSource, float delay)
AudioSourceを指定して再生
SEManager.Stop() 全ての効果音を停止
SEManager.Pause() 全ての効果音の一時停止
SEManager.UnPause() 全ての効果音の一時停止解除
SEManager.VolumeToDecibel(float volume) 値(範囲:0~1)をデシベル(範囲:-80~0)に変換
SEManager.DecibelToVolume(float decibel) デシベル(範囲:-80~0)を値(範囲:0~1)に変換

📝備考

SEの再生に使用するAudioMixerGroupと最大同時再生数の設定は SEManager / Resources / SEManagerSettings.asset から行えます。

💿SEClip

SEClip は、効果音を単調にしないための ScriptableObject です。複数の AudioClip とピッチのブレ幅を設定して再生すると、ランダムな AudioClip とピッチで効果音が鳴ります。これにより、銃弾や足音などにバリエーションを持たせられます。再生は SEManager 上で、AudioClip と同じように行えます。

変数 説明
clips 複数のAudioClip
priority 優先度
volume 音量
pitch ピッチ
pitchRange ピッチのブレ幅

🧰便利コンポーネント

パッケージには、SEManager や SEClip に関する便利なコンポーネントが含まれています。unitypackage で圧縮しているので利用する際は展開してください。

コンポーネント名 説明
SEVolumeSlider Slider と AudioMixer と EventTrigger を指定して、効果音の音量調整スライダーを作成できます。サンプルは SEManager / Prefabs / SEVolumeSlider.prefab にあります。
SEClipPlayer SEClip を再生
SEClipPlayerForAudioSource AudioSource を指定して SEClip を再生
SEPlayer インスペクタ上で SEClip を設定して再生
SEPlayerForAudioSource インスペクタ上で SEClip を設定し、AudioSource を指定して再生
AudioClipLoader Preload Audio Data と Load in BackGround が無効になっている AudioClip を読み込み
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?