using System; using System.Collections; using UnityEngine; public class NavigationMinigame : Minigame { public MeshRenderer TwoAxisImage; public SpriteRenderer CrossHairImage; public Collider2D hitbox; private Controller myController = new Controller(); private Vector2 crossHair; private Vector2 half = new Vector2(0.5f, 0.5f); public override void Begin(PlayerTask task) { base.Begin(task); this.crossHair = UnityEngine.Random.insideUnitCircle.normalized / 2f * 0.6f; Vector3 localPosition = new Vector3(this.crossHair.x * this.TwoAxisImage.bounds.size.x, this.crossHair.y * this.TwoAxisImage.bounds.size.y, -2f); this.CrossHairImage.transform.localPosition = localPosition; this.TwoAxisImage.material.SetVector("_CrossHair", this.crossHair + this.half); } public void FixedUpdate() { if (this.MyNormTask && this.MyNormTask.IsComplete) { return; } this.myController.Update(); DragState dragState = this.myController.CheckDrag(this.hitbox, false); if (dragState != DragState.Dragging) { if (dragState != DragState.Released) { return; } if ((this.crossHair - this.half).magnitude < 0.05f) { base.StartCoroutine(this.CompleteGame()); this.MyNormTask.NextStep(); } } else { Vector2 dragPosition = this.myController.DragPosition; Vector2 a = dragPosition - (this.TwoAxisImage.transform.position - this.TwoAxisImage.bounds.size / 2f); this.crossHair = a.Div(this.TwoAxisImage.bounds.size); if ((this.crossHair - this.half).magnitude < 0.45f) { Vector3 localPosition = dragPosition - base.transform.position; localPosition.z = -2f; this.CrossHairImage.transform.localPosition = localPosition; this.TwoAxisImage.material.SetVector("_CrossHair", this.crossHair); return; } } } private IEnumerator CompleteGame() { WaitForSeconds wait = new WaitForSeconds(0.1f); Color green = new Color(0f, 0.8f, 0f, 1f); Color32 yellow = new Color32(byte.MaxValue, 202, 0, byte.MaxValue); this.CrossHairImage.transform.localPosition = new Vector3(0f, 0f, -2f); this.TwoAxisImage.material.SetVector("_CrossHair", this.half); this.CrossHairImage.color = yellow; this.TwoAxisImage.material.SetColor("_CrossColor", yellow); yield return wait; this.CrossHairImage.color = Color.white; this.TwoAxisImage.material.SetColor("_CrossColor", Color.white); yield return wait; this.CrossHairImage.color = yellow; this.TwoAxisImage.material.SetColor("_CrossColor", yellow); yield return wait; this.CrossHairImage.color = Color.white; this.TwoAxisImage.material.SetColor("_CrossColor", Color.white); yield return wait; this.CrossHairImage.color = green; this.TwoAxisImage.material.SetColor("_CrossColor", green); yield return base.CoStartClose(0.75f); yield break; } }