/// @param amount /// The amount of particles to spawn /// @param reward /// The reward to spawn /// @param position /// The position to spawn at /// @param holder /// The holder to interact with /// @param callback /// The function to call when the ceremony is done /// private void SpawnRewardInternal(int amount, CurrencyItem reward, Vector3 position, TopPanelHolder holder, Action callback) { // Show the holder if needed holder.Show(); // Spawn a bunch of particles int particleFinished = 0; for (int i = 0; i < amount; ++i) { ++holder.m_activeParticles; var particleReward = ParticleUtils.SpawnRewardParticles(reward.m_currencyID, transform.parent, position, holder.transform.position); particleReward.OnReachedDestination += () => { // This is called when the particle hits the holder m_currencySequence.Stop(true); m_currencySequence = DOTween.Sequence(); // Show the flash holder.m_flash.color = Color.white; // Trigger the sequence m_currencySequence.Append(holder.transform.DOPunchPosition(Vector3.up * Screen.height * 0.025f, 0.5f)); m_currencySequence.Insert(0.0f, holder.m_flash.DOColor(GameUtils.k_transparent, 0.5f)); m_currencySequence.OnComplete(() => { --holder.m_activeParticles; // Hide the holder if not needed anymore holder.Hide(); }); PlayCollectSFX(reward.m_currencyID); m_currencySequence.Play(); }; particleReward.OnRewarded += () => { // This is called even if the particle gets destroyed ++particleFinished; if (particleFinished == amount) { callback.SafeInvoke(); } }; } // Text shown above ParticleUtils.SpawnTextParticles(string.Format(GameTextIdentifiers.k_rewardFormat, reward.m_value), transform.parent, position); }
/// @param callback /// The function to call when the tiles are popped /// private IEnumerator StaggerTilesPop(Action callback) { // Pop the tiles int tilePopped = 0; int tilesChained = 0; int tileScore = k_tileScore; foreach (var tile in m_selectedTiles) { string audioSFX = AudioIdentifiers.k_sfxPopPositive; string particleID = ParticleIdentifiers.k_tilePop; string textFormat = GameTextIdentifiers.k_rewardFormat; Color textColour = Color.white; // Special tiles if (tile.m_tileColour == TileColour.Grey) { audioSFX = AudioIdentifiers.k_sfxPopNegative; particleID = ParticleIdentifiers.k_tilePopNegative; textFormat = GameTextIdentifiers.k_penaltyFormat; textColour = Color.red; tileScore = -k_tileScore; } // Audio SFX m_audioService.PlaySFX(audioSFX); // Particle effect and score m_currentScore += tileScore; var textParticle = ParticleUtils.SpawnTextParticles(string.Format(textFormat, tileScore), m_view.TilesHolder, tile.m_boardPosition); textParticle.SetColour(textColour); ParticleUtils.SpawnParticles(particleID, tile.m_boardPosition); // Log the score event m_objectiveService.LogEvent(ObjectiveType.Score, tileScore); tile.Pop(() => { // Tile popped, remove it m_tiles.Remove(tile); tile.gameObject.SetActive(false); ++tilePopped; // Log the popped tile event m_objectiveService.LogEvent(ObjectiveType.Colour, tile.m_tileColour); }); yield return(new WaitForSeconds(0.1f)); // Add bonus score if any ++tilesChained; if (tileScore > 0 && tilesChained % k_minActiveTiles == 0) { tileScore += k_bonusScore; } } while (tilePopped < m_selectedTiles.Count) { yield return(null); } // Log the chain event m_objectiveService.LogEventWithValue(ObjectiveType.Chain, tilesChained); callback.SafeInvoke(); }