コード例 #1
0
    public static void GetNextTilePosByTileDirection(eTileDirection direction, ref sTilePosition tilePos)
    {
        switch (direction)
        {
        case eTileDirection.NORTH_WEST:
            tilePos.tileY++;
            break;

        case eTileDirection.NORTH_EAST:
            tilePos.tileX++;
            break;

        case eTileDirection.SOUTH_EAST:
            tilePos.tileY--;
            break;

        case eTileDirection.SOUTH_WEST:
            tilePos.tileX--;
            break;

        case eTileDirection.IN_TILE:
            break;

        default:
            break;
        }
    }
コード例 #2
0
    public void UpdatePosition(Vector2 position)
    {
        float   speed       = _status.speed + GetCurrentTileCell().GetProperties(eTileLayer.GROUND).speed;
        Vector2 destination = (Vector2)(_transform.position) + (position.normalized * speed * Time.deltaTime);

        TileSystem     tileSystem        = TileSystem.Instance;
        TileCell       curTileCell       = GetCurrentTileCell();
        eTileDirection boundaryDirection = curTileCell.CheckTileBoundary(destination);
        sTilePosition  nextTilePos       = new sTilePosition(_tileX, _tileY);

        TileHelper.GetNextTilePosByTileDirection(boundaryDirection, ref nextTilePos);

        if (tileSystem.CanMoveTileCell(nextTilePos.tileX, nextTilePos.tileY))
        {
            //타일 오프셋에 따른 캐릭터 y값 보정(des = des + (next.offset - cur.offset))
            if (eTileDirection.IN_TILE != boundaryDirection)
            {
                int layerOrder = tileSystem.GetTileCell(nextTilePos.tileX, nextTilePos.tileY).GetGroundLayerOrder();
                var sprites    = GetComponentsInChildren <SpriteRenderer>(true);
                foreach (var spriteRenderer in sprites)
                {
                    spriteRenderer.sortingOrder = layerOrder;
                }

                float curOffset  = curTileCell.GetOffset();
                float nextOffset = tileSystem.GetTileCell(nextTilePos.tileX, nextTilePos.tileY).GetOffset();
                destination.y = destination.y + (nextOffset - curOffset);

                var layer = GetCurrentLayer();
                tileSystem.GetTileCell(_tileX, _tileY).RemoveObject(this, layer);
                tileSystem.GetTileCell(nextTilePos).AddObject(this, layer);
            }

            _tileX = nextTilePos.tileX;
            _tileY = nextTilePos.tileY;

            //z값 -1 : 동일한 레이어 + 동일한 order 에서 캐릭터들이 타일보다 뒤에 있으면 안됨
            transform.position = new Vector3(destination.x, destination.y, -1.0f);
        }
    }