public void Start(Vector3 emitter_position) { if (!isRunning) { if (oneShotSound != null) { EventInstance eventInstance = KFMOD.CreateInstance(oneShotSound); if (!eventInstance.isValid()) { Debug.LogWarning("Could not find event: " + oneShotSound); } else { Vector3 pos = new Vector3(emitter_position.x, emitter_position.y, 0f); ATTRIBUTES_3D attributes = pos.To3DAttributes(); eventInstance.set3DAttributes(attributes); eventInstance.setVolume(tilePercentage * 2f); eventInstance.start(); eventInstance.release(); } } else { soundEvent = KFMOD.CreateInstance(sound); if (soundEvent.isValid()) { soundEvent.start(); } isRunning = true; } } }
private static void Set3DAttributes(FMOD.Studio.EventInstance evt, ATTRIBUTES_3D attributes) { if (evt != null && evt.isValid()) { UnityUtil.ERRCHECK(evt.set3DAttributes(attributes)); } }
public static EventInstance BeginOneShot(string sound, Vector3 position) { if (string.IsNullOrEmpty(sound) || App.IsExiting || !RuntimeManager.IsInitialized) { return(default(EventInstance)); } EventInstance result = CreateInstance(sound); if (!result.isValid()) { if (!((UnityEngine.Object)KFMODDebugger.instance != (UnityEngine.Object)null)) { goto IL_004c; } goto IL_004c; } Vector3 pos = new Vector3(position.x, position.y, 0f); if (!((UnityEngine.Object)KFMODDebugger.instance != (UnityEngine.Object)null)) { goto IL_0078; } goto IL_0078; IL_0078: ATTRIBUTES_3D attributes = pos.To3DAttributes(); result.set3DAttributes(attributes); result.setVolume(1f); return(result); IL_004c: return(result); }
private void Update() { if (this.Remote) { return; } PLAYBACK_STATE pLAYBACK_STATE = PLAYBACK_STATE.STOPPED; if (this.musicTrack != null) { UnityUtil.ERRCHECK(this.musicTrack.getPlaybackState(out pLAYBACK_STATE)); } if (pLAYBACK_STATE != PLAYBACK_STATE.STOPPED) { PlayerSfx.MusicPlaying = true; } else { PlayerSfx.MusicPlaying = false; } if (base.transform.hasChanged) { base.transform.hasChanged = false; ATTRIBUTES_3D attributes = UnityUtil.to3DAttributes(this.SfxPlayer, null); PlayerSfx.Set3DAttributes(this.staminaBreathInstance, attributes); PlayerSfx.Set3DAttributes(this.walkyTalkyInstance, attributes); PlayerSfx.Set3DAttributes(this.musicTrack, attributes); PlayerSfx.Set3DAttributes(this.afterStormInstance, this.SfxPlayer.transform.position.to3DAttributes()); } if (this.afterStormInstance != null && !this.afterStormInstance.isValid()) { this.afterStormInstance = null; } Vector3 vector = (base.GetComponent <Rigidbody>().position - this.prevPosition) / Time.deltaTime; this.prevPosition = base.GetComponent <Rigidbody>().position; Vector3 vector2 = new Vector3(vector.x, 0f, vector.z); this.flatVelocity = vector2.magnitude; if (!this.Buoyancy.InWater) { this.immersed = false; } else if (!this.immersed && !LocalPlayer.FpCharacter.Grounded && LocalPlayer.FpCharacter.IsAboveWaistDeep()) { this.immersed = true; float num = Mathf.Clamp(this.SplashSpeedMaximum - this.SplashSpeedMinimum, 0f, this.SplashSpeedMaximum); float num2 = (this.Buoyancy.LastWaterEnterSpeed - this.SplashSpeedMinimum) / num; if (num2 >= 0f) { FMOD.Studio.EventInstance @event = FMOD_StudioSystem.instance.GetEvent(this.SplashEvent); UnityUtil.ERRCHECK(@event.set3DAttributes(UnityUtil.to3DAttributes(this.SfxPlayer, null))); UnityUtil.ERRCHECK(@event.setParameterValue("speed", Mathf.Clamp01(num2))); UnityUtil.ERRCHECK(@event.start()); UnityUtil.ERRCHECK(@event.release()); } } }
public static ATTRIBUTES_3D To3DAttributes(this Transform transform) { ATTRIBUTES_3D result = default(ATTRIBUTES_3D); result.forward = transform.forward.ToFMODVector(); result.up = transform.up.ToFMODVector(); result.position = transform.position.ToFMODVector(); return(result); }
public static ATTRIBUTES_3D To3DAttributes(this Vector3 pos) { ATTRIBUTES_3D result = default(ATTRIBUTES_3D); result.forward = Vector3.forward.ToFMODVector(); result.up = Vector3.up.ToFMODVector(); result.position = pos.ToFMODVector(); return(result); }
public static ATTRIBUTES_3D To3DAttributes(GameObject go, Rigidbody rigidbody = null) { ATTRIBUTES_3D result = go.transform.To3DAttributes(); if ((bool)rigidbody) { result.velocity = rigidbody.velocity.ToFMODVector(); } return(result); }
protected override void InitializeEventInstance(EventInstance eventInstance) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (!(null == m_mapCharacterObject)) { ATTRIBUTES_3D val = FMODUtility.To3DAttributes(m_mapCharacterObject.get_transform()); eventInstance.set3DAttributes(val); } }
public static ATTRIBUTES_3D To3DAttributes(GameObject go, Rigidbody2D rigidbody) { ATTRIBUTES_3D result = go.transform.To3DAttributes(); if ((bool)rigidbody) { Vector2 velocity = rigidbody.velocity; VECTOR velocity2 = default(VECTOR); velocity2.x = velocity.x; Vector2 velocity3 = rigidbody.velocity; velocity2.y = velocity3.y; velocity2.z = 0f; result.velocity = velocity2; } return(result); }
public static void Initialize() { CheckResult(FMOD.Studio.System.create(out system)); CheckResult(system.initialize(512, FMOD.Studio.INITFLAGS.NORMAL, FMOD.INITFLAGS.NORMAL, IntPtr.Zero)); CheckResult(system.loadBankFile(@"assets\Audio\Desktop\Master.bank", LOAD_BANK_FLAGS.NORMAL, out _)); CheckResult(system.loadBankFile(@"assets\Audio\Desktop\Master.strings.bank", LOAD_BANK_FLAGS.NORMAL, out _)); cachedEventDescriptions = new Dictionary <string, EventDescription>(); attributes3d = new ATTRIBUTES_3D { forward = new VECTOR { x = 0f, y = 0f, z = 1f }, up = new VECTOR { x = 0f, y = 1f, z = 0f } }; }
public void Update(ATTRIBUTES_3D attributes) { PLAYBACK_STATE state; List <EventInstance> list = instances.FindAll(delegate(EventInstance x) { x.getPlaybackState(out state); return(state == PLAYBACK_STATE.STOPPED); }); foreach (EventInstance item in list) { item.release(); } instances.RemoveAll((EventInstance x) => !x.isValid()); foreach (EventInstance instance in instances) { instance.set3DAttributes(attributes); } }
private void Update() { Vector3 velocity = (_prevPosition - _transform.position) / Time.deltaTime; _prevPosition = _transform.position; ATTRIBUTES_3D attributes = new ATTRIBUTES_3D(); attributes.forward = _transform.forward.ToFMODVector(); attributes.up = _transform.up.ToFMODVector(); attributes.position = _transform.position.ToFMODVector(); attributes.velocity = velocity.ToFMODVector(); _emitter.set3DAttributes(attributes); _airspeed = Mathf.Lerp(_airspeed, _wing.AirSpeed, 20f * _clock.DeltaTime); _airspeedParam.setValue(_airspeed); _angleOfAttack = Mathf.Lerp(_angleOfAttack, _wing.AngleOfAttack, 20f * _clock.DeltaTime); _angleOfAttackParam.setValue(_angleOfAttack); }
public RESULT setListenerAttributes(int listener, ATTRIBUTES_3D attributes) { return FMOD_Studio_System_SetListenerAttributes(rawPtr, listener, ref attributes); }
public RESULT getListenerAttributes(int listener, out ATTRIBUTES_3D attributes) { return FMOD_Studio_System_GetListenerAttributes(rawPtr, listener, out attributes); }
private static extern RESULT FMOD_Studio_EventInstance_Set3DAttributes(IntPtr _event, ref ATTRIBUTES_3D attributes);
public RESULT set3DAttributes(ATTRIBUTES_3D attributes) { return FMOD_Studio_EventInstance_Set3DAttributes(rawPtr, ref attributes); }
public RESULT get3DAttributes(out ATTRIBUTES_3D attributes) { return FMOD_Studio_EventInstance_Get3DAttributes(rawPtr, out attributes); }
private static extern RESULT FMOD_Studio_System_SetListenerAttributes(IntPtr studiosystem, int listener, ref ATTRIBUTES_3D attributes);
public void RenderEveryTick(float dt) { ListPool <Sound, LoopingSoundManager> .PooledList pooledList = ListPool <Sound, LoopingSoundManager> .Allocate(); ListPool <int, LoopingSoundManager> .PooledList pooledList2 = ListPool <int, LoopingSoundManager> .Allocate(); ListPool <int, LoopingSoundManager> .PooledList pooledList3 = ListPool <int, LoopingSoundManager> .Allocate(); List <Sound> dataList = sounds.GetDataList(); bool flag = Time.timeScale == 0f; SoundCuller soundCuller = CameraController.Instance.soundCuller; for (int i = 0; i < dataList.Count; i++) { Sound sound = dataList[i]; if ((UnityEngine.Object)sound.transform != (UnityEngine.Object)null) { sound.pos = sound.transform.GetPosition(); if ((UnityEngine.Object)sound.animController != (UnityEngine.Object)null) { Vector3 offset = sound.animController.Offset; sound.pos.x += offset.x; sound.pos.y += offset.y; } } bool flag2 = !sound.IsCullingEnabled || (sound.ShouldCameraScalePosition && soundCuller.IsAudible(sound.pos, sound.falloffDistanceSq)) || soundCuller.IsAudibleNoCameraScaling(sound.pos, sound.falloffDistanceSq); bool isPlaying = sound.IsPlaying; if (flag2) { pooledList.Add(sound); if (!isPlaying) { SoundDescription soundDescription = GetSoundDescription(sound.path); sound.ev = KFMOD.CreateInstance(soundDescription.path); dataList[i] = sound; pooledList2.Add(i); } } else if (isPlaying) { pooledList3.Add(i); } } LoopingSoundParameterUpdater.Sound sound2; foreach (int item in pooledList2) { Sound value = dataList[item]; SoundDescription soundDescription2 = GetSoundDescription(value.path); value.ev.setPaused(flag && value.ShouldPauseOnGamePaused); Vector2 v = value.pos; if (value.ShouldCameraScalePosition) { v = SoundEvent.GetCameraScaledPosition(v); } value.ev.set3DAttributes(RuntimeUtils.To3DAttributes(v)); value.ev.start(); value.flags |= Sound.Flags.PLAYING; if (value.firstParameter != HashedString.Invalid) { value.ev.setParameterValueByIndex(soundDescription2.GetParameterIdx(value.firstParameter), value.firstParameterValue); } if (value.secondParameter != HashedString.Invalid) { value.ev.setParameterValueByIndex(soundDescription2.GetParameterIdx(value.secondParameter), value.secondParameterValue); } sound2 = default(LoopingSoundParameterUpdater.Sound); sound2.ev = value.ev; sound2.path = value.path; sound2.description = soundDescription2; sound2.transform = value.transform; LoopingSoundParameterUpdater.Sound sound3 = sound2; SoundDescription.Parameter[] parameters = soundDescription2.parameters; for (int j = 0; j < parameters.Length; j++) { SoundDescription.Parameter parameter = parameters[j]; LoopingSoundParameterUpdater value2 = null; if (parameterUpdaters.TryGetValue(parameter.name, out value2)) { value2.Add(sound3); } } dataList[item] = value; } pooledList2.Recycle(); foreach (int item2 in pooledList3) { Sound value3 = dataList[item2]; SoundDescription soundDescription3 = GetSoundDescription(value3.path); sound2 = default(LoopingSoundParameterUpdater.Sound); sound2.ev = value3.ev; sound2.path = value3.path; sound2.description = soundDescription3; sound2.transform = value3.transform; LoopingSoundParameterUpdater.Sound sound4 = sound2; SoundDescription.Parameter[] parameters2 = soundDescription3.parameters; for (int k = 0; k < parameters2.Length; k++) { SoundDescription.Parameter parameter2 = parameters2[k]; LoopingSoundParameterUpdater value4 = null; if (parameterUpdaters.TryGetValue(parameter2.name, out value4)) { value4.Remove(sound4); } } if (value3.ShouldCameraScalePosition) { value3.ev.stop(STOP_MODE.IMMEDIATE); } else { value3.ev.stop(STOP_MODE.ALLOWFADEOUT); } value3.flags &= ~Sound.Flags.PLAYING; value3.ev.release(); dataList[item2] = value3; } pooledList3.Recycle(); float velocityScale = TuningData <Tuning> .Get().velocityScale; foreach (Sound item3 in pooledList) { Sound current3 = item3; ATTRIBUTES_3D attributes = SoundEvent.GetCameraScaledPosition(current3.pos).To3DAttributes(); attributes.velocity = (current3.velocity * velocityScale).ToFMODVector(); current3.ev.set3DAttributes(attributes); } foreach (KeyValuePair <HashedString, LoopingSoundParameterUpdater> parameterUpdater in parameterUpdaters) { parameterUpdater.Value.Update(dt); } pooledList.Recycle(); }
private void Update() { if (this.Remote) { return; } PLAYBACK_STATE playback_STATE = PLAYBACK_STATE.STOPPED; if (this.musicTrack != null) { UnityUtil.ERRCHECK(this.musicTrack.getPlaybackState(out playback_STATE)); } if (playback_STATE != PLAYBACK_STATE.STOPPED) { PlayerSfx.MusicPlaying = true; } else { PlayerSfx.MusicPlaying = false; } if (base.transform.hasChanged) { base.transform.hasChanged = false; ATTRIBUTES_3D attributes = UnityUtil.to3DAttributes(this.SfxPlayer, null); PlayerSfx.Set3DAttributes(this.staminaBreathInstance, attributes); PlayerSfx.Set3DAttributes(this.walkyTalkyInstance, attributes); PlayerSfx.Set3DAttributes(this.musicTrack, attributes); PlayerSfx.Set3DAttributes(this.TurtleShellSledLoopInstance, attributes); ATTRIBUTES_3D attributes2 = this.SfxPlayer.transform.position.to3DAttributes(); PlayerSfx.Set3DAttributes(this.afterStormInstance, attributes2); PlayerSfx.Set3DAttributes(this.onOceanInstance, attributes2); } if (this.afterStormInstance != null && !this.afterStormInstance.isValid()) { this.afterStormInstance = null; } this.sledOnTerrain = base.GetComponent <FirstPersonCharacter>().terrainContact; if (this.sledIsPlaying) { UnityUtil.ERRCHECK(this.TurtleShellSledLoopSpeedParameter.setValue(LocalPlayer.Rigidbody.velocity.sqrMagnitude / 200f)); } if (this.sledIsPlaying && LocalPlayer.FpCharacter.Grounded) { UnityUtil.ERRCHECK(this.TurtleShellSledLoopAirParameter.setValue(0f)); } else if (this.sledIsPlaying && !LocalPlayer.FpCharacter.Grounded) { UnityUtil.ERRCHECK(this.TurtleShellSledLoopAirParameter.setValue(1f)); } if (this.sledIsPlaying && LocalPlayer.FpCharacter.inSnow) { UnityUtil.ERRCHECK(this.TurtleShellSledLoopSnowParameter.setValue(1f)); } else if (this.sledIsPlaying && !LocalPlayer.FpCharacter.inSnow) { UnityUtil.ERRCHECK(this.TurtleShellSledLoopSnowParameter.setValue(0f)); } Vector3 vector = (base.GetComponent <Rigidbody>().position - this.prevPosition) / Time.deltaTime; this.prevPosition = base.GetComponent <Rigidbody>().position; Vector3 vector2 = new Vector3(vector.x, 0f, vector.z); this.flatVelocity = vector2.magnitude; if (!this.Buoyancy.InWater) { this.immersed = false; } else if (!this.immersed && !LocalPlayer.FpCharacter.Grounded && LocalPlayer.FpCharacter.IsAboveWaistDeep()) { this.immersed = true; float num = Mathf.Clamp(this.SplashSpeedMaximum - this.SplashSpeedMinimum, 0f, this.SplashSpeedMaximum); float num2 = (this.Buoyancy.LastWaterEnterSpeed - this.SplashSpeedMinimum) / num; if (num2 >= 0f) { EventInstance @event = FMOD_StudioSystem.instance.GetEvent(this.SplashEvent); UnityUtil.ERRCHECK(@event.set3DAttributes(UnityUtil.to3DAttributes(this.SfxPlayer, null))); UnityUtil.ERRCHECK(@event.setParameterValue("speed", Mathf.Clamp01(num2))); UnityUtil.ERRCHECK(@event.start()); UnityUtil.ERRCHECK(@event.release()); } } if (this.Buoyancy.InWater && this.Buoyancy.IsOcean) { if (this.onOceanInstance == null) { this.onOceanInstance = FMODCommon.PlayOneshot("event:/ambient/water/on_ocean", base.transform); } } else if (this.onOceanInstance != null) { UnityUtil.ERRCHECK(this.onOceanInstance.stop(STOP_MODE.ALLOWFADEOUT)); UnityUtil.ERRCHECK(this.onOceanInstance.release()); this.onOceanInstance = null; } }
private void FixedUpdate() { if (!LocalPlayer.FpCharacter.Locked) { Vector3 a = (this.rb.position - this.prevPosition) / Time.deltaTime; Vector3 vector = a - this.prevVelocity; this.prevPosition = this.rb.position; this.prevVelocity = a; this.springVelocity -= vector.y; this.springVelocity -= this.springPos * this.springElastic; this.springVelocity *= this.springDampen; this.springPos += this.springVelocity * Time.deltaTime; this.springPos = Mathf.Clamp(this.springPos, -0.3f, 0.3f); if (Mathf.Abs(this.springVelocity) < this.springVelocityThreshold && Mathf.Abs(this.springPos) < this.springPositionThreshold) { this.springVelocity = 0f; this.springPos = 0f; } Vector3 vector2 = new Vector3(a.x, 0f, a.z); float magnitude = vector2.magnitude; float num = 1f + magnitude * this.bobStrideSpeedLengthen; this.headBobCycle += magnitude / num * (Time.deltaTime / this.headBobFrequency); float num2 = Mathf.Sin(this.headBobCycle * 3.14159274f * 2f); float num3 = Mathf.Sin(this.headBobCycle * 3.14159274f * 2f + 1.57079637f); num2 = 1f - (num2 * 0.5f + 1f); num2 *= num2; Vector3 vector3 = new Vector3(a.x, 0f, a.z); if (vector3.magnitude < 0.1f) { this.headBobFade = Mathf.Lerp(this.headBobFade, 0f, Time.deltaTime); } else { this.headBobFade = Mathf.Lerp(this.headBobFade, 1f, Time.deltaTime); } float num4 = 1f + magnitude * this.bobHeightSpeedMultiplier; float num5 = -this.headBobSideMovement * num3; float num6 = this.springPos * this.jumpLandMove + num2 * this.headBobHeight * this.headBobFade * num4; float num7 = -this.springPos * this.jumpLandTilt; float num8 = num3 * this.headBobSwayAngle * this.headBobFade; if (LocalPlayer.FpCharacter.Grounded && !LocalPlayer.AnimControl.swimming && !LocalPlayer.AnimControl.onRaft && !this.isOnRaft()) { if (this.prevGrounded) { if (this.headBobCycle > this.nextStepTime) { if (PedometerControler.HasPedometer) { LocalPlayer.Stats.PedometerSteps++; if (LocalPlayer.Stats.PedometerSteps % 50 == 0) { EventRegistry.Player.Publish(TfEvent.WalkedSteps, LocalPlayer.Stats.PedometerSteps); } } else { LocalPlayer.Stats.PedometerSteps = 0; } this.nextStepTime = this.headBobCycle + 0.5f; string footstepForPosition = this.GetFootstepForPosition(); EventInstance eventInstance = null; if (FMOD_StudioSystem.instance) { eventInstance = FMOD_StudioSystem.instance.GetEvent(footstepForPosition); } if (eventInstance != null) { ATTRIBUTES_3D attributes = base.transform.position.to3DAttributes(); UnityUtil.ERRCHECK(eventInstance.set3DAttributes(attributes)); float value = LocalPlayer.FpCharacter.CalculateWaterDepth(); float value2 = LocalPlayer.FpCharacter.CalculateSpeedParameter(magnitude); eventInstance.setParameterValue("depth", value); eventInstance.setParameterValue("speed", value2); if (this.surfaceDetector.IsOnGore) { eventInstance.setParameterValue("gore", 1f); } UnityUtil.ERRCHECK(eventInstance.start()); UnityUtil.ERRCHECK(eventInstance.release()); } } } else { float num9 = Time.time - this.airborneStartTime; if (this.airborneStartTime > 0f && num9 > this.airTimeThreshold) { string landEventForPosition = this.GetLandEventForPosition(); EventInstance eventInstance2 = null; if (FMOD_StudioSystem.instance) { eventInstance2 = FMOD_StudioSystem.instance.GetEvent(landEventForPosition); } if (eventInstance2 != null) { eventInstance2.setParameterValue("depth", LocalPlayer.FpCharacter.CalculateWaterDepth()); if (this.surfaceDetector.IsOnGore) { eventInstance2.setParameterValue("gore", 1f); } UnityUtil.ERRCHECK(eventInstance2.set3DAttributes(UnityUtil.to3DAttributes(base.gameObject, null))); UnityUtil.ERRCHECK(eventInstance2.start()); UnityUtil.ERRCHECK(eventInstance2.release()); } this.nextStepTime = this.headBobCycle + 0.5f; this.PlayLandVocals(); } } this.airborneStartTime = 0f; } else if (this.prevGrounded) { this.airborneStartTime = Time.time; } this.prevGrounded = LocalPlayer.FpCharacter.Grounded; } }
private static extern RESULT FMOD_Studio_System_GetListenerAttributes(IntPtr studiosystem, out ATTRIBUTES_3D attributes);