private new void MouseMove(object sender, MouseEventArgs e) { Timer dest = new Timer(1000) { AutoReset = false }; Ellipse x = new Ellipse(); x = shape.CreateEllipse(e.GetPosition(this).X, e.GetPosition(this).Y); c.Children.Add(x); anims.Animate(x); dest.Start(); dest.Elapsed += (object s, ElapsedEventArgs ee) => { try { this.Dispatcher.Invoke(() => { c.Children.Remove(x); dest.Dispose(); }); } catch (Exception w) { } }; }
private async Task Animate(GameObject target, Vector2 delta, TimingFunction timing) { var p0 = target.transform.localPosition; var p1 = p0 + (Vector3)delta; var anim = Animations.Animate(animationTime, timing); while (!anim.isComplete) { await anim.NextFrame(); target.transform.localPosition = Vector3.Lerp(p0, p1, anim.progress); } }
private async Task Fade(Image target, float alpha, float timeMultiplier, TimingFunction timing) { var c0 = target.color; var c1 = c0; c1.a = alpha; var anim = Animations.Animate(animationTime * timeMultiplier, timing); while (!anim.isComplete) { await anim.NextFrame(); target.color = Color.Lerp(c0, c1, anim.progress); } }
private void CreateFloatingText(string a_Message, Color a_Color, Vector3 a_Anchor) { FloatingText newObject = Instantiate(m_FloatingTextPrefab); newObject.transform.SetParent(UIManager.self.backgroundUI.transform, false); newObject.anchor = a_Anchor; Text newText = newObject.GetComponent <Text>(); newText.text = a_Message; newText.color = a_Color; StartCoroutine(Animations.Animate(m_FloatingTextSequence, newText)); StartCoroutine(WaitThenDoThis(m_FloatingTextSequence.totalAnimationTime, delegate { Destroy(newText.gameObject); })); }
public void Chat(string a_Nickname, string a_Message, Unit a_Unit, ChatType a_ChatType = ChatType.Say) { Text newLogItem = Instantiate(m_LogTextPrefab); newLogItem.transform.SetParent(UIManager.self.backgroundUI.transform, false); switch (a_ChatType) { case ChatType.Say: newLogItem.color = Color.black; newLogItem.text = a_Nickname + " says: " + a_Message; break; case ChatType.Yell: newLogItem.color = Color.red; newLogItem.text = a_Nickname + " yells: " + a_Message; break; } FloatingText newObject = Instantiate(m_FloatingTextPrefab); newObject.transform.SetParent(UIManager.self.backgroundUI.transform, false); newObject.anchor = new Vector3(0, 1f, 0); newObject.parent = a_Unit; Text newText = newObject.GetComponent <Text>(); newText.text = a_Message + "\n|"; newText.color = newLogItem.color; StartCoroutine(Animations.Animate(m_ChatSequence, newText)); StartCoroutine(WaitThenDoThis(m_ChatSequence.totalAnimationTime, delegate { Destroy(newText.gameObject); })); StartCoroutine(AnimateToLog(newLogItem)); }
private async Task MoveCamera(Vector3 delta) { moving = true; PlayerController.Frozen = true; var p0 = camera.transform.position; var p1 = p0 + delta; dayNightCycle.Advance(3); var move = Animations.Animate(CameraTime, Animations.EaseInOutQuadratic); while (!move.isComplete) { if (!Physics.IsEnabled) { await Util.NextFrame(); continue; } await move.NextFrame(); if (this == null) { return; } var lastPos = camera.transform.position; var nextPos = Vector3.Lerp(p0, p1, move.progress); camera.transform.position = nextPos; Parallax.parallax?.Invoke(nextPos - lastPos); levelScreen.alpha = move.progress; } PlayerController.Frozen = false; moving = false; }
private IEnumerator AnimateText() { m_CoroutineIsRunning = true; m_CurrentAnnouncementObject.transform.localScale = new Vector3(0, 0, 0); yield return(StartCoroutine(Animations.Animate(m_AnnouncementSequence, m_CurrentAnnouncementObject))); Text newLogItem = Instantiate(m_LogTextPrefab); newLogItem.transform.SetParent(UIManager.self.backgroundUI.transform, false); newLogItem.text = m_CurrentAnnouncementObject.text; Destroy(m_CurrentAnnouncementObject.gameObject); m_CoroutineIsRunning = false; if (m_QueuedAnnouncements.Count > 0) { CreateNewAnnouncement(); } StartCoroutine(AnimateToLog(newLogItem)); }
public async void GoToLevel(int index, bool transition) { if (index < 0 || index >= levels.Length) { return; } levels[index].start.MarkReached(); levelScreen.alpha = 1; foreach (var t in levelNumber) { t.text = $"{World}-{index + 1}"; } foreach (var t in levelName) { t.text = levels[index].title; } levelScreen.gameObject.SetActive(true); if (transition) { if (LevelTransitionSound != null) { audioSource.PlayOneShot(LevelTransitionSound); } var from = currentLevel; currentIndex = index; var delta = currentLevel.transform.position - from.transform.position; await MoveCamera(delta); if (this == null) { return; } } else { currentIndex = index; player.transform.rotation = currentLevel.start.transform.rotation; playerFlip.down = Util.Round(currentLevel.start.transform.rotation * Vector2.down); playerPhysics.velocity = Vector2.zero; playerPhysics.position = Physics.FromUnity(currentLevel.start.transform.position); playerPhysics.UpdatePosition(); levelScreen.alpha = 1; Parallax.parallax?.Invoke(currentLevel.transform.position - camera.transform.position); var pos = currentLevel.transform.position; pos.z = camera.transform.position.z; camera.transform.position = pos; } CurrentLevel = currentLevel; player.UpdateMovement(); border.Move(currentLevel.transform.position); restartState?.Dispose(); restartState = new SaveState(this); foreach (var item in undoStack) { item.Dispose(); } undoStack.Clear(); UpdateColliders(); var delay = Animations.Animate(2f, Animations.Linear); while (!delay.isComplete) { if (!Physics.IsEnabled) { levelScreen.alpha = 0; return; } await delay.NextFrame(); if (this == null || index != currentIndex) { return; } } var fadeOut = Animations.Animate(CameraTime, Animations.Linear); while (!fadeOut.isComplete) { if (!Physics.IsEnabled) { levelScreen.alpha = 0; return; } await fadeOut.NextFrame(); if (this == null || index != currentIndex) { return; } levelScreen.alpha = 1 - fadeOut.progress; } levelScreen.alpha = 0; levelScreen.gameObject.SetActive(false); }
public async void DoFlip(Vector2 down, int input) { if (isFlipping != null) { return; } FlipKind flip; if (input == 1) { flip = flip1; } else { flip = flip2; } Quaternion delta; switch (flip) { case FlipKind.CW: delta = Quaternion.AngleAxis(90, Vector3.back); break; case FlipKind.CCW: delta = Quaternion.AngleAxis(-90, Vector3.back); break; case FlipKind.Horizontal: delta = Quaternion.AngleAxis(-180, down); break; case FlipKind.Vertical: var axis = Quaternion.AngleAxis(90, Vector3.back) * down; delta = Quaternion.AngleAxis(-180, axis); break; default: return; } var overlaps = Physics.AllOverlaps(physics) .Select(o => (o.Item1, o.Item2, o.Item1.GetComponent <Flippable>())) .Where(o => o.Item3 != null) .ToList(); var partials = overlaps .Where(o => o.Item1.bounds != o.Item2) .ToList(); if (partials.Any()) { foreach (var partial in partials) { ShowFlipError(partial.Item2); } return; } var objects = overlaps.Select(o => o.Item3).ToList(); isFlipping = this; audioSource.PlayOneShot(FlipSound); var levelController = FindObjectOfType <LevelController>(); levelController?.SaveUndoState(); var parents = objects.Select(o => o.transform.parent).ToList(); foreach (var o in objects) { o.transform.SetParent(transform, true); o.DoBeginFlip(); } var cancelled = false; cancelFlip = () => { cancelled = true; foreach (var(o, parent) in objects.Zip(parents, (l, r) => (l, r))) { o.transform.SetParent(parent, true); o.DoEndFlip(delta); } cancelFlip = null; }; var originalPos = transform.position; transform.position = originalPos + new Vector3(0, 0, -5); var q0 = transform.rotation; var q1 = delta * q0; var anim = Animations.Animate(FlipTime, Animations.EaseInOutSine); while (!anim.isComplete) { if (!Physics.IsEnabled) { await Util.NextFrame(); continue; } await anim.NextFrame(); if (cancelled || this == null) { return; } transform.rotation = Quaternion.Lerp(q0, q1, anim.progress); } transform.position = originalPos; cancelFlip(); foreach (var o in objects) { var collider = o.GetComponentInChildren <MyCollider>(); if (collider is MyStatic || collider is MyDynamic) { var(other, overlap) = Physics.AllCollisions(collider).FirstOrDefault(); if (other != null) { ShowFlipError(overlap); levelController.DoUndo(); break; } } } isFlipping = null; }