chenxin
2020-10-28 8716403033b7c70b00b61bc6c74af04e4d248ecc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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);
        }
    }
}