Beispiel #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);
        }
Beispiel #2
0
        public void BuildTileset(TileInstance[] tiles)
        {
            //if we are also an intgrid layer, then we already reduced our position in the intGridBuilder
            if (!Layer.IsIntGridLayer)
            {
                RoundTilemapPos();
            }

            _tiles = tiles;

            _tilesetProvider.Clear();

            TilesetDefinition definition = EvaluateTilesetDefinition();

            if (definition == null)
            {
                Debug.LogError($"LDtk: Tileset Definition for {Layer.Identifier} was null.");
                return;
            }

            LDtkRelativeGetterTilesetTexture getter = new LDtkRelativeGetterTilesetTexture();
            Texture2D texAsset = getter.GetRelativeAsset(definition, Importer.assetPath);

            if (texAsset == null)
            {
                return;
            }

            Importer.SetupAssetDependency(texAsset);
            LogPotentialTextureProblems(texAsset);

            //figure out if we have already built a tile in this position. otherwise, build up to the next tilemap. build in a completely seperate p[ath if this is an offset position from the normal standard coordinates
            for (int i = _tiles.Length - 1; i >= 0; i--)
            {
                TileInstance tileData = _tiles[i];
                Tilemap      tilemap  = _tilesetProvider.GetTilemapFromStacks(tileData.UnityPx, (int)Layer.GridSize);


                Tilemaps.Add(tilemap);

                TileBase tile = Importer.GetTile(texAsset, tileData.UnitySrc, (int)Layer.TilesetDefinition.TileGridSize);

                SetTile(tileData, tilemap, tile);
            }

            //set each layer's alpha
            foreach (Tilemap tilemap in _tilesetProvider.Tilemaps)
            {
                AddLayerOffset(tilemap);
                tilemap.SetOpacity(Layer);
            }
        }
        public void BuildTileset(TileInstance[] tiles)
        {
            //if we are also an intgrid layer, then we already reduced our position
            if (!Layer.IsIntGridLayer)
            {
                RoundTilemapPos();
            }

            _tiles = tiles;

            _tilesetProvider.Clear();


            TilesetDefinition definition = Layer.IsAutoLayer
                ? Layer.Definition.AutoTilesetDefinition
                : Layer.Definition.TilesetDefinition;

            LDtkRelativeGetterTilesetTexture getter = new LDtkRelativeGetterTilesetTexture();
            Texture2D texAsset = getter.GetRelativeAsset(definition, Importer.assetPath);

            if (texAsset == null)
            {
                return;
            }


            //figure out if we have already built a tile in this position. otherwise, build up to the next tilemap
            for (int i = _tiles.Length - 1; i >= 0; i--)
            {
                TileInstance tileData = _tiles[i];
                Tilemap      tilemap  = _tilesetProvider.GetAppropriatelyLayeredTilemap(tileData.UnityPx);


                Tilemaps.Add(tilemap);

                TileBase tile = Importer.GetTile(texAsset, tileData.UnitySrc, (int)Layer.TilesetDefinition.TileGridSize);

                SetTile(tileData, tilemap, tile);
            }

            //set each layer's alpha
            foreach (Tilemap tilemap in _tilesetProvider.Tilemaps)
            {
                tilemap.SetOpacity(Layer);
            }
        }