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); }
void StartPlay(GunSoundSource gunSoundSource) { gunSoundSource.Play(); if (!gunSoundSource.setting.isOneShot) { lastPlaying = gunSoundSource; EditorApplication.update += OnUpdateAudio; } }
void StopPlay() { if (lastPlaying && lastPlaying.needStop) { lastPlaying.Stop(); } EditorApplication.update -= OnUpdateAudio; lastPlaying = null; }
void OnEnable() { CreateLineMat(); var previewObject = new GameObject(); previewObject.hideFlags = HideFlags.HideAndDontSave; previewObject.name = "previewSoundSource"; previewSoundSource = previewObject.AddComponent <GunSoundSource>(); previewSoundSource.setting = (GunSoundSetting)target; UpdateSoundPosition(); }