| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| . | public class ShipEffects : MonoBehaviour |
| public class ShipEffects : MonoBehaviour, IMonoUpdater |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| ZNetView componentInParent = base.GetComponentInParent<ZNetView>(); |
| ZNetView componentInParent = base.GetComponentInParent<ZNetView>(); |
| if (componentInParent && componentInParent.GetZDO() == null) |
| if (componentInParent && componentInParent.GetZDO() == null) |
| { |
| { |
| base.enabled = false; |
| base.enabled = false; |
| return; |
| return; |
| } |
| } |
| this.m_body = base.GetComponentInParent<Rigidbody>(); |
| this.m_body = base.GetComponentInParent<Rigidbody>(); |
| this.m_ship = base.GetComponentInParent<Ship>(); |
| this.m_ship = base.GetComponentInParent<Ship>(); |
| if (this.m_speedWakeRoot) |
| if (this.m_speedWakeRoot) |
| { |
| { |
| this.m_wakeParticles = this.m_speedWakeRoot.GetComponentsInChildren<ParticleSystem>(); |
| this.m_wakeParticles = this.m_speedWakeRoot.GetComponentsInChildren<ParticleSystem>(); |
| } |
| } |
| if (this.m_wakeSoundRoot) |
| if (this.m_wakeSoundRoot) |
| { |
| { |
| foreach (AudioSource audioSource in this.m_wakeSoundRoot.GetComponentsInChildren<AudioSource>()) |
| foreach (AudioSource audioSource in this.m_wakeSoundRoot.GetComponentsInChildren<AudioSource>()) |
| { |
| { |
| audioSource.pitch = UnityEngine.Random.Range(0.9f, 1.1f); |
| audioSource.pitch = UnityEngine.Random.Range(0.9f, 1.1f); |
| this.m_wakeSounds.Add(new KeyValuePair<AudioSource, float>(audioSource, audioSource.volume)); |
| this.m_wakeSounds.Add(new KeyValuePair<AudioSource, float>(audioSource, audioSource.volume)); |
| } |
| } |
| } |
| } |
| if (this.m_inWaterSoundRoot) |
| if (this.m_inWaterSoundRoot) |
| { |
| { |
| foreach (AudioSource audioSource2 in this.m_inWaterSoundRoot.GetComponentsInChildren<AudioSource>()) |
| foreach (AudioSource audioSource2 in this.m_inWaterSoundRoot.GetComponentsInChildren<AudioSource>()) |
| { |
| { |
| audioSource2.pitch = UnityEngine.Random.Range(0.9f, 1.1f); |
| audioSource2.pitch = UnityEngine.Random.Range(0.9f, 1.1f); |
| this.m_inWaterSounds.Add(new KeyValuePair<AudioSource, float>(audioSource2, audioSource2.volume)); |
| this.m_inWaterSounds.Add(new KeyValuePair<AudioSource, float>(audioSource2, audioSource2.volume)); |
| } |
| } |
| } |
| } |
| if (this.m_sailSound) |
| if (this.m_sailSound) |
| { |
| { |
| this.m_sailBaseVol = this.m_sailSound.volume; |
| this.m_sailBaseVol = this.m_sailSound.volume; |
| this.m_sailSound.pitch = UnityEngine.Random.Range(0.9f, 1.1f); |
| this.m_sailSound.pitch = UnityEngine.Random.Range(0.9f, 1.1f); |
| } |
| } |
| } |
| } |
| |
| |
| private void OnEnable() |
| private void OnEnable() |
| { |
| { |
| ShipEffects.Instances.Add(this); |
| ShipEffects.Instances.Add(this); |
| } |
| } |
| |
| |
| private void OnDisable() |
| private void OnDisable() |
| { |
| { |
| ShipEffects.Instances.Remove(this); |
| ShipEffects.Instances.Remove(this); |
| } |
| } |
| |
| |
| public void CustomLateUpdate(float deltaTime) |
| public void CustomLateUpdate(float deltaTime) |
| { |
| { |
| if (!Floating.IsUnderWater(base.transform.position, ref this.m_previousWaterVolume)) |
| if (!Floating.IsUnderWater(base.transform.position, ref this.m_previousWaterVolume)) |
| { |
| { |
| this.m_shadow.gameObject.SetActive(false); |
| this.m_shadow.gameObject.SetActive(false); |
| this.SetWake(false, deltaTime); |
| this.SetWake(false, deltaTime); |
| this.FadeSounds(this.m_inWaterSounds, false, deltaTime); |
| this.FadeSounds(this.m_inWaterSounds, false, deltaTime); |
| return; |
| return; |
| } |
| } |
| this.m_shadow.gameObject.SetActive(true); |
| this.m_shadow.gameObject.SetActive(true); |
| bool flag = this.m_body.velocity.magnitude > this.m_minimumWakeVel; |
| bool flag = this.m_body.velocity.magnitude > this.m_minimumWakeVel; |
| this.FadeSounds(this.m_inWaterSounds, true, deltaTime); |
| this.FadeSounds(this.m_inWaterSounds, true, deltaTime); |
| this.SetWake(flag, deltaTime); |
| this.SetWake(flag, deltaTime); |
| if (this.m_sailSound) |
| if (this.m_sailSound) |
| { |
| { |
| float num = (this.m_ship.IsSailUp() ? this.m_sailBaseVol : 0f); |
| float num = (this.m_ship.IsSailUp() ? this.m_sailBaseVol : 0f); |
| ShipEffects.FadeSound(this.m_sailSound, num, this.m_sailFadeDuration, deltaTime); |
| ShipEffects.FadeSound(this.m_sailSound, num, this.m_sailFadeDuration, deltaTime); |
| } |
| } |
| if (this.m_splashEffects != null) |
| if (this.m_splashEffects != null) |
| { |
| { |
| this.m_splashEffects.SetActive(this.m_ship.HasPlayerOnboard()); |
| this.m_splashEffects.SetActive(this.m_ship.HasPlayerOnboard()); |
| } |
| } |
| } |
| } |
| |
| |
| private void SetWake(bool enabled, float dt) |
| private void SetWake(bool enabled, float dt) |
| { |
| { |
| ParticleSystem[] wakeParticles = this.m_wakeParticles; |
| ParticleSystem[] wakeParticles = this.m_wakeParticles; |
| for (int i = 0; i < wakeParticles.Length; i++) |
| for (int i = 0; i < wakeParticles.Length; i++) |
| { |
| { |
| wakeParticles[i].emission.enabled = enabled; |
| wakeParticles[i].emission.enabled = enabled; |
| } |
| } |
| this.FadeSounds(this.m_wakeSounds, enabled, dt); |
| this.FadeSounds(this.m_wakeSounds, enabled, dt); |
| } |
| } |
| |
| |
| private void FadeSounds(List<KeyValuePair<AudioSource, float>> sources, bool enabled, float dt) |
| private void FadeSounds(List<KeyValuePair<AudioSource, float>> sources, bool enabled, float dt) |
| { |
| { |
| foreach (KeyValuePair<AudioSource, float> keyValuePair in sources) |
| foreach (KeyValuePair<AudioSource, float> keyValuePair in sources) |
| { |
| { |
| if (enabled) |
| if (enabled) |
| { |
| { |
| ShipEffects.FadeSound(keyValuePair.Key, keyValuePair.Value, this.m_audioFadeDuration, dt); |
| ShipEffects.FadeSound(keyValuePair.Key, keyValuePair.Value, this.m_audioFadeDuration, dt); |
| } |
| } |
| else |
| else |
| { |
| { |
| ShipEffects.FadeSound(keyValuePair.Key, 0f, this.m_audioFadeDuration, dt); |
| ShipEffects.FadeSound(keyValuePair.Key, 0f, this.m_audioFadeDuration, dt); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private static void FadeSound(AudioSource source, float target, float fadeDuration, float dt) |
| private static void FadeSound(AudioSource source, float target, float fadeDuration, float dt) |
| { |
| { |
| float num = dt / fadeDuration; |
| float num = dt / fadeDuration; |
| if (target > 0f) |
| if (target > 0f) |
| { |
| { |
| if (!source.isPlaying) |
| if (!source.isPlaying) |
| { |
| { |
| source.Play(); |
| source.Play(); |
| } |
| } |
| source.volume = Mathf.MoveTowards(source.volume, target, num); |
| source.volume = Mathf.MoveTowards(source.volume, target, num); |
| return; |
| return; |
| } |
| } |
| if (source.isPlaying) |
| if (source.isPlaying) |
| { |
| { |
| source.volume = Mathf.MoveTowards(source.volume, 0f, num); |
| source.volume = Mathf.MoveTowards(source.volume, 0f, num); |
| if (source.volume <= 0f) |
| if (source.volume <= 0f) |
| { |
| { |
| source.Stop(); |
| source.Stop(); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| . | public static List<ShipEffects> Instances { get; } = new List<ShipEffects>(); |
| public static List<IMonoUpdater> Instances { get; } = new List<IMonoUpdater>(); |
| |
| |
| public Transform m_shadow; |
| public Transform m_shadow; |
| |
| |
| public float m_offset = 0.01f; |
| public float m_offset = 0.01f; |
| |
| |
| public float m_minimumWakeVel = 5f; |
| public float m_minimumWakeVel = 5f; |
| |
| |
| public GameObject m_speedWakeRoot; |
| public GameObject m_speedWakeRoot; |
| |
| |
| public GameObject m_wakeSoundRoot; |
| public GameObject m_wakeSoundRoot; |
| |
| |
| public GameObject m_inWaterSoundRoot; |
| public GameObject m_inWaterSoundRoot; |
| |
| |
| public float m_audioFadeDuration = 2f; |
| public float m_audioFadeDuration = 2f; |
| |
| |
| public AudioSource m_sailSound; |
| public AudioSource m_sailSound; |
| |
| |
| public float m_sailFadeDuration = 1f; |
| public float m_sailFadeDuration = 1f; |
| |
| |
| public GameObject m_splashEffects; |
| public GameObject m_splashEffects; |
| |
| |
| private ParticleSystem[] m_wakeParticles; |
| private ParticleSystem[] m_wakeParticles; |
| |
| |
| private float m_sailBaseVol = 1f; |
| private float m_sailBaseVol = 1f; |
| |
| |
| private readonly List<KeyValuePair<AudioSource, float>> m_wakeSounds = new List<KeyValuePair<AudioSource, float>>(); |
| private readonly List<KeyValuePair<AudioSource, float>> m_wakeSounds = new List<KeyValuePair<AudioSource, float>>(); |
| |
| |
| private readonly List<KeyValuePair<AudioSource, float>> m_inWaterSounds = new List<KeyValuePair<AudioSource, float>>(); |
| private readonly List<KeyValuePair<AudioSource, float>> m_inWaterSounds = new List<KeyValuePair<AudioSource, float>>(); |
| |
| |
| private WaterVolume m_previousWaterVolume; |
| private WaterVolume m_previousWaterVolume; |
| |
| |
| private Rigidbody m_body; |
| private Rigidbody m_body; |
| |
| |
| private Ship m_ship; |
| private Ship m_ship; |
| } |
| } |
| |
| |