Exemplo n.º 1
0
        private GridMap <GridPoint2> CreateMap(IExplicitShape <GridPoint2> grid)
        {
            var cellDimensions = cellPrefab.Sprite.rect.size;
            var scale          = new Vector3(1, .85f, 1);    //VectorExtensions.To3DXY(cellDimensions, 1);

            var spaceMap =
                Map
                .Translate(new Vector3(0, 3.2f, 0))
                .ComposeWith(Map.Linear(Matrixf33.Scale(scale)))
                .ComposeWith(Map.Polar(cellDimensions.y, 1.0f / gridDimensions.x));

            var roundMap         = Map.RectRound();
            var parallelogramMap = Map.ParallelogramWrapX(gridDimensions.x);
            var composeMap       = parallelogramMap.ComposeWith(roundMap);

            var spaceAlignMap = spaceMap.AlignGridInRect(grid, p => scale,
                                                         new Bounds(ScreenRect.center, ScreenRect.size),
                                                         horizontalAlignment, verticalAlignment);
            var spaceAlignAnchorMap = spaceAlignMap.AnchorPivotInRect(grid, p => scale, horizontalAnchorPivot,
                                                                      verticalAnchorPivot);

            var gridMap = new GridMap <GridPoint2>(spaceAlignAnchorMap, composeMap);

            return(gridMap);
        }
Exemplo n.º 2
0
        protected override IMap <Vector3, Vector3> Transform(IMap <Vector3, Vector3> input)
        {
            var matrix = Matrixf33.Scale(scaleFactor);
            var map    = Map.Linear(matrix);

            return((input == null) ? map : input.ComposeWith(map));
        }
Exemplo n.º 3
0
        private GridMap <GridPoint2> CreateMap(IExplicitShape <GridPoint2> grid)
        {
            var cellDimensions = cellPrefab.Sprite.rect.size;

            //static invocation is used here because the Unity compiler
            //gets confused otherwise.
            var scale = cellDimensions.To3DXY(1);

            var scaleSpaceMap = Map.Linear(Matrixf33.Scale(scale));
            var spaceMap      = Map.Linear(PointyHexPoint.SpaceMapTransform.Mul(Matrixf33.RotateZ(-30 * Mathf.Deg2Rad)));

            spaceMap = spaceMap.ComposeWith(scaleSpaceMap);
            var roundMap = Map.HexRound();

            var spaceAlignMap = spaceMap.AlignGridInRect(
                grid,
                p => scale,
                p => p.ToVector2().To3DXY(),
                new Bounds(ScreenRect.center, ScreenRect.size),
                horizontalAlignment, verticalAlignment);
            var spaceAlignAnchorMap = spaceAlignMap.AnchorPivotInRect(grid, p => scale, horizontalAnchorPivot,
                                                                      verticalAnchorPivot);

            var gridMap = new GridMap <GridPoint2>(spaceAlignAnchorMap, roundMap);

            return(gridMap);
        }
Exemplo n.º 4
0
        private IMap <Vector3, GridPoint2> CreateMap()
        {
            var cellDimensions = cellPrefab.SharedMesh.bounds.size;
            var spaceMap       = Map.Linear(Matrixf33.Scale(cellDimensions));
            var roundMap       = Map.RectRound();

            return(spaceMap.ComposeWith(roundMap));
        }
Exemplo n.º 5
0
        protected override IMap <Vector3, Vector3> Transform(IMap <Vector3, Vector3> input)
        {
            var linearMap = Map.Linear(
                Matrixf33
                .RotateZ(45 * Mathf.Deg2Rad)
                .Mul(Matrixf33.Scale(new Vector3(PointyHexPoint.Sqrt3, 1, 1))));

            return((input == null) ? linearMap : input.ComposeWith(linearMap));
        }
Exemplo n.º 6
0
        private GridMap <GridPoint3> CreateMap()
        {
            var cellDimensions = cellPrefab.SharedMesh.bounds.size;

            var spaceMap = Map.Linear(Matrixf33.Scale(cellDimensions));
            var roundMap = Map.BlockRound();
            var gridMap  = new GridMap <GridPoint3>(spaceMap, roundMap);

            return(gridMap);
        }
Exemplo n.º 7
0
        private GridMap <int> CreateMap()
        {
            var cellDimensions = cellPrefab.Sprite.rect.size;
            var scale          = VectorExtensions.To3DXY(cellDimensions, 1);

            var spaceMap =
                Map
                .Translate(new Vector3(0, 1, 0))
                .ComposeWith(Map.Polar(3, 1.0f / gridSize))
                .ComposeWith(Map.Linear(Matrixf33.Scale(scale)));

            var roundMap = Map.PointRound();
            var gridMap  = new GridMap <int>(spaceMap, roundMap);

            return(gridMap);
        }
