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);
        }
    public static void ParseBaseEntityFields <T>(T entity, EntityInstance entityInstance, LDtkLevel level) where T : new()
    {
        EntityDefinition entityDefinition = level.Parent.GetEntityDefinitionFromUid(entityInstance.DefUid);

        ParseBaseField(entity, "Position", (entityInstance.Px + level.Position).ToVector2());
        ParseBaseField(entity, "Pivot", entityInstance._Pivot);
        ParseBaseField(entity, "Size", new Vector2(entityInstance.Width, entityInstance.Height));
        ParseBaseField(entity, "EditorVisualColor", entityDefinition.Color);

        if (entityInstance._Tile != null)
        {
            EntityInstanceTile tileDefinition = entityInstance._Tile;
            Rectangle          rect           = tileDefinition.SrcRect;
            ParseBaseField(entity, "Tile", rect);
        }
    }