Skip to content

Instantly share code, notes, and snippets.

@tatmos
Created August 7, 2013 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatmos/6179196 to your computer and use it in GitHub Desktop.
Save tatmos/6179196 to your computer and use it in GitHub Desktop.
Unity x ADX2LE 【効能】アプリケーションのフォーカスが外れたり復帰時に、自動的にサウンドのポーズやポーズ解除します。 【使いどころ】バックグラウンドで音が進行してしまうと都合が悪い時に使う。 【使い方】AtomSourceのついたオブジェクトに貼付ける。
using UnityEngine;
using System.Collections;
public class BackgroundStop : MonoBehaviour {
CriAtomSource atomSource;
// Use this for initialization
void Start () {
atomSource = gameObject.GetComponent<CriAtomSource>();
}
// Update is called once per frame
void Update () {
}
void OnApplicationPause(bool pause)
{
if(atomSource != null){
atomSource.Pause(pause);
}
}
void OnApplicationFocus(bool focusFlag)
{
if(atomSource != null){
atomSource.Pause(!focusFlag);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment