Exemple #1
0
        private void SetupAudioSource(AudioSource source, SoundDatum data)
        {
            source.name = $"SFX_{data.Clip.name}";

            source.playOnAwake  = false;
            source.clip         = data.Clip;
            source.loop         = data.IsLooping;
            source.volume       = data.Volume;
            source.pitch        = data.RandomPitch;
            source.spatialBlend = 0;

            if (data.Is3d)
            {
                source.spatialBlend = 1;
                source.dopplerLevel = data.Attachment3d.DopplerLevel;
                source.spread       = data.Attachment3d.Spread;
                source.rolloffMode  = data.Attachment3d.VolumeRolloff;
                source.minDistance  = data.Attachment3d.MinDistance;
                source.maxDistance  = data.Attachment3d.MaxDistance;

                if (data.CanAttach())
                {
                    source.transform.SetParent(null);
                    source.transform.position = data.Attachment3d.Attachment.position;
                }
            }

            source.outputAudioMixerGroup = m_sfxMixerGroup;
        }
Exemple #2
0
        public void PlaySound(SoundDatum data)
        {
            if (data == null || !data.IsValid())
            {
                return;
            }

            AudioSource source = GetAudioSource();

            SetupAudioSource(source, data);

            source.Play();

            if (data.Is3d)
            {
                StartCoroutine(Track3dAttachment_Coroutine(source, data.Attachment3d.Attachment));
            }
            else
            {
                StartCoroutine(TrackSoundCompletion_Coroutine(source));
            }
        }