override public void InitGrid() { var imageRectHeight = new Rect(0, 0, heightMap.width, heightMap.height); var imageRectPolitical = new Rect(0, 0, politicalMap.width, politicalMap.height); var map = new FlatHexMap(new Vector2(80, 69)); var mapHeight = new ImageMap <FlatHexPoint>(imageRectHeight, Grid, map); var mapPolitical = new ImageMap <FlatHexPoint>(imageRectPolitical, Grid, map); WaterHexes = new List <FlatHexPoint>(); MountainHexes = new List <FlatHexPoint>(); LandHexes = new List <FlatHexPoint>(); foreach (var point in Grid) { int x = Mathf.FloorToInt(mapHeight[point].x); int y = Mathf.FloorToInt(mapHeight[point].y); float height = heightMap.GetPixel(x, y).r *HeightScale; if (height <= 0) { height = 0.01f; } var block = Grid[point]; if (block == null) { Debug.LogWarning("block is null " + point); } else { if (height < HeightScale * 0.3f) { UVCell thisHex = block.GetComponentInChildren <UVCell>(); thisHex.GetComponent <Renderer>().material = baseWater; block.GetComponent <Renderer>().material = baseWater; block.transform.localScale = new Vector3(1, WaterHeight, 1); //block.transform.position += new Vector3(0f, (BaseHeight + WaterHeight) / 4f, 0f); WaterHexes.Add(point); } else if (height >= HeightScale * 0.3f && height < HeightScale * 0.7f) { UVCell thisHex = block.GetComponentInChildren <UVCell>(); thisHex.GetComponent <Renderer>().material = baseGrass; block.transform.localScale = new Vector3(1, BaseHeight, 1); LandHexes.Add(point); } else { UVCell thisHex = block.GetComponentInChildren <UVCell>(); thisHex.GetComponent <Renderer>().material = baseRocky; block.transform.localScale = new Vector3(1, MountainHeight, 1); MountainHexes.Add(point); } } } }
override public void InitGrid() { var imageRect = new Rect(0, 0, heightMap.width, heightMap.height); var map = new FlatHexMap(new Vector2(80, 69)); var map2D = new ImageMap <FlatHexPoint>(imageRect, Grid, map); foreach (var point in Grid) { int x = Mathf.FloorToInt(map2D[point].x); int y = Mathf.FloorToInt(map2D[point].y); float height = heightMap.GetPixel(x, y).r *HeightScale; if (height <= 0) { height = 0.01f; } var block = Grid[point]; if (block == null) { Debug.LogWarning("block is null " + point); } else { //block.Color = ExampleUtils.Blend(height, ExampleUtils.DefaultColors[0], ExampleUtils.DefaultColors[1]); //block.transform.localScale = new Vector3(1, height, 1); if (height < HeightScale * 0.3f) { UVCell thisHex = block.GetComponentInChildren <UVCell>(); thisHex.GetComponent <Renderer>().material = baseSandy; } if (height > HeightScale * 0.6f && height < HeightScale * 0.8f) { UVCell thisHex = block.GetComponentInChildren <UVCell>(); thisHex.GetComponent <Renderer>().material = baseRockyGrass; } if (height >= HeightScale * 0.8f) { UVCell thisHex = block.GetComponentInChildren <UVCell>(); thisHex.GetComponent <Renderer>().material = baseRocky; } } } }