Exemplo n.º 8
0
        private GridMap <GridPoint2> CreateMap(IExplicitShape <GridPoint2> grid)
        {
            var cellDimensions = cellPrefab.Sprite.rect.size;
            var scale          = cellDimensions.To3DXY(1);
            var spaceMap       = Map.Linear(PointyHexPoint.RawSpaceMapTransform * Matrixf33.Scale(scale * 0.992f));
            var roundMap       = Map.HexRound();

            var spaceAlignMap = spaceMap.AlignGridInRect(grid, p => scale,
                                                         new Bounds(ScreenRect.center, ScreenRect.size),
                                                         horizontalAlignment, verticalAlignment);
            var spaceAlignAnchorMap = spaceAlignMap.AnchorPivotInRect(grid, p => scale, horizontalAnchorPivot,
                                                                      verticalAnchorPivot);

            var gridMap = new GridMap <GridPoint2>(spaceAlignAnchorMap, roundMap);

            return(gridMap);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a Mesh grid using the mesh data provided for each cell.
        /// </summary>
        /// <param name="mesh">Mesh to use to place the generated mesh grid.</param>
        /// <param name="width">Width of the grid.</param>
        /// <param name="height">Height of the grid.</param>
        /// <param name="prefab">Prefab to use for the cells on the grid.</param>
        /// <param name="meshData">The mesh data information to use for the cells.</param>
        /// <param name="cellDimensions">The cell's dimensions.</param>
        public static IGrid <GridPoint2, T> RectXY <T>(
            Mesh mesh,
            int width,
            int height,
            MeshData meshData,
            Vector2 cellDimensions)
        {
            var spaceMap = Map.Linear(Matrixf33.Scale(cellDimensions.To3DXY(1)));
            var center   = new Vector2(width, height) / 2 - Vector2.one * 0.5f;

            spaceMap = spaceMap.PreTranslate(-center);

            var roundMap = Map.RectRound();
            var map      = new GridMap <GridPoint2>(spaceMap, roundMap);
            var grid     = Rect <T>(width, height);

            GridBuilderUtils.InitMesh(mesh, grid, map, meshData, false, true);

            return(grid);
        }
Exemplo n.º 10
0
        private GridMap <GridPoint2> CreateMap(IExplicitShape <GridPoint2> grid)
        {
            var cellDimensions = cellPrefab.Sprite.rect.size;

            //static invocation is used here because the Unity compiler
            //gets confused otherwise.
            var scale = cellDimensions.To3DXY(1);

            var spaceMap = Map.Linear(Matrixf33.Scale(scale));
            var roundMap = Map.RectRound();

            var spaceAlignMap = spaceMap.AlignGridInRect(grid, p => scale,
                                                         new Bounds(ScreenRect.center, ScreenRect.size),
                                                         horizontalAlignment, verticalAlignment);
            var spaceAlignAnchorMap = spaceAlignMap.AnchorPivotInRect(grid, p => scale, horizontalAnchorPivot,
                                                                      verticalAnchorPivot);

            var gridMap = new GridMap <GridPoint2>(spaceAlignAnchorMap, roundMap);

            return(gridMap);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a Pysical Grid.
        /// </summary>
        /// <param name="root">GameObject where all the cells are going to be stored.</param>
        /// <param name="width">Width of the grid.</param>
        /// <param name="height">Height of the grid.</param>
        /// <param name="prefab">Prefab to use for the cells on the grid.</param>
        /// <param name="cellDimensions">The cell's dimensions.</param>
        public static PhysicalGrid <GridPoint2, T> RectXY <T>(
            GameObject root,
            int width,
            int height,
            T prefab,
            Vector2 cellDimensions)
            where T : Component
        {
            var spaceMap = Map.Linear(Matrixf33.Scale(cellDimensions.To3DXY(1)));
            var center   = new Vector2(width, height) / 2 - Vector2.one * 0.5f;

            spaceMap = spaceMap.PreTranslate(-center);

            var grid     = Rect <T>(width, height);
            var roundMap = Map.RectRound();
            var map      = new GridMap <GridPoint2>(spaceMap, roundMap);

            GridBuilderUtils.InitTileGrid(grid, map, prefab, root, (point, cell) => { });

            //root.AddComponent<PhysicalGrid<GridPoint2, T>>();
            return(new PhysicalGrid <GridPoint2, T>(grid, map, root));
        }