using Core.Input;
|
using TowerDefense.UI.HUD;
|
using State = TowerDefense.UI.HUD.EndlessGameUI.State;
|
|
namespace TowerDefense.UI
|
{
|
/// <summary>
|
/// TD Specific input switcher that also disables controls when the game is paused
|
/// PVE 无尽模式使用
|
/// </summary>
|
public class EndlessTowerDefenseInputSchemeSwitcher : InputSchemeSwitcher
|
{
|
/// <summary>
|
/// Gets whether the game is in a paused state
|
/// </summary>
|
public bool isPaused
|
{
|
get { return EndlessGameUI.instance.state == State.Paused; }
|
}
|
|
/// <summary>
|
/// Register GameUI's stateChanged event
|
/// </summary>
|
protected virtual void Start()
|
{
|
if (EndlessGameUI.instanceExists)
|
EndlessGameUI.instance.stateChanged += OnUIStateChanged;
|
}
|
|
/// <summary>
|
/// Do nothing when game is paused
|
/// </summary>
|
protected override void Update()
|
{
|
if (isPaused)
|
return;
|
|
base.Update();
|
}
|
|
/// <summary>
|
/// Unregister from GameUI's stateChanged event
|
/// </summary>
|
protected virtual void OnDestroy()
|
{
|
if (EndlessGameUI.instanceExists)
|
EndlessGameUI.instance.stateChanged -= OnUIStateChanged;
|
}
|
|
/// <summary>
|
/// Activate or deactivate the current input scheme when the game pauses/unpauses
|
/// </summary>
|
void OnUIStateChanged(State oldState, State newState)
|
{
|
if (m_CurrentScheme == null)
|
return;
|
|
if (newState == State.Paused)
|
m_CurrentScheme.Deactivate(null);
|
else
|
m_CurrentScheme.Activate(null);
|
}
|
}
|
}
|