Seanba / Tiled2Unity

Export Tiled Map Editor (TMX) files into Unity
Other
495 stars 120 forks source link

SortingOrder of Layers changes with amount of objects #99

Open falkokoetter opened 7 years ago

falkokoetter commented 7 years ago

Currently I'm working of adding objects to my maps and encounered the following issue/challenge. The sorting order of all GameObjects is incremented for each imported object, i.e. layers and objects in object layers. This leads to all layers above object layers changing sorting order whenever the amount of objects changes. As some scripts, e.g. SpriteDepthInMap rely on a defined layer number, their math gets messed up by this. My suspicion is that the higher sortingOrder combined with a lower number of layers messes up the intervals the Depth buffer uses between horizontal slices of the map.

I will investigate further to maybe pinpoint what exactly happens, but any help would be appreciated.

Below is an abridged example XML showing the increasing sorting order

<Prefab name="gameshop_inner" orientation="Orthogonal" staggerAxis="Y" staggerIndex="Odd" hexSideLength="0" numLayers="4" numTilesWide="20" numTilesHigh="20" tileWidth="16" tileHeight="16" exportScale="0.0625" mapWidthInPixels="320" mapHeightInPixels="320" backgroundColor="#808080" resource="true">
    <GameObject name="Below" x="0" y="0" z="0">
      <TileLayer opacity="1" offsetX="0" offsetY="0" />
      <GameObject name="gameshop_inner_below" copy="mesh_0001" sortingLayerName="" sortingOrder="0" opacity="1" />
    </GameObject>
    <GameObject name="Objects" x="0" y="0" z="-0.05">
      <ObjectLayer offsetX="0" offsetY="0" color="#ff808080" />
      <GameObject name="TileObject" x="8" y="-6" rotation="0" layer="" z="-0.3" scaleX="1" scaleY="1">
        ...
        <GameObject name="TileObject" x="0.5" y="0.5" scaleX="1" scaleY="1">
          <GameObject name="tile_obj" copy="mesh_tile_1234" sortingLayerName="" sortingOrder="1" x="-0.5" y="0.5" />
        </GameObject>
      </GameObject>
      <GameObject name="TileObject" x="11" y="-10" rotation="0" layer="" z="-0.5" scaleX="1" scaleY="1">
        <GameObject name="TileObject" x="0.5" y="0.5" scaleX="1" scaleY="1">
          <GameObject name="tile_obj" copy="mesh_tile_1234" sortingLayerName="" sortingOrder="2" x="-0.5" y="0.5" />
        </GameObject>
      </GameObject>
      <GameObject name="TileObject" x="9" y="-17" rotation="0" layer="" z="-0.85" scaleX="2" scaleY="1">
      ...
      </GameObject>
    </GameObject>
    <GameObject name="SameLayer" x="0" y="0" z="-0.1">
      <TileLayer opacity="1" offsetX="0" offsetY="0" />
      <GameObject name="gameshop_inner_same" copy="mesh_0002" sortingLayerName="" sortingOrder="4" opacity="1" />

    </GameObject>
    <GameObject name="Above" x="0" y="0" z="-0.15">
      <TileLayer opacity="1" offsetX="0" offsetY="0" />
      <GameObject name="gameshop_inner_above" copy="mesh_0003" sortingLayerName="" sortingOrder="5" opacity="1" />
    </GameObject>
    <GameObject name="Collision" x="0" y="0" z="-0.2">
      <TileLayer opacity="0.5" offsetX="0" offsetY="0" />
      <GameObject name="collision" copy="mesh_0004" sortingLayerName="" sortingOrder="6" opacity="0.5" />
      ...
      </GameObject>
    </GameObject>
  </Prefab>