コード例 #1
0
        void Start()
        {
            string turnManagerDebug = "TurnManager Start Info:\n";

            if (HexNodeManager != null)
            {
                _hexNodesManager = HexNodeManager.GetComponent <HexNodesManager>();
                if (_hexNodesManager == null)
                {
                    turnManagerDebug += "There was no HexNodesManager script bound to the given HexNodeManager instance!\n";
                }
                else
                {
                    turnManagerDebug += "Successfully linked the HexNodeManager to the TurnManager!\n";
                }
            }
            else
            {
                turnManagerDebug += "No HexNodeManager instance was supplied to the TurnManager!\n";
            }

            if (Player != null)
            {
                _player = Player.GetComponent <PlayerAgent>();
                if (_player == null)
                {
                    turnManagerDebug += "There was no PlayerAgent script bound to the given Player instance!\n";
                }
                else
                {
                    turnManagerDebug += "Successfully linked the PlayerAgent to the TurnManager!\n";
                }
            }
            else
            {
                turnManagerDebug += "No Player instance was supplied to the TurnManager!\n";
            }

            _enemies = new List <EnemyAgent>();

            //Setting up the cache
            _phases = new Dictionary <Type, TurnPhaseBase>();
            _phases.Add(typeof(TurnPhaseIdle), new TurnPhaseIdle(this, EnemyScanRadius));
            _phases.Add(typeof(TurnPhaseEnemyChange), new TurnPhaseEnemyChange(this));
            _phases.Add(typeof(TurnPhasePlayerSelection), new TurnPhasePlayerSelection(this, _player));
            _phases.Add(typeof(TurnPhasePlayerAction), new TurnPhasePlayerAction(this, _player));
            _phases.Add(typeof(TurnPhaseEnemySelection), new TurnPhaseEnemySelection(this, _currentEnemy));
            _phases.Add(typeof(TurnPhaseEnemyAction), new TurnPhaseEnemyAction(this, _currentEnemy));

            turnManagerDebug += "Phase Cache is initialized!";

            Debug.Log(turnManagerDebug);

            //Initializing the first state manually
            _currentPhase = _phases[typeof(TurnPhaseIdle)];
            _currentPhase.Start();
        }
コード例 #2
0
 public void ChangePhase(Type newPhase)
 {
     Debug.Log("Changing from phase: " + _currentPhase.GetType() + " to: " + newPhase);
     if (_currentPhase.GetType() == typeof(TurnPhasePlayerAction) && newPhase == typeof(TurnPhaseEnemySelection))
     {
         if (_enemies.Count == 0)
         {
             Debug.Log("No enemies available, going back to idle state!");
             newPhase = typeof(TurnPhaseIdle); //if no enemies are present, switching back to Idle
         }
     }
     _currentPhase.End();
     _currentPhase = _phases[newPhase];
     _currentPhase.Start();
 }