public void SendTruckToTile(EGFiretruck truckToSend, int x, int y) { TDPath truckPath = new TDPath(); TDMap dataMap = _map.Map; truckPath.BuildPath(dataMap, dataMap.GetTile(Mathf.FloorToInt(truckToSend.GetPosition().x), Mathf.FloorToInt(-truckToSend.GetPosition().z)), dataMap.GetTile(x, y)); truckToSend.SetPath(truckPath); truckToSend.SetIdle(false); _dispatcher.AddActiveTruck(truckToSend); }
private TDTile GetSelectedTile(ref int x, ref int z) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (GetComponent <Collider>().Raycast(ray, out hitInfo, Mathf.Infinity)) { x = Mathf.FloorToInt(hitInfo.point.x / tileSize); z = Mathf.FloorToInt(hitInfo.point.z / tileSize); z += gridSizeZ; TDTile selectedTile = map.GetTile(x, z); return(selectedTile); } return(null); }
void BuildTexture() { map = new TDMap(gridSizeX, gridSizeZ); int texWidth = gridSizeX * tileResolution; int texHeight = gridSizeZ * tileResolution; texture = new Texture2D(texWidth, texHeight); oldTexture = new Texture2D(texWidth, texHeight); for (int y = 0; y < gridSizeZ; y++) { for (int x = 0; x < gridSizeX; x++) { TDTile tile = map.GetTile(x, y); if (tile == null) { continue; } //texture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, tilePixels[tile.GetTileType()]); texture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, spriteArray[tile.GetTileType()]); } } texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.Apply(); MeshRenderer meshRenderer = GetComponent <MeshRenderer>(); meshRenderer.sharedMaterials[0].mainTexture = texture; Debug.Log("Done Texture!"); }
public TDTile GetNeigbour(int x, int y) { TDTile r = map.GetTile(this.x + x, this.y + y); if (r == null) { return(this); } return(r); }
public void UpdateSelectedTile(int currTile, int prevTile) { Vector2[] tempUVs = new Vector2[size_x * 6 * size_z * 6]; tempUVs = _tileMesh.uv; tempUVs[_tileGraphicUVIndex[prevTile, 0]] = tileDataMap.GetTile(prevTile).UV(TDTile.UVS.BOTTOM_LEFT); tempUVs[_tileGraphicUVIndex[prevTile, 1]] = tileDataMap.GetTile(prevTile).UV(TDTile.UVS.TOP_LEFT); tempUVs[_tileGraphicUVIndex[prevTile, 2]] = tileDataMap.GetTile(prevTile).UV(TDTile.UVS.TOP_RIGHT); tempUVs[_tileGraphicUVIndex[prevTile, 3]] = tileDataMap.GetTile(prevTile).UV(TDTile.UVS.BOTTOM_LEFT); tempUVs[_tileGraphicUVIndex[prevTile, 4]] = tileDataMap.GetTile(prevTile).UV(TDTile.UVS.TOP_RIGHT); tempUVs[_tileGraphicUVIndex[prevTile, 5]] = tileDataMap.GetTile(prevTile).UV(TDTile.UVS.BOTTOM_RIGHT); tempUVs[_tileGraphicUVIndex[currTile, 0]] = tileDataMap.GetTile(currTile).UV(TDTile.UVS.BOTTOM_LEFT); tempUVs[_tileGraphicUVIndex[currTile, 1]] = tileDataMap.GetTile(currTile).UV(TDTile.UVS.TOP_LEFT); tempUVs[_tileGraphicUVIndex[currTile, 2]] = tileDataMap.GetTile(currTile).UV(TDTile.UVS.TOP_RIGHT); tempUVs[_tileGraphicUVIndex[currTile, 3]] = tileDataMap.GetTile(currTile).UV(TDTile.UVS.BOTTOM_LEFT); tempUVs[_tileGraphicUVIndex[currTile, 4]] = tileDataMap.GetTile(currTile).UV(TDTile.UVS.TOP_RIGHT); tempUVs[_tileGraphicUVIndex[currTile, 5]] = tileDataMap.GetTile(currTile).UV(TDTile.UVS.BOTTOM_RIGHT); _tileMesh.uv = tempUVs; }
/** Creates tile collision data from the tilemap. */ public TilePathDataNode(TDMap p_map, Coord p_tileLoc) { TDTile tile = p_map.GetTile(p_tileLoc.X, p_tileLoc.Y); }
// Update is called once per frame public void BuildMesh() { instance = this; MapCreated = false; MapWorldSize = new Vector2(size_x * tileSize, size_y * tileSize); if (grid != null) { grid.node_radius = tileSize / 2; grid.GridWorldSize = MapWorldSize; } CalcTex(); Global_TDMap = new TDMap(size_x, size_y, MapTerrainType, TileChance, MaxHeightForPlants, MaxHeightLeap); int numTiles = size_x * size_y; int numTris = numTiles * 2; int vsize_x = size_x * 2; int vsize_y = size_y * 2; int numVerts = vsize_x * vsize_y; if (vsize_x * vsize_y > 65000) { size_x = 125; size_y = 125; return; } Vector3[] vertices = new Vector3[numVerts]; Vector3[] normals = new Vector3[numVerts]; Vector2[] uv = new Vector2[numVerts]; int[] triangles = new int[numTris * 3]; int x, y; Vector3 sp = Vector3.zero; sp.x -= tileSize * size_x / 2; sp.y -= tileSize * size_x / 2; float r = Random.Range(-2f, 2f); for (y = 0; y < vsize_y; y++) { for (x = 0; x < vsize_x; x++) { vertices[y * vsize_x + x] = new Vector3((x + 1) / 2 * tileSize, (y + 1) / 2 * tileSize, 0) + sp; normals[y * vsize_x + x] = new Vector3(0, 0, -1); uv[y * vsize_x + x] = GetTexture(Global_TDMap.GetTile(x / 2, y / 2).type, x, y); } } if (Heights) { for (y = 1; y < vsize_y - 1; y += 2) { for (x = 1; x < vsize_x - 1; x += 2) { r = Random.Range(0, 0); if (Global_TDMap.GetIfWater(x / 2, y / 2)) { r = -Random.Range(-8f, -10f); } else { r = Global_TDMap.GetIfMountine((x + 0) / 2, (y + 0) / 2); } vertices[y * vsize_x + x].z = r; vertices[y * vsize_x + x + 1].z = r; vertices[(y + 1) * vsize_x + x].z = r; vertices[(y + 1) * vsize_x + x + 1].z = r; } } for (y = 0; y < vsize_y; y++) { vertices[y * vsize_x].z = vertices[y * vsize_x + 1].z; vertices[y * vsize_x + vsize_x - 1].z = vertices[y * vsize_x + vsize_x - 2].z; } for (x = 0; x < vsize_x; x++) { vertices[x].z = vertices[vsize_x + x].z; vertices[(vsize_y - 1) * vsize_x + x].z = vertices[(vsize_y - 2) * vsize_x + x].z; } print("End OF Heights!"); } for (y = 0; y < size_y; y++) { for (x = 0; x < size_x; x++) { //x = 1 int squareIndex = y * size_x + x; int triOffset = squareIndex * 6; triangles[triOffset + 0] = (y * 2) * vsize_x + (x * 2) + 0; triangles[triOffset + 1] = (y * 2) * vsize_x + (x * 2) + vsize_x + 0; triangles[triOffset + 2] = (y * 2) * vsize_x + (x * 2) + vsize_x + 1; triangles[triOffset + 3] = (y * 2) * vsize_x + (x * 2) + 0; triangles[triOffset + 4] = (y * 2) * vsize_x + (x * 2) + vsize_x + 1; triangles[triOffset + 5] = (y * 2) * vsize_x + (x * 2) + 1; } } Mesh mesh = new Mesh(); mesh.vertices = vertices; mesh.normals = normals; mesh.uv = uv; mesh.triangles = triangles; MeshFilter mesh_filter = GetComponent <MeshFilter>(); MeshRenderer mesh_renderer = GetComponent <MeshRenderer>(); MeshCollider mesh_collider = GetComponent <MeshCollider>(); mesh_filter.mesh = mesh; mesh_collider.sharedMesh = mesh; Debug.Log("Done Mesh!"); //BuildTexture(); OnMapGenerator GenerateTrees = new OnMapGenerator(Global_TDMap, size_x, size_y, tileSize, MapHolder); StartCoroutine(GenerateTreesEI(GenerateTrees)); //MapCreated = true; }