diff --git a/Assets/Prefabs/Gems/Bomb Variant.prefab b/Assets/Prefabs/Gems/Bomb Variant.prefab index 2d50b4f..e68795e 100644 --- a/Assets/Prefabs/Gems/Bomb Variant.prefab +++ b/Assets/Prefabs/Gems/Bomb Variant.prefab @@ -40,6 +40,21 @@ PrefabInstance: value: objectReference: {fileID: 21300000, guid: d1c82e015b38d4448bc1ba5e3eff90fa, type: 3} + - target: {fileID: 7667143225876670884, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, + type: 3} + propertyPath: m_Color.b + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7667143225876670884, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, + type: 3} + propertyPath: m_Color.g + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7667143225876670884, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, + type: 3} + propertyPath: m_Color.r + value: 1 + objectReference: {fileID: 0} - target: {fileID: 7667143225876670885, guid: 724e93e48c6cc0b4ab3d44e5ea34f2ec, type: 3} propertyPath: type @@ -139,3 +154,5 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7645dd1d371740729311dd834ab649f3, type: 3} m_Name: m_EditorClassIdentifier: + spawnScaleFrom: 0 + spawnScaleDuration: 0.12 diff --git a/Assets/Scripts/Services/GameBoardService.cs b/Assets/Scripts/Services/GameBoardService.cs index 61f68cc..c958542 100644 --- a/Assets/Scripts/Services/GameBoardService.cs +++ b/Assets/Scripts/Services/GameBoardService.cs @@ -97,7 +97,7 @@ namespace Services { // remove existing gem/view at that position DestroyMatchedGems(position); - GemView gemView = this.objectPool.Get(GemType.Bomb, position, this.gameVariables.dropHeight); + GemView gemView = this.objectPool.Get(GemType.Bomb, position, 0); gemView.name = "Gem - " + position.x + ", " + position.y + ' ' + GemType.Bomb; int scoreValue = GemUtils.GetGemValues(color, this.gameVariables.gemsPrefabs).scoreValue; @@ -258,18 +258,18 @@ namespace Services { } private async UniTask FillBoard() { - await UniTask.Delay(5); + await UniTask.Delay(250); RefillBoard(); - await UniTask.Delay(5); + await UniTask.Delay(600); this.matchService.FindAllMatches(); if (this.matchService.CurrentMatches.Count > 0) { - await UniTask.Delay(5); + await UniTask.Delay(600); // In cascades, there is no "creating slot" bomb protection. await DestroyMatchesAsync(new List()); } else { - await UniTask.Delay(5); + await UniTask.Delay(250); this.currentState = GameState.Move; } } diff --git a/Assets/Scripts/Views/GemView.cs b/Assets/Scripts/Views/GemView.cs index 6d61004..00d2557 100644 --- a/Assets/Scripts/Views/GemView.cs +++ b/Assets/Scripts/Views/GemView.cs @@ -1,3 +1,4 @@ +using System.Threading; using Cysharp.Threading.Tasks; using Enums; using Services; @@ -10,21 +11,68 @@ namespace Views { public Gem Gem => this.gem; private bool isFalling; + [Header("Spawn Scale")] + [SerializeField] private float spawnScaleFrom = 0f; + [SerializeField] private float spawnScaleDuration = 0.12f; + + private CancellationTokenSource spawnScaleCts; public void Bind(Gem gem) { this.gem = gem; this.gameObject.SetActive(true); + + PlaySpawnScale(); } - + public void Unbind() { + this.spawnScaleCts?.Cancel(); + this.spawnScaleCts?.Dispose(); + this.spawnScaleCts = null; + this.gem = null; this.gameObject.SetActive(false); this.isFalling = false; } + private void PlaySpawnScale() { + this.spawnScaleCts?.Cancel(); + this.spawnScaleCts?.Dispose(); + this.spawnScaleCts = new CancellationTokenSource(); + + this.transform.localScale = Vector3.one * this.spawnScaleFrom; + AnimateSpawnScaleAsync(this.spawnScaleCts.Token).Forget(); + } + + private async UniTask AnimateSpawnScaleAsync(CancellationToken ct) { + if (this.spawnScaleDuration <= 0f) { + this.transform.localScale = Vector3.one; + return; + } + + float timer = 0f; + while (timer < this.spawnScaleDuration) { + ct.ThrowIfCancellationRequested(); + + timer += Time.deltaTime; + float scale = Mathf.Clamp01(timer / this.spawnScaleDuration); + + scale = Mathf.SmoothStep(0f, 1f, scale); + + this.transform.localScale = Vector3.LerpUnclamped( + Vector3.one * this.spawnScaleFrom, + Vector3.one, + scale + ); + + await UniTask.Yield(PlayerLoopTiming.Update, ct); + } + + this.transform.localScale = Vector3.one; + } + private async UniTask FallDelay() { - float randomDelay = 1 * this.gem.Position.y / 100f; - await UniTask.WaitForSeconds(randomDelay); + float fallDelay = 1 * (this.gem.Position.y / 10f); + await UniTask.WaitForSeconds(fallDelay); this.isFalling = true; }