Beispiel #1
0
    public void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 worldPosition = GridBuilderUtils.ScreenToWorld(gridRoot, Input.mousePosition);
            var     bigPoint      = bigMap[worldPosition];

            if (grid.BaseGrid.Contains(bigPoint))
            {
                var bigWorldPosition   = bigMap[bigPoint];
                var smallWorldPosition = worldPosition - bigWorldPosition;
                var smallPoint         = smallMap[smallWorldPosition];

                if (grid.GetSmallGrid(bigPoint).Contains(smallPoint))
                {
                    var cell = grid[bigPoint, smallPoint];
                    cell.HighlightOn = !cell.HighlightOn;
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Vector3 worldPosition = GridBuilderUtils.ScreenToWorld(gridRoot, Input.mousePosition);
            var     bigPoint      = bigMap[worldPosition];

            if (grid.BaseGrid.Contains(bigPoint))
            {
                var bigWorldPosition   = bigMap[bigPoint];
                var smallWorldPosition = worldPosition - bigWorldPosition;
                var smallPoint         = smallMap[smallWorldPosition];

                if (grid.GetSmallGrid(bigPoint).Contains(smallPoint))
                {
                    var point = grid.CombinePoints(bigPoint, smallPoint);

                    if (cellSelectionState == 0)
                    {
                        SelectFirstPoint(point);
                    }
                    else
                    {
                        SelectLastPoint(point);
                    }
                }
            }
        }
    }
	private void BuildGrid()
	{
		grid = new NestedRectGrid<SpriteCell>(bigDimensions, smallDimensions);

		var bigCellDimensions = new Vector2(cellDimensions.x*smallDimensions.X, cellDimensions.y*smallDimensions.Y);

		bigMap = new RectMap(bigCellDimensions * 1.05f)
			.AnchorCellBottomLeft()
			.WithWindow(ExampleUtils.ScreenRect)
			.AlignMiddleCenter(grid.BaseGrid) //pass in the base grid
			.Scale(1.2f)
			.To3DXY();

		smallMap = new RectMap(cellDimensions)
			.Scale(1.05f)
			.To3DXY();

		foreach (var bigPoint in grid.BaseGrid)
		{
			var smallGrid = grid.GetSmallGrid(bigPoint);

			foreach (var smallPoint in smallGrid)
			{
				SpriteCell cell = Instantiate(cellPrefab);
				cell.transform.parent = gridRoot.transform;
				cell.transform.localScale = Vector3.one;
				cell.transform.localPosition = bigMap[bigPoint] + smallMap[smallPoint];

				var colorIndex = bigPoint.GetColor(2, 1, 1)*4 + smallPoint.GetColor(3, 1, 1);

				cell.Color = ExampleUtils.Colors[colorIndex];
				cell.name = bigPoint.ToString() + " | " + smallPoint.ToString();
				grid[bigPoint, smallPoint] = cell;
			}
		}
	}
Beispiel #3
0
    private void BuildGrid()
    {
        grid = new NestedRectGrid <SpriteCell>(bigDimensions, smallDimensions);

        var bigCellDimensions = new Vector2(cellDimensions.x * smallDimensions.X, cellDimensions.y * smallDimensions.Y);

        bigMap = new RectMap(bigCellDimensions * 1.05f)
                 .AnchorCellBottomLeft()
                 .WithWindow(ExampleUtils.ScreenRect)
                 .AlignMiddleCenter(grid.BaseGrid)        //pass in the base grid
                 .Scale(1.2f)
                 .To3DXY();

        smallMap = new RectMap(cellDimensions)
                   .Scale(1.05f)
                   .To3DXY();

        foreach (var bigPoint in grid.BaseGrid)
        {
            var smallGrid = grid.GetSmallGrid(bigPoint);

            foreach (var smallPoint in smallGrid)
            {
                SpriteCell cell = Instantiate(cellPrefab);
                cell.transform.parent        = gridRoot.transform;
                cell.transform.localScale    = Vector3.one;
                cell.transform.localPosition = bigMap[bigPoint] + smallMap[smallPoint];

                var colorIndex = bigPoint.GetColor(2, 1, 1) * 4 + smallPoint.GetColor(3, 1, 1);

                cell.Color = ExampleUtils.Colors[colorIndex];
                cell.name  = bigPoint.ToString() + " | " + smallPoint.ToString();
                grid[bigPoint, smallPoint] = cell;
            }
        }
    }