private void Awake()
        {
            Current         = this;
            _networkManager = FindObjectOfType <NetworkManager>();

            Team blueTeam = GameObject.Find("Team_Blue").GetComponent <Team>();
            Team redTeam  = GameObject.Find("Team_Red").GetComponent <Team>();

            Deck bluePlayerDeck = ConfigReader.FindDeck("player-blue");
            Deck redPlayerDeck  = ConfigReader.FindDeck("player-red");

            PlayerData bluePlayer = new PlayerData(
                bluePlayerDeck, blueTeam, (byte)Players.Count);

            Players.Add(bluePlayer);
            blueTeam.Players.Add(bluePlayer);

            PlayerData redPlayer = new PlayerData(
                redPlayerDeck, redTeam, (byte)Players.Count);

            Players.Add(redPlayer);
            redTeam.Players.Add(redPlayer);

            Teams.Add(blueTeam);
            Teams.Add(redTeam);

            LocalPlayer      = gameObject.AddComponent <PlayerBehaviour>();
            LocalPlayer.Data = redTeam.Players[0];

            _unitRegistry = new UnitRegistry(LocalPlayer.Data.Team, Teams);

            _inputManager = FindObjectOfType <InputManager>();

            if (!_inputManager)
            {
                _inputManager = gameObject.AddComponent <InputManager>();
            }
            _inputManager.Session = _inputManager.Session ?? this;

            _visibilityManager = FindObjectOfType <VisibilityManager>();
            if (!_visibilityManager)
            {
                _visibilityManager = gameObject.AddComponent <VisibilityManager>();
            }
            _visibilityManager.UnitRegistry = _visibilityManager.UnitRegistry ?? _unitRegistry;

            _deploymentMenu.Initialize(_inputManager, LocalPlayer);

            // LoadedData ideally comes from the loading scene
            _loadedData = FindObjectOfType <LoadedData>();

            if (_loadedData != null)
            {
                TerrainMap = _loadedData.terrainData;
                PathData   = _loadedData.pathFinderData;
                Factory    = new UnitFactory();
                Settings   = new Settings();
            }
        }
Exemplo n.º 2
0
        private void Awake()
        {
            Current         = this;
            _networkManager = FindObjectOfType <NetworkManager>();

            // LoadedData ideally comes from the loading scene
            _loadedData = FindObjectOfType <LoadedData>();

            // If there is no loaded data, this scene is just
            // a false start and we will instantly move to
            // the loading scene (see Start() ) and then reset this
            // scene with a loaded data.
            if (_loadedData != null)
            {
                TerrainMap = _loadedData.TerrainData;
                PathData   = _loadedData.PathFinderData;
                Factory    = new UnitFactory();
                Settings   = new Settings();


                Team blueTeam = GameObject.Find("Team_Blue").GetComponent <Team>();
                Team redTeam  = GameObject.Find("Team_Red").GetComponent <Team>();

                Deck bluePlayerDeck = ConfigReader.ParseDeck(
                    "player-blue", _loadedData.Armory);
                Deck redPlayerDeck = ConfigReader.ParseDeck(
                    "player-red", _loadedData.Armory);

                PlayerData bluePlayer = new PlayerData(
                    bluePlayerDeck, blueTeam, (byte)Players.Count);
                Players.Add(bluePlayer);
                blueTeam.Players.Add(bluePlayer);

                PlayerData redPlayer = new PlayerData(
                    redPlayerDeck, redTeam, (byte)Players.Count);
                Players.Add(redPlayer);
                redTeam.Players.Add(redPlayer);

                Teams.Add(blueTeam);
                Teams.Add(redTeam);

                LocalPlayer      = gameObject.AddComponent <PlayerBehaviour>();
                LocalPlayer.Data = redTeam.Players[0];

                _unitRegistry = new UnitRegistry(LocalPlayer.Data.Team, Teams);

                _inputManager = FindObjectOfType <InputManager>();

                if (!_inputManager)
                {
                    _inputManager = gameObject.AddComponent <InputManager>();
                }
                _inputManager.Session     = this;
                _inputManager.LocalPlayer = LocalPlayer.Data;

                _visibilityManager = FindObjectOfType <VisibilityManager>();
                if (!_visibilityManager)
                {
                    _visibilityManager = gameObject.AddComponent <VisibilityManager>();
                }
                _visibilityManager.UnitRegistry = _visibilityManager.UnitRegistry ?? _unitRegistry;

                _deploymentMenu.Initialize(_inputManager, LocalPlayer);

                SpawnPointBehaviour[] spawns =
                    FindObjectsOfType <SpawnPointBehaviour>();
                foreach (SpawnPointBehaviour spawn in spawns)
                {
                    _inputManager.RegisterSpawnPoint(spawn);
                }
            }
        }