using System; using UnityEngine; public class RefuelStage : MonoBehaviour { public NormalPlayerTask MyNormTask { get; set; } public float RefuelDuration = 5f; private Color darkRed = new Color32(90, 0, 0, byte.MaxValue); private Color red = new Color32(byte.MaxValue, 58, 0, byte.MaxValue); private Color green = Color.green; public SpriteRenderer redLight; public SpriteRenderer greenLight; public VerticalGauge srcGauge; public VerticalGauge destGauge; public AudioClip RefuelSound; private float timer; private bool isDown; private bool complete; public void Begin() { this.timer = (float)this.MyNormTask.Data[0] / 255f; } public void FixedUpdate() { if (this.complete) { return; } if (this.isDown && this.timer < 1f) { this.timer += Time.fixedDeltaTime / this.RefuelDuration; this.MyNormTask.Data[0] = (byte)Mathf.Min(255f, this.timer * 255f); if (this.timer >= 1f) { this.complete = true; this.greenLight.color = this.green; this.redLight.color = this.darkRed; this.MyNormTask.Data[0] = 0; byte[] data = this.MyNormTask.Data; int num = 1; data[num] += 1; if (this.MyNormTask.Data[1] % 2 == 0) { this.MyNormTask.NextStep(); } this.MyNormTask.UpdateArrow(); } } this.destGauge.value = this.timer; if (this.srcGauge) { this.srcGauge.value = 1f - this.timer; } } public void Refuel() { if (this.complete) { base.transform.parent.GetComponent().Close(); return; } this.isDown = !this.isDown; this.redLight.color = (this.isDown ? this.red : this.darkRed); if (this.isDown) { if (Constants.ShouldPlaySfx()) { SoundManager.Instance.PlayDynamicSound("Refuel", this.RefuelSound, true, new DynamicSound.GetDynamicsFunction(this.GetRefuelDynamics), true); return; } } else { SoundManager.Instance.StopSound(this.RefuelSound); } } private void GetRefuelDynamics(AudioSource player, float dt) { player.volume = 1f; player.pitch = Mathf.Lerp(0.75f, 1.25f, this.timer); } }