コード例 #1
0
        private void OnEnable()
        {
            _enemy.enabled        = true;
            _room                 = new LocalRoom(PlayerId, EnemyId);
            _room.State.OnChange += changes =>
            {
                foreach (var change in changes)
                {
                    switch (change.Field)
                    {
                    case RoomState.Phase:
                        var phase = (string)change.Value;
                        GamePhaseChanged?.Invoke(phase);
                        if (phase.Equals(RoomPhase.Result))
                        {
                            _isMatchFinished = true;
                        }
                        break;

                    case RoomState.PlayerTurn:
                        if (!_isMatchFinished && EnemyId.Equals((string)change.Value))
                        {
                            StartCoroutine(_enemy.GetShots(cells => _room.Turn(EnemyId, cells)));
                        }
                        break;
                    }
                }
            };
            _room.State.players[PlayerId].ships.OnChange += (turn, part) => _enemy.UpdatePlayerShips(part, turn);
        }
コード例 #2
0
 private void OnDisable()
 {
     _enemy.enabled = false;
     _room          = null;
 }