Giter Site home page Giter Site logo

unitytilemap's Introduction

UnityTileMap

A TileMap library for Unity written in C#.

It provides a method to stitch together many Sprites into a single large texture which is much more efficient to render rather than having each tile be a separate GameObject.

Limitations

  • If you have enough tiles to make the texture larger than the maximum texture size the TileMeshGrid class is supposed to create a grid of textures, but that logic hasn't been written yet.
  • There is no built in support for layering, while there is nothing wrong with creating multiple TileMaps with different z coordinate I would like something more formal.

Credits

unitytilemap's People

Contributors

alexanderfast avatar brendor avatar daxea avatar rakkarage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unitytilemap's Issues

Chunk Manager

There is a maximum size for a TileMap (depending on MeshMode, max texture size for SingleQuad and max vertex count if QuadGrid). To get around this limitation a ChunkManager class should be added.

It's main responsibility is to automatically and under-the-hood split up the TileMap into several chunks, thus circumventing the above limitations.

It should support three ChunkModes which will most likely be three implementations/classes. Those are (names obviously subject to change):

Single Chunk

For use when the above limitations doesn't become a problem, easier to understand and work with for newcomers experimenting with the code.

Fixed Size

For use when the above limitations do become a problem and the TileMap needs to be split. The number and size of chunks are known upfront making it somewhat easy to work with.

Flexible Grid

For use when the TileMap becomes so large that it's impossible to keep it all instantiated at once. There needs be methods of loading and unloading chunks. This also supports the use-case of "infinite worlds". Like MineCraft, the first time a chunk is visited it's generated, when the player walks away it's unloaded, when the player returns it's reloaded (not re-generated).

flip & rotate

got it kinda working like this but of course there is a better way

        if (rotate == TileRotate.Rotate0)
        {
            if (flip == TileFlip.FlipNone)
            {
                // 0-1
                //  /
                // 2-3
                // rotate 0
                uv[index + 0] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 1] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 2] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 3] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
            else if (flip == TileFlip.FlipX)
            {
                // 1-0
                //  /
                // 3-2
                // rotate 0 flip x
                uv[index + 1] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 0] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 3] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 2] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
            else if (flip == TileFlip.FlipY)
            {
                // 2-3
                //  /
                // 0-1
                // rotate 0 flip y
                uv[index + 2] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 3] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 0] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 1] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
        }
        else if (rotate == TileRotate.Rotate90)
        {
            if (flip == TileFlip.FlipNone)
            {
                // 2-0
                //  /
                // 3-1
                // rotate 90
                uv[index + 2] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 0] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 3] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 1] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
            else if (flip == TileFlip.FlipX)
            {
                // 3-1
                //  /
                // 2-0
                // rotate 90 flip x
                uv[index + 3] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 1] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 2] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 0] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
            else if (flip == TileFlip.FlipY)
            {
                // 0-2
                //  /
                // 1-3
                // rotate 90 flip y
                uv[index + 0] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 2] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 1] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 3] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
        }
        else if (rotate == TileRotate.Rotate180)
        {
            if (flip == TileFlip.FlipNone)
            {
                // 3-2
                //  /
                // 1-0
                // rotate 180
                uv[index + 3] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 2] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 1] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 0] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
            else if (flip == TileFlip.FlipX)
            {
                // 2-3
                //  /
                // 0-1
                // rotate 180 flip x
                uv[index + 2] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 3] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 0] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 1] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
            else if (flip == TileFlip.FlipY)
            {
                // 1-0
                //  /
                // 3-2
                // rotate 180 flip y
                uv[index + 1] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 0] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 3] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 2] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
        }
        else if (rotate == TileRotate.Rotate270)
        {
            if (flip == TileFlip.FlipNone)
            {
                // 1-3
                //  /
                // 0-2
                // rotate 270
                uv[index + 1] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 3] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 0] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 2] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
            else if (flip == TileFlip.FlipX)
            {
                // 0-2
                //  /
                // 1-3
                // rotate 270 flip x
                uv[index + 0] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 2] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 1] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 3] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
            else if (flip == TileFlip.FlipY)
            {
                // 3-1
                //  /
                // 2-0
                // rotate 270 flip y
                uv[index + 3] = ToUv(new Vector2(tr.xMin, tr.yMin), Texture);
                uv[index + 1] = ToUv(new Vector2(tr.xMax, tr.yMin), Texture);
                uv[index + 2] = ToUv(new Vector2(tr.xMin, tr.yMax), Texture);
                uv[index + 0] = ToUv(new Vector2(tr.xMax, tr.yMax), Texture);
            }
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.