private void OnEnable() { triggerSignal.onValueChanged += SignalChanged; if (triggerSignal.value > treshold || (playOnReverse && triggerSignal.value < 0f - treshold)) { sound.SetPitch(Mathf.Lerp(pitchLow, pitchHigh, Mathf.Abs(triggerSignal.value))); sound.Play(); } }
private void Update() { float f = Mathf.InverseLerp(0f, 2000f, force.magnitude); f = Mathf.Sqrt(f); float num = Vector3.Dot(boom.transform.right, force.normalized); num = Mathf.Clamp(num * 100f, -1f, 1f); float num2 = Mathf.Abs(Vector3.Dot(rhs: (wind - boom.GetPointVelocity(forcePoint.position)).normalized, lhs: boom.transform.right)); float num3 = Mathf.Sqrt(1f - num2 * num2); float time = ReplayRecorder.time; float num4 = lastFrameTime - time; lastFrameTime = time; phaseOpen += num4 * f * f * 100f; phaseFill += num4 * f * 5f; float value = num2 * num * f; float value2 = num3 * num * f; value = Smoothing.SmoothValue(smoothFill, value); value2 = Smoothing.SmoothValue(smoothOpen, value2); SetSignedShape(0, 150f * value + Mathf.Sin(phaseFill) * Mathf.Lerp(5f, 0f, f * 10f)); SetSignedShape(2, 150f * value2 + Mathf.Sin(phaseOpen) * Mathf.Lerp(10f, 5f, f)); if (sailSound != null) { sailSound.SetPitch(Mathf.Lerp(0.4f, 1.2f, f)); sailSound.SetVolume(Mathf.Lerp(0.2f, 1f, f)); } }
private void SyncAudio() { if (sound == null) { return; } int num = isHot ? Mathf.Clamp(coalList.Count, 0, 5) : 0; if (currentAudio == num) { return; } currentAudio = num; if (num == 0) { if (sound.isPlaying) { sound.Stop(); } return; } sound.SetPitch(0.9f + (float)currentAudio * 0.1f); sound.SetVolume(0.5f + fireVolume * 0.1f); sound.Switch((char)(65 + num - 1)); if (!sound.isPlaying) { sound.Play(forceLoop: true); } }
private void SignalChanged(float val) { if (sound != null) { sound.SetPitch(Mathf.Lerp(minPitch, maxPitch, val)); sound.SetVolume(Mathf.Lerp(minVolume, maxVolume, val)); } else { source.pitch = Mathf.Lerp(minPitch, maxPitch, val); source.volume = Mathf.Lerp(minVolume, maxVolume, val); } }
private void FixedUpdate() { float num = 0f; num = ((!(triggerSignal != null)) ? input.value : triggerSignal.value); if (motorSound != null) { if (num != 0f && !motorSound.isPlaying) { motorSound.Play(); char choice = (!(floatingmesh.sensor.waterBody == null)) ? 'A' : 'B'; motorSound.Switch(choice); } else if (num == 0f && motorSound.isPlaying) { motorSound.Stop(); } } else if (servoSound != null) { if (num != 0f && !servoSound.isPlaying) { servoSound.Play(); bool flag = floatingmesh.sensor.waterBody == null; servoSound.secondMedium = (flag && servoSound.loopClips2.Length > 0); } else if (num == 0f && servoSound.isPlaying) { servoSound.Stop(); } } Rigidbody rigidbody = this.rigidbody; float magnitude = rigidbody.velocity.magnitude; if (num != 0f) { rigidbody.SafeAddForceAtPosition(forcePoint.forward * (force + forceLinear * magnitude + forceSquare * magnitude * magnitude) * num, forcePoint.position); } if (motorSound != null) { char choice2 = (!(floatingmesh.sensor.waterBody == null)) ? 'A' : 'B'; motorSound.Switch(choice2); motorSound.SetPitch(Mathf.Lerp(pitchLow, pitchHigh, Mathf.Abs(num))); } else { if (!(servoSound != null)) { return; } bool flag2 = floatingmesh.sensor.waterBody == null && servoSound.loopClips2.Length > 0; if (servoSound.secondMedium != flag2) { servoSound.secondMedium = flag2; if (num != 0f) { servoSound.CrossfadeLoop(); } } servoSound.SetPitch(Mathf.Lerp(pitchLow, pitchHigh, Mathf.Abs(num))); } }
private void FixedUpdate() { float value = triggerSignal.value; value = ((value < deadzoneFrom) ? ((value - deadzoneFrom) / (1f + deadzoneFrom)) : ((!(value > deadzoneTo)) ? 0f : ((value - deadzoneTo) / (1f + deadzoneTo)))); float num = (!(powerSignal != null)) ? 1f : (powerSignal.value / neededVoltage); if (Mathf.Abs(num) < 0.5f) { num = 0f; value = 0f; } if (oldPower != num) { PowerChanged(Mathf.Abs(num)); } oldPower = num; value *= num; float num2 = maxVelocity * value; if (timeToAccelerate == 0f) { velocity = num2; } else { if (velocity > 0f && num2 <= velocity) { velocity = Mathf.Max(0f, num2); } if (velocity < 0f && num2 >= velocity) { velocity = Mathf.Min(0f, num2); } velocity = Mathf.MoveTowards(velocity, num2, maxVelocity * Time.fixedDeltaTime / timeToAccelerate); } if (velocity != 0f) { if (stopSoundOnStop && Mathf.Sign(velocity) == blockedDirection) { return; } blockedDirection = 0f; if (sound != null) { if (!sound.isPlaying) { sound.Play(); } } else if (servoSound != null && !servoSound.isPlaying) { servoSound.Play(); } float num3 = targetValue; targetValue = Mathf.Clamp(targetValue + velocity * Time.fixedDeltaTime, minValue, maxValue); if (targetValue == num3) { timeStopped += Time.fixedDeltaTime; if (timeStopped > resetSignalDelay) { if (resetSignalOnStop) { triggerSignal.ResetSignal(); } if (stopSoundOnStop) { if (sound != null) { sound.Stop(); } else { servoSound.Stop(); } blockedDirection = Mathf.Sign(velocity); } } } else { blockedDirection = 0f; timeStopped = 0f; } if (sound != null) { sound.SetPitch(((!(velocity > 0f)) ? pitchNegative : pitchPositive) * ((targetValue != num3) ? 1f : pitchLimit)); } else if (servoSound != null) { servoSound.SetPitch(((!(velocity > 0f)) ? pitchNegative : pitchPositive) * ((targetValue != num3) ? 1f : pitchLimit)); } TargetValueChanged(targetValue); } else if (sound != null) { if (sound.isPlaying) { sound.Stop(); } } else if (servoSound != null && servoSound.isPlaying) { servoSound.Stop(); } }