// Refresh score public void Animate(bool immediately) { if (GameManager.instance.players != null && GameManager.instance.players.Count > 0 && GameManager.instance.players.Count <= playerScoreContainer.childCount) { for (int p = 0; p < GameManager.instance.players.Count; p++) { PlayerScoreCell cell = playerScoreContainer.GetChild(p).GetComponent <PlayerScoreCell>(); cell.Animate(immediately); } } }
// Load character info private void LayoutCharacters(bool immediately) { // Unload player data UnloadPlayerData(); // Load players if (GameManager.instance.players != null && GameManager.instance.players.Count > 0) { int leftCount = Mathf.CeilToInt((float)GameManager.instance.players.Count / 2f); float height = leftCount * playerScorePrefab.GetComponent <RectTransform>().rect.height + Mathf.Max(0f, leftCount - 1f) * playerMarginY; float startY = (playerScoreContainer.rect.height - height) / 2f; float y = startY; for (int p = 0; p < GameManager.instance.players.Count; p++) { // Get cell RectTransform playerScoreRect = Pool.instance.Load(playerScorePrefab.gameObject).GetComponent <RectTransform>(); playerScoreRect.gameObject.name = "PLAYER_" + (p + 1).ToString("00"); playerScoreRect.gameObject.SetActive(true); // Set transform playerScoreRect.transform.SetParent(playerScoreContainer); playerScoreRect.transform.localPosition = Vector3.zero; playerScoreRect.transform.localRotation = Quaternion.identity; playerScoreRect.transform.localScale = Vector3.one; if (p < leftCount) { playerScoreRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, playerPaddingX, playerScoreRect.rect.width); playerScoreRect.localScale = Vector3.one; } else { playerScoreRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, playerPaddingX - playerScoreRect.rect.width, playerScoreRect.rect.width); playerScoreRect.localScale = new Vector3(-1f, 1f, 1f); } playerScoreRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, y, playerScoreRect.rect.height); y += playerScoreRect.rect.height + playerMarginY; if (p + 1 == leftCount) { y = startY; } // Set player items PlayerScoreCell cell = playerScoreRect.GetComponent <PlayerScoreCell>(); cell.characterName.transform.localScale = playerScoreRect.localScale; cell.scoreMaxLabel.transform.parent.localScale = playerScoreRect.localScale; cell.LayoutInterface(p); } } }
// Refresh interface protected virtual void SetInterface(int playerIndex) { // Get tint Color tint = GameManager.instance.GetPlayerColor(playerIndex); // Reset snatched LeanTween.cancel(snatchedGroup.gameObject, false); snatchedGroup.alpha = 0f; snatchedIcon.color = tint; snatchedGroup.transform.localScale = Vector3.one * snatchedScaleStart; // Reset plus one LeanTween.cancel(plusOneGroup.gameObject, false); plusOneGroup.alpha = 0f; plusOneIcon.color = tint; RectTransform plusRect = plusOneGroup.GetComponent <RectTransform>(); Vector3 worldPos = Vector3.zero; foreach (GridProp prop in GridManager.instance.props) { if (prop != null && prop.data != null && prop.data.isWinProp) { worldPos = prop.transform.position; break; } } Vector3 screenPos = Camera.main.WorldToScreenPoint(worldPos); Vector2 plusStart = new Vector2(screenPos.x, screenPos.y); plusStart *= 1080f / (float)Screen.height; plusStart += plusOneOffsetStart; plusRect.anchoredPosition = plusStart; // Get plus one end RectTransform parent = scoreOverlay.playerScoreContainer; PlayerScoreCell scoreCell = scoreOverlay.playerScoreContainer.GetChild(playerIndex).GetComponent <PlayerScoreCell>(); Vector2 plusEnd = scoreCell.playerPosition; plusEnd += new Vector2(scoreCell.transform.localScale.x < 1 ? parent.rect.width - plusOneOffsetEnd.x : plusOneOffsetEnd.x, plusOneOffsetEnd.y + parent.rect.height); // Play animation StopAllCoroutines(); StartCoroutine(RoundOver(scoreCell, plusRect, plusStart, plusEnd)); }
// Animate private IEnumerator RoundOver(PlayerScoreCell scoreCell, RectTransform plusRect, Vector2 plusStart, Vector2 plusEnd) { // Snatched animation yield return(new WaitForSeconds(snatchedScaleDelay)); LeanTween.value(snatchedGroup.gameObject, 0f, 1f, fadeDuration).setEase(fadeEase).setOnUpdate(delegate(float alpha) { snatchedGroup.alpha = alpha; }); LeanTween.value(snatchedGroup.gameObject, snatchedScaleStart, 1f, snatchedScaleDuration).setEase(snatchedScaleEase).setOnUpdate(delegate(float scale) { snatchedGroup.transform.localScale = Vector3.one * scale; }); // Score animation yield return(new WaitForSeconds(scoreDelay)); scoreOverlay.Animate(false); // Plus one animation yield return(new WaitForSeconds(plusOneOffsetDelay)); LeanTween.value(plusOneGroup.gameObject, 0f, 1f, plusOneFadeDuration).setEase(fadeEase).setOnUpdate(delegate(float alpha) { plusOneGroup.alpha = alpha; }); LeanTween.value(plusOneGroup.gameObject, plusStart.x, plusEnd.x, plusOneAnimXDuration).setEase(plusOneXOffsetEase).setDelay(plusOneAnimXDelay).setOnUpdate(delegate(float val) { Vector2 pos = plusRect.anchoredPosition; pos.x = val; plusRect.anchoredPosition = pos; }); LeanTween.value(plusOneGroup.gameObject, plusStart.y, plusStart.y + plusOneAnimYOffset, plusOneAnimYUpDuration).setEase(plusOneAnimYUpEase).setOnUpdate(delegate(float val) { Vector2 pos = plusRect.anchoredPosition; pos.y = val; plusRect.anchoredPosition = pos; }); yield return(new WaitForSeconds(plusOneAnimYUpDuration)); LeanTween.value(plusOneGroup.gameObject, plusStart.y + plusOneAnimYOffset, plusEnd.y, plusOneAnimYDownDuration).setEase(plusOneAnimYDownEase).setOnUpdate(delegate(float val) { Vector2 pos = plusRect.anchoredPosition; pos.y = val; plusRect.anchoredPosition = pos; }); LeanTween.value(plusOneGroup.gameObject, 1f, 0f, plusOneFadeDuration).setEase(fadeEase).setDelay(plusOneAnimYDownDuration - plusOneFadeDuration).setOnUpdate(delegate(float alpha) { plusOneGroup.alpha = alpha; }); yield return(new WaitForSeconds(plusOneAnimYDownDuration)); // Bounce animation yield return(new WaitForSeconds(bounceDelay)); _cell = scoreCell; scoreCell.LayoutScore(); LeanTween.value(gameObject, 1f, bounceScale, bounceUpDuration).setEase(bounceUpEase).setOnUpdate(SetScoreScale); yield return(new WaitForSeconds(bounceUpDuration)); LeanTween.value(gameObject, bounceScale, 1f, bounceDownDuration).setEase(bounceDownEase).setOnUpdate(SetScoreScale); yield return(new WaitForSeconds(bounceDownDuration)); _cell = null; // Final wait yield return(new WaitForSeconds(finalWait)); // Next round if (!GameManager.instance.isEndOfMatch) { GameManager.instance.PlayNewRound(); } // Show results else { GameManager.instance.SetState(GameState.MatchComplete); } }