Пример #1
0
        public static Texture2D GetEntityImageAndRect(EntityInstance entityData, string assetPath, out Rect rect)
        {
            rect = Rect.zero;

            EntityInstanceTile tile = entityData.Tile;

            if (tile == null)
            {
                return(null);
            }

            LDtkRelativeGetterTilesetTexture textureGetter = new LDtkRelativeGetterTilesetTexture();
            Texture2D tex = textureGetter.GetRelativeAsset(tile.TilesetDefinition, assetPath);

            if (tex == null)
            {
                return(null);
            }

            Rect src = tile.UnitySourceRect;

            Vector2Int pos        = new Vector2Int((int)src.position.x, (int)src.position.y);
            Vector2Int correctPos = LDtkCoordConverter.ImageSliceCoord(pos, tex.height, (int)src.height);

            Rect actualRect = new Rect(src)
            {
                position = correctPos,
            };

            rect = actualRect;
            return(tex);
        }
        private void ManipulateImageTransform(Transform trans)
        {
            trans.parent = _levelTransform.transform;

            Vector2 levelPosition = LDtkCoordConverter.LevelBackgroundImagePosition(_level.BgPos.UnityTopLeftPx, _level.BgPos.UnityCropRect.height, _importer.PixelsPerUnit, _level.BgPos.UnityScale.y);

            trans.localPosition = levelPosition;

            Vector2 scale = _level.BgPos.UnityScale;

            trans.localScale = new Vector3(scale.x, scale.y, 1);
        }
        private Sprite GetSprite()
        {
            Rect rect = _level.BgPos.UnityCropRect;

            rect.position = LDtkCoordConverter.LevelBackgroundImageSliceCoord(rect.position, _texture.height, rect.height);

            if (!LDtkTextureSpriteSlicer.IsLegalSpriteSlice(_texture, rect))
            {
                Debug.LogError($"Illegal Sprite slice {rect} from texture ({_texture.width}, {_texture.height})");
                return(null);
            }

            Sprite sprite = Sprite.Create(_texture, rect, Vector2.up, _importer.PixelsPerUnit);

            sprite.name = _texture.name;
            return(sprite);
        }
Пример #4
0
        private void BuildIntGridValue(Tilemap tilemapToBuildOn, IntGridValueDefinition definition, int intValueData, LDtkIntGridTile tileAsset)
        {
            Vector2Int cellCoord = LDtkCoordConverter.IntGridValueCsvCoord(intValueData, Layer.UnityCellSize);
            Vector2    coord     = ConvertCellCoord(cellCoord);

            Vector3Int cell = new Vector3Int((int)coord.x, (int)coord.y, 0);

            tilemapToBuildOn.SetTile(cell, tileAsset);
            tilemapToBuildOn.SetTileFlags(cell, TileFlags.None);
            tilemapToBuildOn.SetColor(cell, definition.UnityColor);

            //for some reason a GameObject is instantiated causing two to exist in play mode; maybe because its the import process. destroy it
            GameObject instantiatedObject = tilemapToBuildOn.GetInstantiatedObject(cell);

            if (instantiatedObject != null)
            {
                Object.DestroyImmediate(instantiatedObject);
            }
        }
Пример #5
0
        public void OnDrawHandles()
        {
            if (!LDtkPrefs.ShowEntityShape)
            {
                return;
            }

            if (!_data.Hollow && LDtkPrefs.EntityOnlyHollow)
            {
                return;
            }

            float lineAlpha = _data.LineOpacity;
            float fillAlpha = _data.Hollow ? 0 : _data.FillOpacity;

            Vector2 size = _data.Size;

            Vector2 pos = (Vector2)_transform.position + LDtkCoordConverter.EntityPivotOffset(_data.Pivot, _data.Size);

            DrawShape(pos, size, fillAlpha, lineAlpha);
        }
Пример #6
0
 protected Vector2Int ConvertCellCoord(Vector2Int cellCoord)
 {
     return(LDtkCoordConverter.ConvertCell(cellCoord, (int)Layer.CHei));
 }