public void SpawnObstacles()
    {
        var cells = _cellGrid.Cells;

        for (int i = 0; i < _obstaclesParent.childCount; i++)
        {
            var obstacle = _obstaclesParent.GetChild(i);

            var cell = cells.OrderBy(h => Math.Abs((h.transform.position - obstacle.transform.position).magnitude)).First();
            if (!cell.IsTaken)
            {
                cell.IsTaken = true;
                CustomSquare square = cell as CustomSquare;
                if (square != null)
                {
                    square.isTakenByObstacle = true;
                }
                var     bounds = getBounds(obstacle);
                Vector3 offset = new Vector3(0, bounds.y, 0);
                obstacle.localPosition = cell.transform.localPosition + offset;
            }
            else
            {
                Destroy(obstacle.gameObject);
            }
        }
    }
Esempio n. 2
0
    public override void Initialize()
    {
        base.Initialize();
        transform.localPosition = new Vector3(transform.localPosition.x, 0.5f, transform.localPosition.z);

        CustomSquare cell = Cell as CustomSquare;

        cell.unit = this;
    }
Esempio n. 3
0
    public override void OnCellSelected(Cell cell, List <Cell> targetCells)
    {
        _unit.abilityActionUsable = false;
        _unit.isActing            = true;
        _unit.animator.SetTrigger("Ability");

        CustomSquare square = cell as CustomSquare;

        _targetSquares = targetCells;
    }
Esempio n. 4
0
    public override void OnCellSelected(Cell cell, List <Cell> gridCells)
    {
        _unit.abilityActionUsable = false;
        _unit.isActing            = true;
        _unit.animator.SetTrigger("Ability");

        CustomSquare square = cell as CustomSquare;

        _targetSquares = square.GetNeighbours(gridCells);
        _targetSquares.Add(cell);
    }
Esempio n. 5
0
    private IEnumerator DestroyWhenStopped()
    {
        while (isActing || _isAnimating)
        {
            yield return(null);
        }

        CustomSquare square = Cell as CustomSquare;

        if (square)
        {
            square.unit = null;
        }
        MarkAsDestroyed();

        GameController gameController = FindObjectOfType <GameController>();

        gameController.DeregisterUnitFromPlayer(this);

        _unitBody.transform.SetParent(transform.parent);
        Destroy(gameObject);
    }
Esempio n. 6
0
    public override void Move(Cell destinationCell, List <Cell> path)
    {
        Cell.UnMark();

        CustomSquare currentSquare = Cell as CustomSquare;

        if (currentSquare)
        {
            currentSquare.unit = null;
        }
        Debug.Assert(currentSquare, "Cell is not custom square");

        base.Move(destinationCell, path);
        MovementPoints = 0;

        CustomSquare destSquare = destinationCell as CustomSquare;

        if (destSquare)
        {
            destSquare.unit = this;
        }
        Debug.Assert(destSquare, "Cell is not custom square");
    }