public GameObject createMapTileView(float x, float y, Map.MapTileType type) { GameObject result = null; Vector3 tilePosition = new Vector3(-this.mapModel.Width / 2f + x + 0.5f, 0, -this.mapModel.Height / 2f + y + 0.5f); switch (type) { case Map.MapTileType.Wall: result = createWall(Mathf.RoundToInt(x), Mathf.RoundToInt(y)); tilePosition.y = 0.9f; createMapTileView(x, y, Map.MapTileType.Floor); break; case Map.MapTileType.Barrier: result = createBarrier(Mathf.RoundToInt(x), Mathf.RoundToInt(y)); tilePosition.y = 0.9f; createMapTileView(x, y, Map.MapTileType.Floor); break; case Map.MapTileType.Floor: result = createFloor(Mathf.RoundToInt(x), Mathf.RoundToInt(y)); tilePosition.y = -0.1f; break; } if (result) { result.gameObject.transform.position = tilePosition; } return(result); }
public void setType(Map.MapTileType type) { this.type = type; if (this.type != Map.MapTileType.NotDefined) { tileImage.sprite = tileSprites[Map.typeToTypeIndex(this.type)]; } }
private GameObject createMapTile(Map.MapTileType type, int x, int y) { GameObject result = null; if (type != Map.MapTileType.NotDefined) { result = createMapTileView(x, y, type); } return(result); }
private GameObject createMapTile(Map.MapTileType type, int x, int y) { GameObject result = null; if (type != Map.MapTileType.NotDefined) { result = GameObject.Instantiate(mapTilePrefab, mapContainer.transform); result.GetComponent <MapTileView>().setPosition(x, y); result.GetComponent <MapTileView>().setType(type); } return(result); }
// Create map Tiles private void drawMap() { this.tileGameObjects = new Dictionary <KeyValuePair <int, int>, GameObject>(); if (this.mapModel != null) { for (int y = 0; y < this.mapModel.Height; y++) { for (int x = 0; x < this.mapModel.Width; x++) { Map.MapTileType type = this.mapModel.getTileType(x, y); this.tileGameObjects.Add(new KeyValuePair <int, int>(y, x), this.createMapTile(type, x, y)); } } // Adjust the camera Camera mapCamera = GameObject.FindObjectOfType <Camera>(); if (mapCamera != null) { mapCamera.transform.position = new Vector3(this.mapModel.Width / 2f - 0.5f, this.mapModel.Height / 2f - 0.5f, -1); // 0.5 is the size of a half of the tile mapCamera.orthographicSize = Mathf.Max(this.mapModel.Width / 2f, this.mapModel.Height / 2f); } } }
// Create map Tiles private void drawMap() { this.tileGameObjects = new Dictionary <KeyValuePair <int, int>, GameObject>(); if (this.mapModel != null) { // Create tiles for (int y = 0; y < this.mapModel.Height; y++) { for (int x = 0; x < this.mapModel.Width; x++) { Map.MapTileType type = this.mapModel.getTileType(x, y); this.tileGameObjects.Add(new KeyValuePair <int, int>(y, x), this.createMapTile(type, x, y)); } } // Create Player this.createPlayer(0); // Create Bridges foreach (BridgeElement bridge in this.mapModel.Bridges) { this.createBridge(bridge); } foreach (BridgeButton button in this.mapModel.BridgeButtons) { this.createBridgeButton(button); } // Create Collectibles foreach (CollectibleElement collectible in this.mapModel.Collectibles) { this.createCollectible(collectible); } // Create Target this.createTarget(this.mapModel.PlayerTarget); // Create Blocks foreach (BlockElement block in this.mapModel.Blocks) { this.createBlock(block); } // Adjust the camera Camera mapCamera = GameObject.FindObjectOfType <Camera>(); if (mapCamera != null) { mapCamera.GetComponent <TrackingCamera> ().Target = this.gameObject.transform; mapCamera.transform.position = new Vector3(0, this.mapModel.Height + 1, 0); // 0.5 is the size of a half of the tile //mapCamera.transform.position = new Vector3( this.mapModel.Width/2f-0.5f, this.mapModel.Height/2f-0.5f, -1 ); // 0.5 is the size of a half of the tile //mapCamera.orthographicSize = Mathf.Max( this.mapModel.Width/2f, this.mapModel.Height/2f ); } // Adjust Kill Collider KillCollider killCollider = GetComponentInChildren <KillCollider>(); if (killCollider != null) { killCollider.setScale(this.mapModel.Width, this.mapModel.Height); killCollider.setMinHeight(0f); } // Adjust Floor /*if(floor != null){ * floor.transform.localScale = new Vector3 ( this.mapModel.Width-(useThinWall?0.9f:0f), 0.2f, this.mapModel.Height-(useThinWall?0.9f:0f)); * floor.transform.position = new Vector3 ( 0, -0.1f, 0 ); * }*/ } }
public void SetTileType(Map.MapTileType pTileType) { mTileType = pTileType; }
public MapTile() { mIndex = 0; mPosition = new Vector2(0, 0); mTileType = Map.MapTileType.None; }