예제 #1
0
        IEnumerator OnSoundPlayFinish(float delay, GameObject go, OnSoundEnd endCallback, object endParam)
        {
            yield return(new WaitForSeconds(delay));

            Stop(go);

            if (endCallback != null)
            {
                endCallback(endParam);
            }
        }
예제 #2
0
        public GameObject Play(string name, OnSoundEnd onEndCallback = null, object onEndParam = null)
        {
            SoundData dat;

            GameObject ret = null;

            if (mSfx.TryGetValue(name, out dat))
            {
                ret = GetAvailable();
                if (ret != null)
                {
                    ret.audio.clip   = dat.clip;
                    ret.audio.volume = dat.volume;
                    ret.audio.loop   = dat.loop;

                    SoundPlayer sp = ret.GetComponent <SoundPlayer>();
                    sp.playOnActive  = false;
                    sp.defaultVolume = dat.volume;
                    sp.playDelay     = dat.delay;

                    sp.Play();

                    SoundPlaying newPlay = new SoundPlaying()
                    {
                        data          = dat,
                        player        = sp,
                        startTime     = dat.realtime ? Time.realtimeSinceStartup : Time.time,
                        onEndCallback = onEndCallback,
                        onEndParam    = onEndParam
                    };

                    mSfxPlaying.Add(newPlay);

                    //   sp.StartCoroutine(OnSoundPlayFinish(dat.clip.length + dat.delay, ret, onEndCallback, onEndParam));

                    ret.SetActive(true);
                }

                /*else {
                 *  Debug.LogWarning("Ran out of available sound player for: " + name);
                 * }*/
            }
            else
            {
                Debug.LogWarning("sound player not found: " + name);
            }

            return(ret);
        }
예제 #3
0
        public AudioSource Play(string name, OnSoundEnd onEndCallback = null, object onEndParam = null)
        {
            SoundData dat;

            if (mDataLookup.TryGetValue(name, out dat))
            {
                return(Play(dat, onEndCallback, onEndParam));
            }
            else
            {
                Debug.LogWarning("Unknown sound: " + name);
            }

            return(null);
        }
예제 #4
0
        IEnumerator DoSoundPlay(SoundPlayer sp, OnSoundEnd endCallback, params object[] endParam)
        {
            sp.Play();

            while (sp.target.isPlaying)
            {
                yield return(null);
            }

            Stop(sp);

            if (endCallback != null)
            {
                endCallback(endParam);
            }
        }
예제 #5
0
        public SoundPlayer Play(string name, Vector3 position, OnSoundEnd onEndCallback = null, params object[] onEndParam)
        {
            SoundData dat;

            SoundPlayer ret = null;

            if (mSfx.TryGetValue(name, out dat))
            {
                ret = GetAvailable();
                if (ret != null)
                {
                    ret.transform.position = position;

                    ret.target.clip   = dat.clip;
                    ret.target.volume = dat.volume;
                    ret.target.loop   = dat.loop;

                    ret.defaultVolume = dat.volume;
                    ret.playDelay     = dat.delay;

                    if (ret.target.loop)
                    {
                        ret.Play();
                    }
                    else
                    {
                        ret.StartCoroutine(DoSoundPlay(ret, onEndCallback, onEndParam));
                    }
                }

                /*else {
                 *  Debug.LogWarning("Ran out of available sound player for: " + name);
                 * }*/
            }
            else
            {
                Debug.LogWarning("sound player not found: " + name);
            }

            return(ret);
        }
예제 #6
0
        AudioSource Play(SoundData dat, OnSoundEnd onEndCallback, object onEndParam)
        {
            AudioSource ret = null;

            if (mSfxPlayingCount < sfx.Length)
            {
                SoundPlaying plyr = mSfxPlaying[mSfxPlayingCount];
                mSfxPlayingCount++;

                plyr.data          = dat;
                plyr.src.clip      = dat.clip;
                plyr.startTime     = dat.realtime ? Time.realtimeSinceStartup : Time.time;
                plyr.onEndCallback = onEndCallback;
                plyr.onEndParam    = onEndParam;
                plyr.src.volume    = dat.volume * UserSettingAudio.instance.soundVolume;
                plyr.src.loop      = dat.loop;

                if (dat.delay > 0.0f)
                {
                    audio.PlayDelayed(dat.delay);
                }
                else
                {
                    audio.Play();
                }

                if (!mSoundActive)
                {
                    StartCoroutine(DoSounds());
                }
            }
            else
            {
                Debug.LogWarning("Ran out of available player for: " + dat.name);
            }

            return(ret);
        }
예제 #7
0
 public AudioSource Play(int index, OnSoundEnd onEndCallback = null, object onEndParam = null)
 {
     return(Play(sfx[index], onEndCallback, onEndParam));
 }
예제 #8
0
 public SoundPlayer Play(string name, OnSoundEnd onEndCallback = null, params object[] onEndParam)
 {
     return(Play(name, Vector3.zero, onEndCallback, onEndParam));
 }