diff options
Diffstat (limited to 'Client/Assembly-CSharp/AlignGame.cs')
-rw-r--r-- | Client/Assembly-CSharp/AlignGame.cs | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/AlignGame.cs b/Client/Assembly-CSharp/AlignGame.cs new file mode 100644 index 0000000..1ee70f0 --- /dev/null +++ b/Client/Assembly-CSharp/AlignGame.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections; +using UnityEngine; + +public class AlignGame : Minigame +{ + private Controller myController = new Controller(); + + public FloatRange YRange = new FloatRange(-0.425f, 0.425f); + + public AnimationCurve curve; + + public LineRenderer centerline; + + public LineRenderer[] guidelines; + + public SpriteRenderer engine; + + public Collider2D col; + + public TextController StatusText; + + private float pulseTimer; + + public override void Begin(PlayerTask task) + { + base.Begin(task); + float value = AlignGame.FromByte(this.MyNormTask.Data[base.ConsoleId]); + bool flag = AlignGame.IsSuccess(this.MyNormTask.Data[base.ConsoleId]); + Vector3 localPosition = this.col.transform.localPosition; + localPosition.y = this.YRange.Clamp(value); + float num = this.YRange.ReverseLerp(localPosition.y); + localPosition.x = this.curve.Evaluate(num); + this.col.transform.eulerAngles = new Vector3(0f, 0f, Mathf.Lerp(20f, -20f, num)); + this.engine.transform.eulerAngles = new Vector3(0f, 0f, Mathf.Lerp(45f, -45f, num)); + this.centerline.material.SetColor("_Color", flag ? Color.green : Color.red); + this.engine.color = (flag ? Color.green : Color.red); + this.col.transform.localPosition = localPosition; + this.guidelines[0].enabled = flag; + this.guidelines[1].enabled = flag; + this.StatusText.gameObject.SetActive(flag); + } + + public void Update() + { + this.centerline.material.SetTextureOffset("_MainTex", new Vector2(Time.time, 0f)); + this.guidelines[0].material.SetTextureOffset("_MainTex", new Vector2(Time.time, 0f)); + this.guidelines[1].material.SetTextureOffset("_MainTex", new Vector2(Time.time, 0f)); + if (this.MyTask && this.MyNormTask.IsComplete) + { + return; + } + Vector3 localPosition = this.col.transform.localPosition; + bool flag = AlignGame.IsSuccess(this.MyNormTask.Data[base.ConsoleId]); + bool flag2 = AlignGame.IsSuccess(AlignGame.ToByte(localPosition.y)); + this.myController.Update(); + switch (this.myController.CheckDrag(this.col, false)) + { + case DragState.TouchStart: + this.pulseTimer = 0f; + break; + case DragState.Dragging: + if (!flag) + { + Vector2 vector = this.myController.DragPosition - base.transform.position; + float num = this.YRange.ReverseLerp(localPosition.y); + localPosition.y = this.YRange.Clamp(vector.y); + float num2 = this.YRange.ReverseLerp(localPosition.y); + localPosition.x = this.curve.Evaluate(num2); + this.col.transform.eulerAngles = new Vector3(0f, 0f, Mathf.Lerp(20f, -20f, num2)); + this.engine.transform.eulerAngles = new Vector3(0f, 0f, Mathf.Lerp(45f, -45f, num2)); + this.centerline.material.SetColor("_Color", flag2 ? Color.green : Color.red); + if (Mathf.Abs(num2 - num) > 0.001f) + { + this.pulseTimer += Time.deltaTime * 25f; + int num3 = (int)this.pulseTimer % 3; + if (num3 > 1) + { + if (num3 == 2) + { + this.engine.color = Color.clear; + } + } + else + { + this.engine.color = Color.red; + } + } + else + { + this.engine.color = Color.red; + } + } + break; + case DragState.Released: + if (!flag && flag2) + { + base.StartCoroutine(this.LockEngine()); + this.MyNormTask.Data[base.ConsoleId] = AlignGame.ToByte(localPosition.y); + this.MyNormTask.NextStep(); + base.StartCoroutine(base.CoStartClose(0.75f)); + } + break; + } + this.col.transform.localPosition = localPosition; + } + + private IEnumerator LockEngine() + { + int num; + for (int i = 0; i < 3; i = num) + { + this.guidelines[0].enabled = true; + this.guidelines[1].enabled = true; + yield return new WaitForSeconds(0.1f); + this.guidelines[0].enabled = false; + this.guidelines[1].enabled = false; + yield return new WaitForSeconds(0.1f); + num = i + 1; + } + this.StatusText.gameObject.SetActive(true); + Color green = new Color(0f, 0.7f, 0f); + yield return new WaitForLerp(1f, delegate(float t) + { + this.engine.color = Color.Lerp(Color.white, green, t); + }); + this.guidelines[0].enabled = true; + this.guidelines[1].enabled = true; + yield break; + } + + public static float FromByte(byte b) + { + return (float)b * 0.025f - 3f; + } + + public static byte ToByte(float y) + { + return (byte)((y + 3f) / 0.025f); + } + + public static bool IsSuccess(byte b) + { + return Mathf.Abs(AlignGame.FromByte(b)) <= 0.05f; + } +} |