Esempio n. 1
0
    private void OnMouseOver()
    {
        //if left or right click
        if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
        {
            RemovePathIndexes();
            highlightColour = Input.GetMouseButtonDown(1) ? Color.red : Color.yellow; //red for delete, yellow for create
            state          |= eSquareState.highlighted;
            startSquare     = gridCoord;
            endSquare       = startSquare;
            drawHorizontal  = true;
            drawPathIndexes.Add(GridUtilities.TwoToOne(startSquare));
        }
        else if (Input.GetMouseButton(0) || Input.GetMouseButton(1)) //left or right click down
        {
            //skip if same tile as last time
            if (gridCoord == endSquare)
            {
                return;
            }
            bool prevDrawHor = drawHorizontal;
            drawHorizontal = IsHorizontal(startSquare, gridCoord, drawHorizontal);

            //If we've changed direction our whole list is wrong
            if (prevDrawHor != drawHorizontal)
            {
                RemovePathIndexes();

                int startIndex = GridUtilities.TwoToOne(startSquare);
                int diff       = drawHorizontal ? startSquare.x - gridCoord.x : startSquare.y - gridCoord.y;
                int direction  = diff < 0 ? 1 : -1;
                int boxCount   = Mathf.Abs(diff) + 1; //plus one to include starting box
                int modifier   = drawHorizontal ? 1 : Grid.width;

                for (int i = 0; i < boxCount; ++i)
                {
                    int index = startIndex + (modifier * i * direction);
                    drawPathIndexes.Add(index);
                    Grid.squares[index].state |= eSquareState.highlighted;
                }
            }
            else
            {
                int diff      = drawHorizontal ? startSquare.x - endSquare.x : startSquare.y - endSquare.y;
                int direction = diff < 0 ? 1 : -1;
                int newDiff   = drawHorizontal ? endSquare.x - gridCoord.x : endSquare.y - gridCoord.y;
                int newDir    = newDiff < 0 ? 1 : -1;
                int boxCount  = Mathf.Abs(newDiff);
                int modifier  = drawHorizontal ? 1 : Grid.width;

                for (int i = 0; i < boxCount; ++i)
                {
                    if (newDir != direction && diff != 0)
                    {
                        if (drawPathIndexes.Count == 1)
                        {
                            direction *= -1;
                            continue;
                        }
                        int index = drawPathIndexes[drawPathIndexes.Count - 1];
                        Grid.squares[index].state &= ~eSquareState.highlighted;
                        drawPathIndexes.Remove(index);
                    }
                    else
                    {
                        int index = drawPathIndexes[drawPathIndexes.Count - 1] + (modifier * newDir);
                        Grid.squares[index].state |= eSquareState.highlighted;
                        drawPathIndexes.Add(index);
                    }
                }
            }

            endSquare = gridCoord;
        }
    }
Esempio n. 2
0
 void OnMouseExit()
 {
     //while mouse is over tile it is selected
     state &= ~eSquareState.selected;
 }
Esempio n. 3
0
 void OnMouseEnter()
 {
     //tile is selected while mouse is over it.
     state |= eSquareState.selected;
 }