Beispiel #1
0
        //NEW
        public AudioSource PlaySound(List <AudioClip> clips, Enumerators.SoundType soundType, int clipIndex = 0, int priority = 128, float volume = -1f, Transform parent = null, bool isLoop = false,
                                     bool isPlaylist = false, bool dropOldBackgroundMusic = true, bool returnHashCode = false)
        {
            if (dropOldBackgroundMusic)
            {
                var oldContainers = _soundContainers.FindAll(x => x.soundParameters.isBackground);

                foreach (var oldCotainer in oldContainers)
                {
                    oldCotainer.audioSource.Stop();
                    oldCotainer.forceClose = true;
                }
            }


            SoundParam     soundParam    = new SoundParam();
            SoundContainer container     = new SoundContainer();
            SoundTypeList  soundTypeList = new SoundTypeList();

            soundTypeList.soundType      = soundType;
            soundTypeList.audioTypeClips = clips;

            soundParam.isBackground = soundType.ToString().Contains("BACKGROUND") ? true : false;
            soundParam.audioClips   = soundTypeList.audioTypeClips;
            soundParam.isLoop       = isLoop;
            soundParam.isMute       = false;
            soundParam.playOnAwake  = false;
            soundParam.priority     = 128;
            soundParam.volume       = volume;


            soundParam.startPosition = 0f;

            container.Init(_soundsRoot, soundType, soundParam, isPlaylist, clipIndex);

            if (parent != null)
            {
                container.container.transform.SetParent(parent);
            }

            _soundContainers.Add(container);

            return(container.audioSource);
        }
Beispiel #2
0
        public void Init(Transform soundsContainerRoot, Enumerators.SoundType type, SoundParam soundParam, bool playlistEnabled, int soundIndex = 0)
        {
            forceClose        = false;
            currentSoundIndex = soundIndex;
            soundParameters   = soundParam;
            isPlaylist        = playlistEnabled;
            soundType         = type;
            container         = new GameObject("AudioClip " + soundType.ToString());
            container.transform.SetParent(soundsContainerRoot, false);
            audioSource = container.AddComponent <AudioSource>();

            audioSource.clip         = soundParam.audioClips[currentSoundIndex];
            audioSource.volume       = soundParam.volume;
            audioSource.loop         = soundParam.isLoop;
            audioSource.time         = soundParam.startPosition;
            audioSource.mute         = soundParam.isMute;
            audioSource.playOnAwake  = soundParam.playOnAwake;
            audioSource.priority     = soundParam.priority;
            audioSource.spatialBlend = 1f;

            audioSource.Play();
        }