Esempio n. 1
0
        public void Update()
        {
            int max = mPlayingTracks.Count;

            if (max > 0)
            {
                while (max > 0)
                {
                    mTrackTemp  = mPlayingTracks.Dequeue();
                    mSourceTemp = mTrackTemp.source;
                    CheckTrackPlayedTime();
                    max--;
                }
                mTrackTemp  = default;
                mSourceTemp = default;
            }
            else
            {
            }

            mWillStopSounds.Clear();

            mPlayCompleteCallback?.Invoke();
            mPlayCompleteCallback = default;
        }
Esempio n. 2
0
        public void PlayBGM(string name, Action onBGMCompleted = default)
        {
            SoundInfo info = mSounds[name];

            if (info != default)
            {
                if (info.isBGM)
                {
                    mBGMInfo = info;
                    if (mBGMSoundTrack == default)
                    {
                        mBGMSoundTrack = new SoundTrack();
                    }
                    else
                    {
                    }
                    mBGMAudioSource.volume = VolumnBGM;
                    PlaySoundTrack(ref name, ref mBGMInfo, ref mBGMAudioSource, ref mBGMSoundTrack, onBGMCompleted, false, IsBGMMute);
                }
                else
                {
                    "error:Audio clip {0} is short effect sound what you will play".Log(name);
                }
            }
            else
            {
            }
        }
Esempio n. 3
0
        private void CreateNewSoundTrack(out AudioSource player, out SoundTrack track)
        {
            GameObject item = new GameObject
            {
                name = "SoundTrack_".Append(mSoundTrackCount.ToString())
            };

            item.transform.SetParent(mPlayerRoot.transform);
            mSoundTrackCount++;

            player = item.AddComponent <AudioSource>();
            track  = new SoundTrack();
        }
Esempio n. 4
0
        public void PlaySound(string name, Action onCompleted = default)
        {
            if (IsSoundMute)
            {
                return;
            }
            else
            {
            }

            SoundInfo info = mSounds[name];

            if (info != default)
            {
                if (!info.isBGM)
                {
                    AudioSource player;
                    SoundTrack  track = default;
                    if (mAudioSourcePool.Count > 0)
                    {
                        track  = mTrackPool.Pop();
                        player = mAudioSourcePool.Pop();
                    }
                    else
                    {
                        CreateNewSoundTrack(out player, out track);
                    }

                    player.volume = VolumnSound;
                    PlaySoundTrack(ref name, ref info, ref player, ref track, onCompleted, true, IsSoundMute);
                }
                else
                {
                    "error:Audio clip {0} is bgm what you will play".Log(name);
                }
            }
            else
            {
            }
        }
Esempio n. 5
0
        private void PlaySoundTrack(ref string name, ref SoundInfo info, ref AudioSource player, ref SoundTrack track, Action onCompleted = default, bool isPlayingStacking = true, bool isMute = false)
        {
            if (track != default)
            {
                player.clip = info.clip;

                if (!isMute)
                {
                    player.Play();
                }
                else
                {
                }

                track.source          = player;
                track.soundInfoName   = name;
                track.clipLength      = info.clip.length;
                track.onPlayCompleted = onCompleted;

                if (isPlayingStacking)
                {
                    mPlayingTracks.Enqueue(track);
                }
                else
                {
                }
            }
            else
            {
            }
        }