Ejemplo n.º 1
0
        void Start()
        {
            // setup GUI - only for the demo
            GUIResizer.Init(800, 500);
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor = Color.white;

            // Get a reference to Grids 2D System's API
            grid = Grid2D.instance;
            for (int k = 0; k < grid.numCells; k++)
            {
                Texture2D fruitTexture = fruits [Random.Range(0, fruits.Length)];
                DrawFruit(k, fruitTexture);
            }

            grid.OnCellClick += CheckMatchingCells;
        }
Ejemplo n.º 2
0
        void Start()
        {
            // setup GUI - only for the demo
            GUIResizer.Init(800, 500);
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor = Color.white;

            // Get a reference to Grids 2D System's API
            grid = Grid2D.instance;
            for (int k = 0; k < grid.numCells; k++)
            {
                Texture2D fruitTexture = fruits [Random.Range(0, fruits.Length)];

                Vector2 textureOffset   = Vector2.zero;
                Vector2 textureScale    = new Vector2(1f, 0.6f);               // to keep some aspect ratio
                float   rotationDegrees = -90f;

                grid.CellToggle(k, true, Color.white, false, fruitTexture, textureScale, textureOffset, rotationDegrees, true);
            }
        }
Ejemplo n.º 3
0
        // Use this for initialization
        void Start()
        {
            grid = Grid2D.instance;

            // setup GUI resizer - only for the demo
            GUIResizer.Init(800, 500);
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor = Color.white;

            // Configure the grid crossing cost depending on the textures
            for (int k = 0; k < grid.cells.Count; k++)
            {
                int textureIndex = grid.CellGetTextureIndex(k);
                if (textureIndex == 2)
                {
                    grid.CellSetCrossCost(k, 10);
                }
                else
                {
                    grid.CellSetCrossCost(k, 1);
                }
            }

            // Hook into cell click event to toggle start selection or draw a computed path using A* path finding algorithm
            grid.OnCellClick += BuildPath;

            // Position the token
            tokenRow    = grid.rowCount - 1;
            tokenColumn = 5;
            Vector3 position = grid.CellGetPosition(tokenRow, tokenColumn);

            token.transform.position = position;

            // Prepare move points and show available positions
            movePoints = 10;
        }
Ejemplo n.º 4
0
        // Use this for initialization
        void Start()
        {
            grid = Grid2D.instance;

            // setup GUI resizer - only for the demo
            GUIResizer.Init(800, 500);
            labelStyle                  = new GUIStyle();
            labelStyle.alignment        = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor = Color.white;

            isSelectingStart = true;

            Random.InitState(2);

            // Draw some blocked areas
            for (int i = 0; i < 25; i++)
            {
                int row = Random.Range(2, grid.rowCount - 3);
                int col = Random.Range(2, grid.columnCount - 3);

                for (int j = -2; j <= 2; j++)
                {
                    for (int k = -2; k <= 2; k++)
                    {
                        int cellIndex = grid.CellGetIndex(row + j, col + k);
                        grid.CellSetGroup(cellIndex, CELL_OBSTACLE);
                        grid.CellToggle(cellIndex, true, Color.white);
                    }
                }
            }


            // Example: sets crossing costs for hexagon sides and draw a line
            int   barrierCost  = 100;
            Color barrierColor = Color.blue;
            float barrierWidth = 5f;

            for (int k = 0; k < 10; k++)
            {
                int cellIndex = grid.CellGetIndex(10, k + 20);
                if (!grid.cells [cellIndex].canCross)
                {
                    continue;
                }
                if (grid.cells [cellIndex].column % 2 == 0)
                {
                    grid.CellSetSideCrossCost(cellIndex, CELL_SIDE.Top, barrierCost);
                    grid.CellSetSideCrossCost(cellIndex, CELL_SIDE.TopLeft, barrierCost);
                    grid.CellSetSideCrossCost(cellIndex, CELL_SIDE.TopRight, barrierCost);
                    grid.DrawLine(cellIndex, CELL_SIDE.Top, barrierColor, barrierWidth);
                    grid.DrawLine(cellIndex, CELL_SIDE.TopLeft, barrierColor, barrierWidth);
                    grid.DrawLine(cellIndex, CELL_SIDE.TopRight, barrierColor, barrierWidth);
                }
                else
                {
                    grid.CellSetSideCrossCost(cellIndex, CELL_SIDE.Top, barrierCost);
                    grid.DrawLine(cellIndex, CELL_SIDE.Top, barrierColor, barrierWidth);
                }
            }



            // Hook into cell click event to toggle start selection or draw a computed path using A* path finding algorithm
            grid.OnCellClick += (cellIndex) => BuildPath(cellIndex);

            grid.OnCellEnter += (cellIndex) => ShowLineOfSight(cellIndex);
        }