using TowerDefense.Economy;
using TowerDefense.Level;
using UnityEngine;
namespace TowerDefense.Affectors
{
///
/// A tower effect for generating currency
///
public class CurrencyAffector : Affector
{
///
/// The controller for currency gain
///
public CurrencyGainer currencyGainer;
///
/// Format for displaying the the properties of this affector
///
public string descriptionFormat = "Produces {1} at {2} units per second";
///
/// The audio source attached
///
public AudioSource audioSource;
///
/// The attached particle system
///
public ParticleSystem currencyParticleSystem;
///
/// Initialize the currency gain
///
protected virtual void Start()
{
currencyGainer.Initialize(LevelManager.instance.currency);
}
///
/// Update the currency gain
///
protected virtual void Update()
{
currencyGainer.Tick(Time.deltaTime);
}
///
/// Subscribe to currency gain events
///
protected virtual void OnEnable()
{
currencyGainer.currencyChanged += OnCurrencyChanged;
}
///
/// Unsubscribe to currency gain event
///
protected virtual void OnDisable()
{
currencyGainer.currencyChanged -= OnCurrencyChanged;
}
///
/// Fires when currency changed in
///
///
/// The info for the currency gainer
///
protected void OnCurrencyChanged(CurrencyChangeInfo info)
{
if (audioSource != null)
{
audioSource.Play();
}
if (currencyParticleSystem != null)
{
currencyParticleSystem.Play();
}
}
}
}