示例#1
0
        public float GetSoundLength(Enumerators.SoundType soundType, string namePattern)
        {
            SoundTypeList soundTypeList = _gameSounds.Find(x => x.SoundType == soundType);

            AudioClip clip = soundTypeList.AudioTypeClips.Find(x => x.name.Contains(namePattern));

            return(clip != null ? clip.length : 0f);
        }
示例#2
0
        private void InitializeSounds()
        {
            _gameSounds = new List <SoundTypeList>();

            int countOfTypes = Enum.GetNames(typeof(Enumerators.SoundType)).Length;

            for (int i = 0; i < countOfTypes; i++)
            {
                SoundTypeList soundsList = new SoundTypeList();
                soundsList.SoundType      = (Enumerators.SoundType)i;
                soundsList.AudioTypeClips = LoadAudioClipsByType(soundsList.SoundType);

                _gameSounds.Add(soundsList);
            }
        }
示例#3
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);
        }
示例#4
0
        public float GetSoundLength(Enumerators.SoundType soundType)
        {
            SoundTypeList soundTypeList = _gameSounds.Find(x => x.SoundType == soundType);

            return(soundTypeList.AudioTypeClips.Count > 0 ? soundTypeList.AudioTypeClips[0].length : 0f);
        }