Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Simple CSV based tilemap importer

Discussion in 'Works In Progress - Archive' started by FlodLab, Mar 13, 2013.

  1. FlodLab

    FlodLab

    Joined:
    Feb 6, 2013
    Posts:
    30
    Maybe somone is interested in a simple csv based Tilemap importer.

    Can be used to generate tile maps (i.e. painted in the tiled editor) based on a comma separated value string.

    Updated description:

    Import the Package:
    Download here: View attachment $TileSetMesh.unitypackage

    Instructions:
    To crate a new CSV Based Tileset, select GameObject->Create Other->CSV Based Tileset


    A new GameObject called “CSV Mesh” will be created
    Showing a 2x2 Grid in a pink color.



    In the inspector you have the following Parameters:
    Tileset: A material containing your Texture for the Tileset.
    CSV_Input: Your CSV String describing witch tile part to use at witch position.
    CSV_Cols: after how many values, a new Line should be created.
    e.g. CSV_Input: 1,2,3,4
    CSV_Cols:2
    Would result a two by two mesh
    Tileset Columns: Wow many horizontal columns does your texture have
    Tileset Rows : Wow many vertical rows does your texture have
    for example: the contained texture has 3 columns and 6 rows
    Starts With: Do you refer the top left tile as 0 or 1
    Spacing: how many pixels from top and left should be skipped before each tile.
    Margin: how many pixels should be skipped on bottom right after each tile.
    Update Mesh: Re-Generates the mesh using updated values

    Example:

    created a 10x10 Map in Tiled
    And exported it to .json format
    Open the .json File using a texteditor.



    Copy the content of the data part into your clipboard (everything between “[“ and ”]”
    In my sample this is
    11, 2, 14, 14, 14, 14, 14, 3, 18, 11, 18, 12, 16, 16, 16, 16, 16, 10, 18, 11, 17, 5, 8, 9, 16, 16, 16, 10, 17, 17, 18, 17, 11, 5, 9, 16, 16, 10, 17, 17, 14, 14, 3, 18, 5, 9, 16, 13, 14, 14, 16, 16, 13, 3, 17, 5, 8, 9, 16, 16, 16, 16, 16, 13, 14, 14, 3, 5, 8, 8, 16, 16, 16, 16, 16, 16, 10, 18, 18, 11, 16, 16, 16, 16, 16, 16, 13, 3, 11, 17, 16, 16, 16, 16, 16, 16, 16, 10, 11, 17

    • Paste that value into CSV_Input
    • Set CSV_Cols to 10
    • Use the provided “watergrass” material as tileset
    • Set Tileset Cols to 3
    • Set Tileset Rows to 6
    • Set Start With to one
    • Set spacing and margin to 1
    • Hit Update Mesh in the inspector

    See your generated Plane in the SceneEditor:

     
    Last edited: Mar 14, 2013
  2. FlodLab

    FlodLab

    Joined:
    Feb 6, 2013
    Posts:
    30
    updated description