public void BuildGrid() { var grid = PointyHexGrid <UVCell> .ThinRectangle(11, 11); var baseMap = new PointyHexMap(cellPrefab.Dimensions * 1.1f); Debug.Log(cellPrefab.Dimensions); var cellMap = baseMap .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(grid) .To3DXY(); var imageMap = new ImageMap <PointyHexPoint>(new Rect(0, 0, 1, 1), grid, baseMap); foreach (var point in grid) { var worldPosition = cellMap[point]; var cell = Instantiate(cellPrefab); Debug.Log(cell.Dimensions); cell.transform.parent = gridRoot.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPosition; cell.SetTexture(texture); cell.name = point.ToString(); var imagePoint = imageMap[point]; cell.SetUVs(imagePoint, imageMap.GetCellDimensions(point)); } }
public void BuildGrid() { var grid = PointyHexGrid<UVCell>.ThinRectangle(11, 11); var baseMap = new PointyHexMap(cellPrefab.Dimensions * 1.1f); Debug.Log(cellPrefab.Dimensions); var cellMap = baseMap .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(grid) .To3DXY(); var imageMap = new ImageMap<PointyHexPoint>(new Rect(0, 0, 1, 1), grid, baseMap); foreach (var point in grid) { var worldPosition = cellMap[point]; var cell = Instantiate(cellPrefab); Debug.Log(cell.Dimensions); cell.transform.parent = gridRoot.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPosition; cell.SetTexture(texture); cell.name = point.ToString(); var imagePoint = imageMap[point]; cell.SetUVs(imagePoint, imageMap.GetCellDimensions(point)); } }
private void BuildGrid() { //This is the base grid, we will use it to define //the shape of the splice grid. //The contents is not important. var baseGrid = PointyHexGrid<bool> .BeginShape() .Hexagon(5) .EndShape(); //This is the base map, used for the course //mapping var baseMap = new PointyHexMap(cellDimensions) .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(baseGrid); //Now we make the actual spliced grid. //We feed it the base grid, and the number //of splices we want. grid = new SplicedGrid<SpriteCell, PointyHexPoint>(baseGrid, spliceOffsets.Length); //Now we make a spliced map. This is just a one-way map -- //it only maps grid points to the world (using the base map plus //splice point offsets var splicedMap = new SplicedMap<PointyHexPoint>(baseMap, spliceOffsets); //Finally, we make the above into a two way map. This map uses a Vonoroi diagram //to do the inverse mapping map = new VoronoiMap<SplicedPoint<PointyHexPoint>>(grid, splicedMap).To3DXY(); //Then we instantiate cells as usual, and put them in our grid. foreach (var point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = map[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; //slightly lighter than the DefaultColors we will use to paint the background cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white*0.1f; cell.name = point.ToString(); grid[point] = cell; } // To make it easier to see how points are mapped, we ExampleUtils.PaintScreenTexture(plane, map.To2D(), ColorFunction); }
private void BuildGrid() { //This is the base grid, we will use it to define //the shape of the splice grid. //The contents is not important. var baseGrid = PointyHexGrid <bool> .BeginShape() .Hexagon(5) .EndShape(); //This is the base map, used for the course //mapping var baseMap = new PointyHexMap(cellDimensions) .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(baseGrid); //Now we make the actual spliced grid. //We feed it the base grid, and the number //of splices we want. grid = new SplicedGrid <SpriteCell, PointyHexPoint>(baseGrid, spliceOffsets.Length); //Now we make a spliced map. This is just a one-way map -- //it only maps grid points to the world (using the base map plus //splice point offsets var splicedMap = new SplicedMap <PointyHexPoint>(baseMap, spliceOffsets); //Finally, we make the above into a two way map. This map uses a Vonoroi diagram //to do the inverse mapping map = new VoronoiMap <SplicedPoint <PointyHexPoint> >(grid, splicedMap).To3DXY(); //Then we instantiate cells as usual, and put them in our grid. foreach (var point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = map[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; //slightly lighter than the DefaultColors we will use to paint the background cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.1f; cell.name = point.ToString(); grid[point] = cell; } // To make it easier to see how points are mapped, we ExampleUtils.PaintScreenTexture(plane, map.To2D(), ColorFunction); }
override public WindowedMap <TPoint> CreateWindowedMap <TPoint>() { if (typeof(TPoint) == typeof(PointyHexPoint)) { var map = new PointyHexMap(new Vector2(69, 80)) .Animate((x, t) => x.Rotate(45 + 0 * t), (x, t) => x.Rotate(-45 + 0 * t)) .Animate((x, t) => x + new Vector2(75 * Mathf.Sin(t / 5.0f), 0), (x, t) => x - new Vector2(75 * Mathf.Sin(t / 5.0f), 0)) .Animate((x, t) => x * (1.5f + 0.5f * Mathf.Sin(t * 7)), (x, t) => x / (1.5f + 0.5f * Mathf.Sin(t * 7))) .WithWindow(ExampleUtils.ScreenRect); return((WindowedMap <TPoint>)(object) map); } return(null); }
public void GenerateMesh() { var grid = PointyHexGrid <int> .Hexagon(50); foreach (var point in grid) { grid[point] = Random.Range(0, textureCount); } var dimensions = new Vector2(69, 80); var map = new PointyHexMap(dimensions) .WithWindow(new Rect(0, 0, 0, 0)) .AlignMiddleCenter(grid) .To3DXZ(); var mesh = new Mesh(); GetComponent <MeshFilter>().mesh = mesh; GenerateMesh(mesh, grid, map, dimensions); }