Esempio n. 1
0
        private static void SetSoundResource(SoundParam param)
        {
            param.source_ = SoundResources.GetAudioSource(param.category_id_);

            param.source_.clip   = param.clip_;
            param.source_.volume = param.volume_;
            param.source_.loop   = param.loop_;

            sound_play_list_[param.category_id_].Add(param);
        }
Esempio n. 2
0
        private static void Stop(SoundParam param)
        {
            param.source_.Stop();

            if (param.onFinish != null)
            {
                param.onFinish();
            }

            param.source_.clip = null;
        }
Esempio n. 3
0
        private static SoundParam GetSoundParam(string file_name, int category_id)
        {
            List <SoundParam> category_play_list = sound_play_list_[category_id];

            Debug.Assert(category_play_list != null, "The category doesn't exist!!!");

            SoundParam param = category_play_list.Find((par) => { return(par.file_name_ == file_name); });

            Debug.Assert(param != null, "The filename doesn't exist !!!!");

            return(param);
        }
Esempio n. 4
0
        public static void UnPause(string file_name, int category_id)
        {
            SoundParam param = GetSoundParam(file_name, category_id);

            if (param.source_.isPlaying || param.is_pause_)
            {
                param.source_.UnPause();
                param.is_pause_ = false;
            }
            else
            {
                Debug.LogWarning("Can't unpause!!!");
            }
        }
Esempio n. 5
0
        public static void Play(SoundParam param)
        {
            Debug.Assert(param != null, "Param is null!!!!!");

            SetSoundResource(param);

            if (param.is_oneshot_)
            {
                param.source_.PlayOneShot(param.clip_, param.volume_);
                mono_behaviour_.StartCoroutine(StopDetect(param));
            }
            else
            {
                param.source_.Play();
            }
        }
Esempio n. 6
0
        public static void Stop(string file_name, int category_id, float fade_time = 0.0f)
        {
            List <SoundParam> category_play_list = sound_play_list_[category_id];

            Debug.Assert(category_play_list != null, "The category doesn't exist !!!!");

            SoundParam param = category_play_list.Find((par) => { return(par.file_name_ == file_name); });

            Debug.Assert(param != null, "The filename doesn't exist !!!!");

            mono_behaviour_.StartCoroutine(FadeOut(param, fade_time,
                                                   () => {
                category_play_list.Remove(param);
                if (param.onFinish != null)
                {
                    param.onFinish();
                }
            }));
        }
Esempio n. 7
0
        private static IEnumerator StopDetect(SoundParam param)
        {
            Debug.Assert(param != null, "param is null!!!!!");

            while (param.source_.isPlaying || param.is_pause_)
            {
                yield return(null);
            }

            List <SoundParam> category_play_list = sound_play_list_[param.category_id_];

            param.source_.clip = null;

            if (param.onFinish != null)
            {
                param.onFinish();
            }

            category_play_list.Remove(param);
        }
Esempio n. 8
0
        public void Play(string file_name, bool loop, bool one_shot, System.Action onFinish = null, float volume = 1.0f)
        {
            Debug.Assert(!string.IsNullOrEmpty(file_name), "filename is empty!!!!");

            SoundParam param = new SoundParam();

            AudioClip clip = Resources.Load <AudioClip>(path_ + file_name);

            Debug.Assert(clip != null, file_name + " doesn't exist!!!!");

            param.clip_        = clip;
            param.file_name_   = file_name;
            param.loop_        = loop;
            param.is_oneshot_  = one_shot;
            param.volume_      = volume;
            param.category_id_ = category_id_;
            param.onFinish     = onFinish;

            SoundSystem.Play(param);
        }
Esempio n. 9
0
        private static IEnumerator FadeOut(SoundParam param, float fade_time, System.Action onFinish = null)
        {
            if (fade_time > 0.0f)
            {
                float frame_count_ = param.source_.volume / (fade_time * SoundSettings.frame_rate_);

                while (param.source_.volume > 0.0f)
                {
                    param.source_.volume -= frame_count_;
                    yield return(null);
                }
            }

            param.source_.Stop();
            param.source_.clip = null;

            if (onFinish != null)
            {
                onFinish();
            }
        }