Пример #1
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);
            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();
        }
Пример #2
0
        private SoundContainer DoSoundContainer(
            Enumerators.SoundType soundType,
            float volume     = -1f,
            Transform parent = null,
            bool isLoop      = false,
            bool isPlaylist  = false,
            int clipIndex    = 0,
            string clipTitle = "",
            bool isInQueue   = false,
            string tag       = "")
        {
            SoundParam     soundParam    = new SoundParam();
            SoundContainer container     = new SoundContainer();
            SoundTypeList  soundTypeList = _gameSounds.Find(x => x.SoundType == soundType);

            switch (soundType)
            {
            case Enumerators.SoundType.BACKGROUND:
            case Enumerators.SoundType.BATTLEGROUND:
                soundParam.IsBackground = true;
                break;

            default:
                soundParam.IsBackground = false;
                break;
            }

            soundParam.AudioClips = soundTypeList.AudioTypeClips;
            if (!string.IsNullOrEmpty(clipTitle))
            {
                soundParam.AudioClips = soundParam.AudioClips.Where(clip => clip.name.Contains(clipTitle)).ToList();
            }

            // small hack to ignore missing audio clips
            if (soundParam.AudioClips.Count == 0)
            {
                return(null);
            }

            soundParam.IsLoop      = isLoop;
            soundParam.IsMute      = false;
            soundParam.PlayOnAwake = false;

            soundParam.Priority = 128;
            if (volume < 0)
            {
                soundParam.Volume = _sfxVolume;
            }
            else
            {
                soundParam.Volume = volume;
            }

            if (SfxMuted && !soundParam.IsBackground)
            {
                soundParam.IsMute = true;
            }
            else if (MusicMuted && soundParam.IsBackground)
            {
                soundParam.IsMute = true;
            }

            soundParam.StartPosition = 0f;

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

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

            _soundContainers.Add(container);
            return(container);
        }