// Start is called before the first frame update void Start() { cameraBoundaries = GameObject.Find("CameraBoundaries").GetComponent <CameraBoundaries>(); }
// construct map from tiles based on the generated or loaded map private bool GenerateMap() { if (ReadMapFromFile) { try { MapGrid = new Map(MapFilePath, FitnessFunction); MapWidth = MapGrid.Width; MapHeight = MapGrid.Height; } catch (MapFileException ex) { ex.streamReader.Close(); ColorBlock cbl = MapFilePathField.colors; cbl.normalColor = new Color(1f, 0.7f, 0.7f); MapFilePathField.colors = cbl; GameStage = GameStages.Settings; SettingsCanvas.gameObject.SetActive(true); RouteCanvas.gameObject.SetActive(false); return(false); } } else { MapGrid = new Map(MapWidth, MapHeight, FitnessFunction); } GameObject tempObject; Node tempNode; MapTileController tempTile; for (int x = 0; x < MapWidth; x++) { for (int y = 0; y < MapHeight; y++) { tempObject = Instantiate(MapTilePrefab, MapContainer); tempNode = MapGrid.GetNode(x, y); tempNode.Tile = tempObject; tempTile = tempObject.GetComponent <MapTileController>(); for (int i = 0; i < 4; i++) { tempTile.ModifyBorder((Node.Dir)(i), tempNode.Edges[(Node.Dir)(i)].IsPassable, tempNode.Edges[(Node.Dir)(i)].IsPerceptible); } tempObject.transform.position = new Vector3(x, y, 0f); } } _mainCamera.orthographicSize = MapHeight / 2f + 1; _mainCamera.transform.position = new Vector3(MapWidth / 2f, MapHeight / 2f - 0.5f, _mainCamera.transform.position.z); CameraBoundaries cb = _mainCamera.GetComponent <CameraBoundaries>(); cb.BottomBoundary = -1.5f; cb.LeftBoundary = -1.5f; cb.TopBoundary = MapHeight + 0.5f; cb.RightBoundary = MapWidth + 0.5f; cb.Reinitialize(); return(true); }