void Slide(float to) { if (anim.Animate(new UIAnimator.Slide(slideTime, to, () => { // Normalize positions inactiveContainer.RectTransform.SetAnchoredPositionX(0f); activeContainer.RectTransform.SetAnchoredPositionX(-to); RectTransform.SetAnchoredPositionX(0f); // Unload the previous view activeContainer.UnloadView(); // Swap the active and inactive containers UpdateActiveContainer(); // Inform the newly active container that the animation has finished & input is being accepted activeContainer.SetInputEnabled(); // Enable the raycaster so that input is accepted again (small pause so that players don't accidently 'double press' buttons) Co.WaitForSeconds(0.05f, () => { Raycaster.enabled = true; }); }))) { // Disable the raycaster while animating so that the user can't "double press" buttons Raycaster.enabled = false; inactiveContainer.RectTransform.SetAnchoredPositionX(-to); } }
public void RunCoinToAvatarAnimation(string coinCount, string avatarColor) { // Introduce the coin AnimElementUI coin = CreateAnimation(); coin.SpriteName = "coin"; coin.Text = "+" + coinCount; coin.Size = new Vector2(50, 50); coin.LocalPosition = new Vector3(-50, 25, 0); coin.TextPadding = new Vector2(-10, 0); coin.Animate(new UIAnimator.Expand(0.5f)); Co.WaitForSeconds(1f, () => { // Introduce the avatar Vector3 avatarPosition = new Vector3(50, 25f, 0); AnimElementUI avatar = CreateAnimation(); avatar.AvatarName = avatarColor; avatar.Size = new Vector2(75, 75); avatar.LocalPosition = avatarPosition; avatar.Animate(new UIAnimator.Expand(0.5f)); Co.WaitForSeconds(1f, () => { // Move the coin to the avatar and shrink out coin.Animate(new UIAnimator.Move(1f, avatarPosition, () => { coin.Destroy(); avatar.Animate(new UIAnimator.Shrink(0.5f, () => { avatar.Destroy(); })); })); }); }); }
void RunPlayerAnimation() { if (data.PlayerCoinCount > 0 && Elements["instruction2"].Visible && !animationsRun["player"]) { if (data.IsDecider) { Co.WaitForSeconds(0.5f, () => { AnimElementUI coin = CreateAnimation(); coin.SpriteName = "coin"; coin.Text = "+" + data.PlayerCoinCount.ToString(); coin.Size = new Vector2(100, 100); coin.TextPadding = new Vector2(-10, 0); coin.Animate(new UIAnimator.Expand(1.5f, () => { Co.WaitForSeconds(1f, () => { coin.Animate(new UIAnimator.Shrink(1.5f, () => { coin.Destroy(); })); }); })); }); } else { RunCoinAnimation(data.PlayerCoinCount.ToString(), data.PlayerAvatarColor); } animationsRun["player"] = true; } }
public void Show(string message, Color color) { text.text = message; panel.SetActive(true); panel.GetComponent <Image>().color = color; Co.WaitForSeconds(3, Hide); }
protected override void OnInputEnabled() { // Introduce the coin AnimElementUI coin = CreateAnimation(); coin.SpriteName = "coin"; coin.Text = "+" + data.CoinCount.ToString(); coin.Size = new Vector2(50, 50); coin.LocalPosition = new Vector3(-50, 25, 0); coin.Animate(new UIAnimator.Expand(0.5f)); Co.WaitForSeconds(1f, () => { // Introduce the avatar Vector3 avatarPosition = new Vector3(50, 25f, 0); AnimElementUI avatar = CreateAnimation(); avatar.AvatarName = data.PlayerAvatarColor; avatar.Size = new Vector2(75, 75); avatar.LocalPosition = avatarPosition; avatar.Animate(new UIAnimator.Expand(0.5f)); Co.WaitForSeconds(0.5f, () => { coin.Animate(new UIAnimator.Shrink(0.5f)); Co.WaitForSeconds(0.5f, () => { avatar.Animate(new UIAnimator.Spin(0.5f, () => { avatar.Animate(new UIAnimator.Shrink(0.5f)); })); }); }); }); }
public void DelayedFadeIn(float delay = 0.75f, float fadeTime = 0.5f) { Alpha = 0f; Co.WaitForSeconds(delay, () => { Animate(new UIAnimator.FadeIn(fadeTime)); }); }
void RunPotAnimation() { if (Elements["instruction4"].Visible && !animationsRun["pot"]) { Co.WaitForSeconds(0.5f, () => { int potStartCount = data.PotCount; int potEndCount = (int)(potStartCount * 1.5f); AnimElementUI pot = CreateAnimation(); pot.SpriteName = "coin_stack"; pot.Text = potStartCount.ToString(); pot.Size = new Vector2(100, 100); pot.TextPadding = new Vector2(-60, 0); pot.Animate(new UIAnimator.Expand(1.5f)); Co.WaitForSeconds(4f, () => { Co.StartCoroutine(2.5f, (float p) => { pot.Text = Mathf.Ceil(Mathf.Lerp(potStartCount, potEndCount, p)).ToString(); }); Co.WaitForSeconds(0.5f, () => { pot.Animate(new UIAnimator.Shrink(2f)); }); }); }); animationsRun["pot"] = true; } }
protected override void OnInputEnabled() { Co.WaitForSeconds(5f, () => { Elements["timeout"].Animate(new UIAnimator.FadeIn(0.5f, () => { Elements["menu"].Animate(new UIAnimator.FadeIn(0.5f)); })); }); }
protected override void OnShow() { Co.WaitForSeconds(0.2f, () => { // Ugly, but necessary because GameController hasn't loaded the game data by this point (typically you'd be better off with Game.Controller.Avatar) Game.Audio.Play(AssetLoader.GetPlayerAudioFilename(Game.Manager.Players[Name].Avatar)); }); foreach (var player in Game.Manager.Players) { OnAddPeer(player.Key, player.Value.Avatar); } Game.Manager.onAddPeer += OnAddPeer; Game.Manager.onRemovePeer += OnRemovePeer; }
/// <summary> /// Repeatedly invokes a function as long as the condition is met /// </summary> /// <param name="time">(optional) The initial delay before invoking begins</param> /// <param name="rate">The delay between invoke calls</param> /// <param name="condition">The expression to evaluate. When 'condition' is false, the coroutine stops.</param> /// <param name="onEnd">(optional) A function to run after the coroutine has finished</param> public static void InvokeWhileTrue(float time, float rate, Func <bool> condition, Action onInvoke, Action onEnd = null) { float duration = time > 0f ? time : rate; Co.WaitForSeconds(duration, () => { if (condition()) { onInvoke(); InvokeWhileTrue(0f, rate, condition, onInvoke, onEnd); } else if (onEnd != null) { onEnd(); } }); }
void Spin() { if (!spinning) { spinning = true; Co.WaitForSeconds(Random.Range(5, 8), () => { RectTransform r = avatar.GetComponent <RectTransform> (); if (Random.value > 0.5f) { Animate(new UIAnimator.Spin(1f), r); } else { Animate(new UIAnimator.Bump(1f, 1.25f), r); } spinning = false; Spin(); }); } }
protected override void OnInputEnabled() { Co.WaitForSeconds(1f, () => { // Show avatar Elements["avatar"].Animate(new UIAnimator.Expand(1f)); Co.WaitForSeconds(0.5f, () => { // Show winner's name Elements["winner_name"].Animate(new UIAnimator.Expand(1f)); Co.WaitForSeconds(0.5f, () => { // Show winnings Elements["coins_won"].Animate(new UIAnimator.Expand(1f, () => { Elements["next"].Visible = true; Elements["next"].Animate(new UIAnimator.FadeIn(0.5f)); })); }); }); }); }
protected override void OnInputEnabled() { List <AvatarInlineElementUI> childElements = SortPlayers(); int counter = 0; Co.WaitForSeconds(1f, () => { Avatar.gameObject.SetActive(true); Avatar.RandomAnimations = false; Co.InvokeWhileTrue(2.5f, 0.33f, () => { return(counter < childElements.Count); }, () => { childElements[counter].Animate(new UIAnimator.FadeIn(0.75f)); counter++; }, () => { Co.WaitForSeconds(0.75f, () => { ContinueButton.Visible = true; ContinueButton.Animate(new UIAnimator.FadeIn(0.5f)); }); }); }); }
void RunWinnerAnimation() { if (Elements["instruction3"].Visible && !animationsRun["winner"]) { Co.WaitForSeconds(0.5f, () => { AnimElementUI trophy = CreateAnimation(); trophy.SpriteName = "trophy"; trophy.Size = new Vector2(100, 100); trophy.Animate(new UIAnimator.Expand(1f)); trophy.Animate(new UIAnimator.Spin(1f)); Co.WaitForSeconds(3.5f, () => { trophy.Animate(new UIAnimator.Spin(1f)); trophy.Animate(new UIAnimator.Shrink(1f, () => { trophy.Destroy(); })); }); }); animationsRun["winner"] = true; } }
protected override void OnInputEnabled() { List <AvatarInlineElementUI> childElements = SortPlayers(); int counter = childElements.Count - 1; Co.InvokeWhileTrue(0.5f, 2f, () => { return(counter >= 0); }, () => { childElements[counter].PlayAudio(); childElements[counter].Animate(new UIAnimator.FadeIn(0.75f)); counter--; }, () => { Co.WaitForSeconds(0.75f, () => { ContinueButton.Visible = true; ContinueButton.Animate(new UIAnimator.FadeIn(0.5f)); }); TextElementUI instructions; if (TryGetElement <TextElementUI> ("decider_instructions", out instructions)) { instructions.Visible = true; instructions.Animate(new UIAnimator.FadeIn(0.5f)); } }); }
void RunCoinAnimation(string coinCount, string avatarColor) { Co.WaitForSeconds(0.5f, () => { AnimationContainer.RunCoinToAvatarAnimation(coinCount, avatarColor); }); }
void GotoView(NetMessage msg) { Co.YieldWhileTrue(() => { return(Animating); }, () => { Co.WaitForSeconds(0.5f, () => { switch (msg.str1) { case "deck": if (Hosting) { PressRadioButton("deck_list", "Civic"); } break; case "pot": case "bio": case "agenda": case "question": case "think_instructions": case "pitch_instructions": case "deliberate_instructions": case "winner": case "agenda_item_accept": case "agenda_item_reject": case "scoreboard": PressNext(); break; case "roles": if (IsDecider) { PressButton("play"); } break; case "think": if (IsDecider) { PressTimerButton(); } break; case "pitch": if (IsDecider) { PressTimerButton(); } else { Co.YieldWhileTrue(() => { return(Game.Views.CurrView != "extra_time"); }, () => { GotoView(NetMessage.Create("GotoView", "extra_time")); }); } break; case "extra_time": case "extra_time_deliberate": PressButton("decline"); break; case "deliberate": if (IsDecider) { PressTimerButton(); } else { Co.YieldWhileTrue(() => { return(Game.Views.CurrView != "extra_time_deliberate"); }, () => { GotoView(NetMessage.Create("GotoView", "extra_time_deliberate")); }); } break; case "decide": if (IsDecider) { PressListButton("peer_list", Game.Controller.PeerNames[0]); PressButton("confirm"); } break; case "agenda_item": if (IsDecider) { bool accept = Random.value > 0.5f; if (accept) { PressButton("accept"); } else { PressButton("reject"); } } break; } }); }); }