public GunSoundSourceElement(GunSoundSetting soundSetting, GunSoundSetting.GunSoundElement setting, GunSoundSource source)
        {
            this.soundSetting = soundSetting;
            this.setting      = setting;
            this.source       = source;
            gameObject        = new GameObject(setting.name);
#if AimSoundInternal
            // gameObject.hideFlags = HideFlags.DontSave;
#else
            gameObject.hideFlags = HideFlags.HideAndDontSave;
#endif
            gameObject.transform.SetParent(source.transform, false);
            loopAudioSource      = CloneAudioSource(setting, gameObject);
            loopAudioSource.loop = true;
            var endClips = setting.endClips;
            for (int i = 0; i < endClips.Length; ++i)
            {
                if (endClips[i])
                {
                    _maxEndSoundDuration = Mathf.Max(_maxEndSoundDuration, endClips[i].length);
                }
            }

            if (setting.useLowPassFilter)
            {
                var audioLowPassFilter = gameObject.AddComponent <AudioLowPassFilter>();
                audioLowPassFilter.lowpassResonanceQ = setting.lowpassResonanceQ;
                audioLowPassFilter.customCutoffCurve = setting.lowPassFilterCurve;
            }
            // endAudioSource = CloneAudioSource(soundSetting.audioSource,gameObject);
        }
 public static void ParseAudioSource(GunSoundSetting.GunSoundElement from, AudioSource to, float volume)
 {
     to.volume      = from.volume * volume;
     to.rolloffMode = AudioRolloffMode.Custom;
     AddCurveEnd(from.volumeCurve);
     AddCurveEnd(from.spatialBlendCurve);
     AddCurveEnd(from.lowPassFilterCurve);
     to.SetCustomCurve(AudioSourceCurveType.CustomRolloff, from.volumeCurve);
     to.SetCustomCurve(AudioSourceCurveType.SpatialBlend, from.spatialBlendCurve);
 }
        public AudioSource CloneAudioSource(GunSoundSetting.GunSoundElement from, GameObject to)
        {
            var audioSource = to.AddComponent <AudioSource>();

            audioSource.playOnAwake  = false;
            audioSource.loop         = false;
            audioSource.dopplerLevel = 0;
            ParseAudioSource(from, audioSource, source.volume);
            audioSource.outputAudioMixerGroup = source.outputAudioMixerGroup;
            audioSource.priority = source.priority;
            // audioSource.minDistance = source.minDistance;
            audioSource.maxDistance = source.maxDistance;
            return(audioSource);
        }