public void SetAudioSource(AudioSource sourceToCopy) { AudioSource.clip = sourceToCopy.clip; AudioSource.loop = sourceToCopy.loop; AudioSource.pitch = sourceToCopy.pitch; AudioSource.mute = sourceToCopy.mute; AudioSource.spatialize = sourceToCopy.spatialize; AudioSource.spread = sourceToCopy.spread; AudioSource.volume = sourceToCopy.volume; AudioSource.bypassEffects = sourceToCopy.bypassEffects; AudioSource.dopplerLevel = sourceToCopy.dopplerLevel; AudioSource.maxDistance = sourceToCopy.maxDistance; AudioSource.minDistance = sourceToCopy.minDistance; AudioSource.panStereo = sourceToCopy.panStereo; AudioSource.rolloffMode = sourceToCopy.rolloffMode; AudioSource.spatialBlend = sourceToCopy.spatialBlend; AudioSource.bypassListenerEffects = sourceToCopy.bypassListenerEffects; AudioSource.bypassReverbZones = sourceToCopy.bypassReverbZones; AudioSource.reverbZoneMix = sourceToCopy.reverbZoneMix; AudioSource.spatializePostEffects = sourceToCopy.spatializePostEffects; AudioSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, sourceToCopy.GetCustomCurve(AudioSourceCurveType.CustomRolloff)); AudioSource.SetCustomCurve(AudioSourceCurveType.Spread, sourceToCopy.GetCustomCurve(AudioSourceCurveType.Spread)); AudioSource.SetCustomCurve(AudioSourceCurveType.SpatialBlend, sourceToCopy.GetCustomCurve(AudioSourceCurveType.SpatialBlend)); AudioSource.SetCustomCurve(AudioSourceCurveType.ReverbZoneMix, sourceToCopy.GetCustomCurve(AudioSourceCurveType.ReverbZoneMix)); }
public static SAudioSource Serialize(this AudioSource _audioSource) { SAudioSource returnVal = new SAudioSource { ExistsOnObject = (_audioSource == null) ? false : true, Enabled = _audioSource.enabled, //outputAudioMixerGroup = _audioSource.outputAudioMixerGroup, //audioClip = _audioSource.clip, playOnAwake = _audioSource.playOnAwake, volume = _audioSource.volume, pitch = _audioSource.pitch, loop = _audioSource.loop, mute = _audioSource.mute, spatialize = _audioSource.spatialize, spatializePostEffect = _audioSource.spatializePostEffects, priority = _audioSource.priority, dopplerLevel = _audioSource.dopplerLevel, minDistance = _audioSource.minDistance, maxDistance = _audioSource.maxDistance, pan2D = _audioSource.panStereo, rolloffMode = _audioSource.rolloffMode, bypassEffects = _audioSource.bypassEffects, bypassListenerEffects = _audioSource.bypassListenerEffects, bypassReverbZones = _audioSource.bypassReverbZones, rolloffCustomCurve = _audioSource.GetCustomCurve(AudioSourceCurveType.CustomRolloff).Serialize(), panLevelCustomCurve = _audioSource.GetCustomCurve(AudioSourceCurveType.SpatialBlend).Serialize(), spreadCustomCurve = _audioSource.GetCustomCurve(AudioSourceCurveType.Spread).Serialize(), reverbZoneMixCustomCurve = _audioSource.GetCustomCurve(AudioSourceCurveType.ReverbZoneMix).Serialize() }; return(returnVal); }
private static void CopySource(ref AudioSource source, AudioSource copySource) { source.bypassEffects = copySource.bypassEffects; source.bypassListenerEffects = copySource.bypassListenerEffects; source.bypassReverbZones = copySource.bypassReverbZones; source.dopplerLevel = copySource.dopplerLevel; source.enabled = copySource.enabled; source.hideFlags = copySource.hideFlags; source.ignoreListenerPause = copySource.ignoreListenerPause; source.ignoreListenerVolume = copySource.ignoreListenerVolume; source.loop = copySource.loop; source.maxDistance = copySource.maxDistance; source.minDistance = copySource.minDistance; source.mute = copySource.mute; source.outputAudioMixerGroup = copySource.outputAudioMixerGroup; source.panStereo = copySource.panStereo; source.pitch = copySource.pitch; source.playOnAwake = copySource.playOnAwake; source.priority = copySource.priority; source.reverbZoneMix = copySource.reverbZoneMix; source.rolloffMode = copySource.rolloffMode; source.spatialBlend = copySource.spatialBlend; source.spatialize = copySource.spatialize; source.spatializePostEffects = copySource.spatializePostEffects; source.spread = copySource.spread; source.tag = copySource.tag; source.time = copySource.time; source.timeSamples = copySource.timeSamples; source.velocityUpdateMode = copySource.velocityUpdateMode; source.volume = copySource.volume; source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, copySource.GetCustomCurve(AudioSourceCurveType.CustomRolloff)); source.SetCustomCurve(AudioSourceCurveType.ReverbZoneMix, copySource.GetCustomCurve(AudioSourceCurveType.ReverbZoneMix)); source.SetCustomCurve(AudioSourceCurveType.SpatialBlend, copySource.GetCustomCurve(AudioSourceCurveType.SpatialBlend)); source.SetCustomCurve(AudioSourceCurveType.Spread, copySource.GetCustomCurve(AudioSourceCurveType.Spread)); }
public static void Copy(this AudioSource target, AudioSource source, bool useCustomCurves = true) { target.enabled = source.enabled; target.clip = source.clip; target.mute = source.mute; target.bypassEffects = source.bypassEffects; target.bypassListenerEffects = source.bypassListenerEffects; target.bypassReverbZones = source.bypassReverbZones; target.playOnAwake = source.playOnAwake; target.loop = source.loop; target.priority = source.priority; target.volume = source.volume; target.pitch = source.pitch; target.dopplerLevel = source.dopplerLevel; target.rolloffMode = source.rolloffMode; target.minDistance = source.minDistance; target.spatialBlend = source.spatialBlend; target.spread = source.spread; target.maxDistance = source.maxDistance; target.panStereo = source.panStereo; target.time = source.time; target.timeSamples = source.timeSamples; target.velocityUpdateMode = source.velocityUpdateMode; target.ignoreListenerPause = source.ignoreListenerPause; target.ignoreListenerVolume = source.ignoreListenerVolume; target.spatialize = source.spatialize; if (useCustomCurves) { target.SetCustomCurve(AudioSourceCurveType.CustomRolloff, source.GetCustomCurve(AudioSourceCurveType.CustomRolloff)); target.SetCustomCurve(AudioSourceCurveType.ReverbZoneMix, source.GetCustomCurve(AudioSourceCurveType.ReverbZoneMix)); target.SetCustomCurve(AudioSourceCurveType.SpatialBlend, source.GetCustomCurve(AudioSourceCurveType.SpatialBlend)); target.SetCustomCurve(AudioSourceCurveType.Spread, source.GetCustomCurve(AudioSourceCurveType.Spread)); } }
private static void ApplyAudioSourceCharacteristicsInternal(AudioSource applyTarget, AudioSource applyFrom) { applyTarget.outputAudioMixerGroup = applyFrom.outputAudioMixerGroup; applyTarget.SetCustomCurve(AudioSourceCurveType.CustomRolloff, applyFrom.GetCustomCurve(AudioSourceCurveType.CustomRolloff)); applyTarget.SetCustomCurve(AudioSourceCurveType.ReverbZoneMix, applyFrom.GetCustomCurve(AudioSourceCurveType.ReverbZoneMix)); applyTarget.SetCustomCurve(AudioSourceCurveType.SpatialBlend, applyFrom.GetCustomCurve(AudioSourceCurveType.SpatialBlend)); applyTarget.SetCustomCurve(AudioSourceCurveType.Spread, applyFrom.GetCustomCurve(AudioSourceCurveType.Spread)); applyTarget.ignoreListenerVolume = applyFrom.ignoreListenerVolume; applyTarget.ignoreListenerPause = applyFrom.ignoreListenerPause; applyTarget.velocityUpdateMode = applyFrom.velocityUpdateMode; applyTarget.panStereo = applyFrom.panStereo; applyTarget.spatialBlend = applyFrom.spatialBlend; applyTarget.spatialize = applyFrom.spatialize; applyTarget.spatializePostEffects = applyFrom.spatializePostEffects; applyTarget.reverbZoneMix = applyFrom.reverbZoneMix; applyTarget.bypassEffects = applyFrom.bypassEffects; applyTarget.bypassListenerEffects = applyFrom.bypassListenerEffects; applyTarget.bypassReverbZones = applyFrom.bypassReverbZones; applyTarget.dopplerLevel = applyFrom.dopplerLevel; applyTarget.spread = applyFrom.spread; applyTarget.priority = applyFrom.priority; applyTarget.mute = applyFrom.mute; applyTarget.minDistance = applyFrom.minDistance; applyTarget.maxDistance = applyFrom.maxDistance; }
private static void CopySourceParemeters(AudioSource fromSource, ref AudioSource toSource) { toSource.bypassEffects = fromSource.bypassEffects; toSource.bypassListenerEffects = fromSource.bypassListenerEffects; toSource.bypassReverbZones = fromSource.bypassReverbZones; toSource.dopplerLevel = fromSource.dopplerLevel; toSource.enabled = fromSource.enabled; toSource.hideFlags = fromSource.hideFlags; toSource.ignoreListenerPause = fromSource.ignoreListenerPause; toSource.ignoreListenerVolume = fromSource.ignoreListenerVolume; toSource.loop = fromSource.loop; toSource.maxDistance = fromSource.maxDistance; toSource.minDistance = fromSource.minDistance; toSource.mute = fromSource.mute; toSource.outputAudioMixerGroup = fromSource.outputAudioMixerGroup; toSource.panStereo = fromSource.panStereo; toSource.pitch = fromSource.pitch; toSource.playOnAwake = fromSource.playOnAwake; toSource.priority = fromSource.priority; toSource.reverbZoneMix = fromSource.reverbZoneMix; toSource.rolloffMode = fromSource.rolloffMode; toSource.spatialBlend = fromSource.spatialBlend; toSource.spatialize = fromSource.spatialize; toSource.spatializePostEffects = fromSource.spatializePostEffects; toSource.spread = fromSource.spread; toSource.tag = fromSource.tag; toSource.time = fromSource.time; toSource.timeSamples = fromSource.timeSamples; toSource.velocityUpdateMode = fromSource.velocityUpdateMode; toSource.volume = fromSource.volume; toSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, fromSource.GetCustomCurve(AudioSourceCurveType.CustomRolloff)); toSource.SetCustomCurve(AudioSourceCurveType.ReverbZoneMix, fromSource.GetCustomCurve(AudioSourceCurveType.ReverbZoneMix)); toSource.SetCustomCurve(AudioSourceCurveType.SpatialBlend, fromSource.GetCustomCurve(AudioSourceCurveType.SpatialBlend)); toSource.SetCustomCurve(AudioSourceCurveType.Spread, fromSource.GetCustomCurve(AudioSourceCurveType.Spread)); }
private AudioSource CopySource(AudioSource newSource, AudioSource sourceToCopy) { newSource.clip = sourceToCopy.clip; newSource.loop = sourceToCopy.loop; newSource.pitch = sourceToCopy.pitch; newSource.mute = sourceToCopy.mute; newSource.spatialize = sourceToCopy.spatialize; newSource.spread = sourceToCopy.spread; newSource.volume = sourceToCopy.volume; newSource.bypassEffects = sourceToCopy.bypassEffects; newSource.dopplerLevel = sourceToCopy.dopplerLevel; newSource.maxDistance = sourceToCopy.maxDistance; newSource.minDistance = sourceToCopy.minDistance; newSource.panStereo = sourceToCopy.panStereo; newSource.rolloffMode = sourceToCopy.rolloffMode; newSource.spatialBlend = sourceToCopy.spatialBlend; newSource.bypassListenerEffects = sourceToCopy.bypassListenerEffects; newSource.bypassReverbZones = sourceToCopy.bypassReverbZones; newSource.reverbZoneMix = sourceToCopy.reverbZoneMix; newSource.spatializePostEffects = sourceToCopy.spatializePostEffects; newSource.outputAudioMixerGroup = sourceToCopy.outputAudioMixerGroup; newSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, sourceToCopy.GetCustomCurve(AudioSourceCurveType.CustomRolloff)); newSource.SetCustomCurve(AudioSourceCurveType.Spread, sourceToCopy.GetCustomCurve(AudioSourceCurveType.Spread)); newSource.SetCustomCurve(AudioSourceCurveType.SpatialBlend, sourceToCopy.GetCustomCurve(AudioSourceCurveType.SpatialBlend)); newSource.SetCustomCurve(AudioSourceCurveType.ReverbZoneMix, sourceToCopy.GetCustomCurve(AudioSourceCurveType.ReverbZoneMix)); return(newSource); }
// Token: 0x060063FA RID: 25594 RVA: 0x00237B94 File Offset: 0x00235F94 private static float CalculateCustomRolloffNearDistance(AudioSource audioSrc) { if (audioSrc.rolloffMode != AudioRolloffMode.Custom) { return(audioSrc.minDistance); } AnimationCurve customCurve = audioSrc.GetCustomCurve(AudioSourceCurveType.CustomRolloff); if (customCurve == null) { return(1f); } Keyframe[] keys = customCurve.keys; if (keys.Length == 0) { return(1f); } Keyframe keyframe = keys[0]; for (int i = 1; i < keys.Length; i++) { if (keys[i].value < keyframe.value - 0.001f) { break; } keyframe = keys[i]; } return(keyframe.time * audioSrc.maxDistance); }
private CSoundSlot ProcPlaySound_GetSlot() { if (_pSlotCurrentPlaying != null) { _pManagerSound.EventOnSlotFinishClip(_pSlotCurrentPlaying); } CSoundSlot pSlot = null; if (_arrPlayAudioClip != null) { AudioClip pClipRandom = _arrPlayAudioClip.GetRandom(); pSlot = _pManagerSound.DoPlaySoundEffect_OrNull(pClipRandom, _fSoundVolume); } if (pSlot != null && _pAudioSource != null) { AudioSource pSlotSource = pSlot.p_pAudioSource; pSlotSource.rolloffMode = _pAudioSource.rolloffMode; for (int i = 0; i < 3; i++) { AnimationCurve pCurve = _pAudioSource.GetCustomCurve((AudioSourceCurveType)i); pSlotSource.SetCustomCurve((AudioSourceCurveType)i, pCurve); } } return(pSlot); }
//Transfers audio settings from an AudioSource. Only used in the editor public void TransferFromAudioSource(AudioSource source) { Loop = source.loop; Volume = source.volume; AudioClip = source.clip; BypassEffects = source.bypassEffects; BypassListenerEffects = source.bypassListenerEffects; BypassReverbZones = source.bypassReverbZones; DopplerLevel = source.dopplerLevel; MaxDistance = source.maxDistance; MinDistance = source.minDistance; Mute = source.mute; OutputAudioMixerGroup = source.outputAudioMixerGroup; PanStereo = source.panStereo; Pitch = source.pitch; Priority = source.priority; RolloffMode = source.rolloffMode; SpatialBlend = source.spatialBlend; ReverbZoneMix = source.reverbZoneMix; Spatialize = source.spatialize; if (RolloffMode == AudioRolloffMode.Custom) { CustomRolloffCurve = source.GetCustomCurve(AudioSourceCurveType.CustomRolloff); } else { CustomRolloffCurve = null; } }
private CSoundSlot ProcPlaySound_GetSlot(string strSoundEvent) { if (_bStop_OnPlaySound && _listSlotCurrentPlaying.Count != 0) { for (int i = 0; i < _listSlotCurrentPlaying.Count; i++) { CManagerSound.instance.EventOnSlotFinishClip(_listSlotCurrentPlaying[i]); } _listSlotCurrentPlaying.Clear(); } CSoundSlot pSlot = null; if (_listSoundPlayInfo != null) { SSoundPlayInfo pPlayInfo = string.IsNullOrEmpty(strSoundEvent) == false && _mapSoundPlayEventWrapper.ContainsKey(strSoundEvent) ? _mapSoundPlayEventWrapper[strSoundEvent].GetRandom().p_pSoundPlayInfo : _listSoundPlayInfo.GetRandom(); if (pPlayInfo == null) { Debug.LogError(name + "pPlayInfo == null strSoundEvent : " + strSoundEvent, this); } else { if (pPlayInfo.p_pAudioClip != null) { pSlot = CManagerSound.instance.DoPlaySoundEffect_OrNull(pPlayInfo.p_pAudioClip, _fSoundVolume * pPlayInfo.p_fLocalVolume); } else { if (string.IsNullOrEmpty(pPlayInfo.p_strAudioKey) == false) { pSlot = CManagerSound.instance.DoPlaySoundEffect_OrNull(pPlayInfo.p_strAudioKey, _fSoundVolume * pPlayInfo.p_fLocalVolume); } else { Debug.LogError(name + "SoundPlayInfo 가 잘못되었습니다", this); } } } } if (pSlot != null && _pAudioSource != null) { AudioSource pSlotSource = pSlot.p_pAudioSource; pSlotSource.rolloffMode = _pAudioSource.rolloffMode; for (int i = 0; i < 3; i++) { AnimationCurve pCurve = _pAudioSource.GetCustomCurve((AudioSourceCurveType)i); pSlotSource.SetCustomCurve((AudioSourceCurveType)i, pCurve); } } _bIsPlaying = pSlot != null; return(pSlot); }
public void UpdateCurve(float volume) { var curve = source.GetCustomCurve(AudioSourceCurveType.CustomRolloff); var distance = Vector3.Distance(listener.transform.position, transform.position); curve.AddKey(new Keyframe(distance / source.maxDistance, Mathf.Clamp01(volume))); source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, curve); }
static int GetCustomCurve(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); AudioSource obj = (AudioSource)LuaScriptMgr.GetUnityObjectSelf(L, 1, "AudioSource"); AudioSourceCurveType arg0 = (AudioSourceCurveType)LuaScriptMgr.GetNetObject(L, 2, typeof(AudioSourceCurveType)); AnimationCurve o = obj.GetCustomCurve(arg0); LuaScriptMgr.PushObject(L, o); return(1); }
static int GetCustomCurve(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); AudioSource obj = LuaScriptMgr.GetUnityObject <AudioSource>(L, 1); AudioSourceCurveType arg0 = LuaScriptMgr.GetNetObject <AudioSourceCurveType>(L, 2); AnimationCurve o = obj.GetCustomCurve(arg0); LuaScriptMgr.PushObject(L, o); return(1); }
private void Awake() { spectrum = GetComponent <AudioSpectrum>(); intensityAnimRecord = new ChangeRecord[spectrumAnimations.Length]; if (spriteRemderer) { initialColor = spriteRemderer.color; //initialScale = transformToAnim.localScale; } audioSource = GetComponent <AudioSource>(); volumeCurve = audioSource.GetCustomCurve(AudioSourceCurveType.CustomRolloff); animator = GetComponent <Animator>(); }
void Start() { //if (!GetComponent<Rigidbody>()) Debug.Log("No RigidBody on" + gameObject.name); if (!GetComponent <Rigidbody>()) { Rigidbody rb = gameObject.AddComponent(typeof(Rigidbody)) as Rigidbody; rb.useGravity = false; rb.isKinematic = true; } AudioSource settings = audiosourceSettings.source; for (int i = 0; i < 2; i++) { AudioSource audioSource = gameObject.AddComponent(typeof(AudioSource)) as AudioSource; audioSource.spatialBlend = settings.spatialBlend; audioSource.spatialize = settings.spatialize; audioSource.rolloffMode = settings.rolloffMode; audioSource.rolloffMode = settings.rolloffMode; audioSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, settings.GetCustomCurve(AudioSourceCurveType.CustomRolloff)); audioSource.maxDistance = soundRange * 2; sources.Add(audioSource); } sourceNear = sources[0]; sourceNear.volume = .4f; if (playbackDevice) { sourceNear.volume = 1.5f; } sourceFar = sources[1]; sourceFar.maxDistance *= 8; sourceFar.volume = .1f; soundSphere = gameObject.AddComponent(typeof(SphereCollider)) as SphereCollider; soundSphere.radius = soundRange; soundSphere.isTrigger = true; if (testClip) { PlaySound(testClip); } }
public static float EvaluateRolloff(float distance, AudioSource source) { switch (source.rolloffMode) { case AudioRolloffMode.Logarithmic: return((source.minDistance / distance).Clamp01()); case AudioRolloffMode.Linear: return((1 - (distance - source.minDistance) / (source.maxDistance - source.minDistance)).Clamp01()); case AudioRolloffMode.Custom: var animationCurve = source.GetCustomCurve(AudioSourceCurveType.CustomRolloff); return(animationCurve.Evaluate(distance / source.maxDistance)); default: throw new ArgumentOutOfRangeException(); } }
public static void AddVRCSpatialToBareAudioSource(AudioSource src) { if (src == null) { return; } var vrcsp = src.gameObject.GetComponent <VRC.SDKBase.VRC_SpatialAudioSource>(); if (vrcsp != null) { return; } #if VRC_SDK_VRCSDK2 vrcsp = src.gameObject.AddComponent <VRCSDK2.VRC_SpatialAudioSource>(); #elif UDON vrcsp = src.gameObject.AddComponent <VRC.SDK3.Components.VRCSpatialAudioSource>(); #endif // add default values bool isAvatar = src.gameObject.GetComponentInParent <VRC.SDKBase.VRC_AvatarDescriptor>(); vrcsp.Gain = isAvatar ? AudioManagerSettings.AvatarAudioMaxGain : AudioManagerSettings.RoomAudioGain; vrcsp.Near = 0; vrcsp.Far = isAvatar ? AudioManagerSettings.AvatarAudioMaxRange : AudioManagerSettings.RoomAudioMaxRange; vrcsp.UseAudioSourceVolumeCurve = false; // enable spatialization if src is not 2D vrcsp.EnableSpatialization = false; AnimationCurve curve = src.GetCustomCurve(AudioSourceCurveType.SpatialBlend); if (curve != null) { foreach (var key in curve.keys) { if (key.value != 0 || key.inTangent != 0) { vrcsp.EnableSpatialization = true; break; } } } }
// Use this for initialization void Awake() { soundTimer = Random.Range(0, soundFrequency); AudioSource settings = audiosourceSettings.source; source = gameObject.AddComponent(typeof(AudioSource)) as AudioSource; source.spatialBlend = settings.spatialBlend; source.spatialize = settings.spatialize; source.rolloffMode = settings.rolloffMode; source.rolloffMode = settings.rolloffMode; source.maxDistance = settings.maxDistance; source.playOnAwake = settings.playOnAwake; source.dopplerLevel = settings.dopplerLevel; source.priority = Random.Range(100, 256); source.volume = settings.volume; source.spread = settings.spread; source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, settings.GetCustomCurve(AudioSourceCurveType.CustomRolloff)); }
public static void AddVRCSpatialToBareAudioSource(AudioSource src) { if (src == null) { return; } var vrcsp = src.gameObject.GetComponent <VRC.SDKBase.VRC_SpatialAudioSource>(); if (vrcsp != null) { return; } vrcsp = src.gameObject.AddComponent <VRC.SDKBase.VRC_SpatialAudioSource>(); // add default values bool isAvatar = src.gameObject.GetComponentInParent <VRC.SDKBase.VRC_AvatarDescriptor>(); vrcsp.Gain = isAvatar ? VRCSDK2.AudioManagerSettings.AvatarAudioMaxGain : VRCSDK2.AudioManagerSettings.RoomAudioGain; vrcsp.Near = 0; vrcsp.Far = isAvatar ? VRCSDK2.AudioManagerSettings.AvatarAudioMaxRange : VRCSDK2.AudioManagerSettings.RoomAudioMaxRange; vrcsp.UseAudioSourceVolumeCurve = false; // enable spatialization if src is not 2D AnimationCurve curve = src.GetCustomCurve(AudioSourceCurveType.SpatialBlend); if (src.spatialBlend == 0 || (curve == null || curve.keys.Length <= 1)) { vrcsp.EnableSpatialization = false; } else { vrcsp.EnableSpatialization = true; } }
private void Awake() { mSimulator = SteamAudioManager.Simulator; var settings = SteamAudioManager.GetSimulationSettings(false); mSource = new Source(SteamAudioManager.Simulator, settings); mAudioEngineSource = AudioEngineSource.Create(SteamAudioSettings.Singleton.audioEngine); if (mAudioEngineSource != null) { mAudioEngineSource.Initialize(gameObject); mAudioEngineSource.UpdateParameters(this); } mAudioSource = GetComponent <AudioSource>(); mThis = GCHandle.Alloc(this); if (SteamAudioSettings.Singleton.audioEngine == AudioEngineType.Unity && distanceAttenuation && distanceAttenuationInput == DistanceAttenuationInput.CurveDriven && reflections && useDistanceCurveForReflections) { mAttenuationData.rolloffMode = mAudioSource.rolloffMode; mAttenuationData.minDistance = mAudioSource.minDistance; mAttenuationData.maxDistance = mAudioSource.maxDistance; mAttenuationData.curve = mAudioSource.GetCustomCurve(AudioSourceCurveType.CustomRolloff); mCurveAttenuationModel.type = DistanceAttenuationModelType.Callback; mCurveAttenuationModel.callback = EvaluateDistanceCurve; mCurveAttenuationModel.userData = GCHandle.ToIntPtr(mThis); mCurveAttenuationModel.dirty = Bool.False; } }
private static bool IsAudioSource2D(AudioSource src) { AnimationCurve curve = src.GetCustomCurve(AudioSourceCurveType.SpatialBlend); return(Math.Abs(src.spatialBlend) < float.Epsilon && (curve == null || curve.keys.Length <= 1)); }
public AnimationCurve GetCustomCurve(AudioSourceCurveType type) { return(audio.GetCustomCurve(type)); }
AudioClipPlayer PrepareClip(AudioClip clip, AudioManagerCategory trigger, bool loop = false, bool startPaused = false, AudioMixerGroup outBus = null, float volume = 1.0f, float delay = 0.0f, bool in3D = false, Vector3?position = null, float minDistance = 1f, float maxDistance = 500f, AudioRolloffMode volumeRolloffMode = AudioRolloffMode.Logarithmic, float pitchRandomisation = 0.0f, Transform trackTrans = null, AudioSource referenceAudioSource = null) { AudioClipPlayer go = m_AudioClipPlayerPool.RentObject().GetComponent <AudioClipPlayer>(); go.Setup(m_AudioClipPlayerPool, this, signalBus); go.Category = trigger; if (go.IsEmpty == false) { D.LogError("Rented AudioClipPlayer is not empty! Used for " + go.ClipID); } go.transform.parent = transform; go.transform.localPosition = Vector3.zero; var audioSource = go.AudioSource; if (outBus != null) { audioSource.outputAudioMixerGroup = outBus; } audioSource.pitch = referenceAudioSource ? referenceAudioSource.pitch : 1; audioSource.loop = loop; audioSource.clip = clip; audioSource.volume = volume; audioSource.spatialBlend = referenceAudioSource ? referenceAudioSource.spatialBlend : (in3D) ? 1.0f : 0.0f; if (in3D || m_AudioMode == AudioMode.AUDIO_3D) { audioSource.minDistance = referenceAudioSource ? referenceAudioSource.minDistance : minDistance; audioSource.maxDistance = referenceAudioSource ? referenceAudioSource.maxDistance : maxDistance; audioSource.rolloffMode = referenceAudioSource ? referenceAudioSource.rolloffMode : volumeRolloffMode; if (position != null) { go.transform.position = position.Value; } if (audioSource.rolloffMode == AudioRolloffMode.Custom && referenceAudioSource) { foreach (AudioSourceCurveType audioCurve in (AudioSourceCurveType[])Enum.GetValues(typeof(AudioSourceCurveType))) { audioSource.SetCustomCurve(audioCurve, referenceAudioSource.GetCustomCurve(audioCurve)); } } audioSource.dopplerLevel = referenceAudioSource ? referenceAudioSource.dopplerLevel : audioSource.dopplerLevel; audioSource.spread = referenceAudioSource ? referenceAudioSource.spread : audioSource.spread; audioSource.spatialize = referenceAudioSource ? referenceAudioSource.spatialize : audioSource.spatialize; audioSource.spatializePostEffects = referenceAudioSource ? referenceAudioSource.spatializePostEffects : audioSource.spatializePostEffects; } if (pitchRandomisation != 0.0f) { pitchRandomisation = Mathf.Abs(pitchRandomisation); float defaultPitch = referenceAudioSource ? referenceAudioSource.pitch : 1.0f; audioSource.pitch = defaultPitch + UnityEngine.Random.Range(-pitchRandomisation, pitchRandomisation); } float releaseDelayGameTime = 0; float releaseDelayRealTime = 0; if (!loop && !startPaused) { // Return to pool after the clip is played releaseDelayGameTime = delay; releaseDelayRealTime = clip.length + 0.1f; } go.SetClip(clip, trackTrans, releaseDelayGameTime, releaseDelayRealTime, trigger.ID); return(go); }
/// <summary> /// Make this <see cref="IntroloopPlayer"> audio curve to be like <paramref name="matchTo"> for a specific <see cref="AudioSourceCurveType"> /// </summary> public void MatchAudioSourceCurveType(AudioSourceCurveType curveType, AudioSource matchTo) { SetAudioSourceCurveType(curveType, matchTo.GetCustomCurve(curveType)); }