// initial start private void Start() { playerBulletPool = GameManager.Instance.PlayerBulletPool; shootTimer = TimerManager.Instance.CreateTimerRepeat(1 / FIRE_RATE); shootTimer.onFinish += shootTimer_onFinish; shootPattern = DefaultShoot; if (_shooting) { shootTimer.Start(); } }
// Perform null checks and set values if effect's is not null // Set up post-effect restore values (if applicable) and start restore timer public void GotPowerup(PowerupEffect effect) { // initial value to the restore effect. Should get overwritten by another one if an effect is happening // otherwise just here as a fallback PowerupEffect restoreValuesEffect = new PowerupEffect { bulletScaling = BulletScaling }; string effectType = ""; if (effect.health != null) { health = (float)effect.health; } // if (effect.shield != null) shield = (float)effect.shield; // TOOD: implement shield if (effect.bulletScaling != null) { restoreValuesEffect = new PowerupEffect { bulletScaling = BulletScaling }; effectType = "BulletScaling"; BulletScaling = (float)effect.bulletScaling; } if (effect.shipScaling != null) { restoreValuesEffect = new PowerupEffect { shipScaling = ShipScaling }; effectType = "ShipScaling"; ShipScaling = (float)effect.shipScaling; } if (effect.shootPattern != null) { restoreValuesEffect = new PowerupEffect { shootPattern = ShootPattern }; effectType = "ShootPattern"; ShootPattern = effect.shootPattern; } if (effect.duration != null) { Timer effectTimer = TimerManager.Instance.CreateTimerOneshot((float)effect.duration); effectTimer.onFinish += () => { GotPowerup(restoreValuesEffect); // apply the values from the restoreValuesEffect to return to a 'normal' state powerupEffectRestoreValues.Remove(effectType); powerupEffectDurations[effectType].Stop(); powerupEffectDurations.Remove(effectType); }; effectTimer.Start(); // add or update the timer for this effect type if (powerupEffectDurations.ContainsKey(effectType)) { powerupEffectDurations[effectType].Stop(); powerupEffectDurations[effectType] = effectTimer; } else { powerupEffectDurations.Add(effectType, effectTimer); } // add or update the restore value effect struct for this effect type if (powerupEffectRestoreValues.ContainsKey(effectType)) { powerupEffectRestoreValues[effectType] = restoreValuesEffect; } else { powerupEffectRestoreValues.Add(effectType, restoreValuesEffect); } } }