Exemplo n.º 1
0
    public bool canMove(Direction direction)
    {
        MapVector2 tryMovePos = GetPositionAfterTryMove(direction);

        if (tryMovePos.x < 0 || tryMovePos.x >= MapManager.I.MapSize.x ||
            tryMovePos.y < 0 || tryMovePos.y >= MapManager.I.MapSize.y)
        {
            return(false);
        }
        BoxUnit box = BoxManager.I.ExistBoxAtPos(tryMovePos);

        if (box != null)
        {
            Debug.Log("运动方向上有box");
            if (!box.canMove(direction))
            {
                return(false);
            }
        }
        ElementType element = MapManager.I.GetElementAt(tryMovePos.x, tryMovePos.y);

        if (element == ElementType.Wall)
        {
            return(false);
        }
        return(true);
    }