{"id":575,"date":"2017-01-18T16:45:12","date_gmt":"2017-01-18T15:45:12","guid":{"rendered":"http:\/\/davikingcode.com\/blog\/?p=575"},"modified":"2017-01-20T18:35:53","modified_gmt":"2017-01-20T17:35:53","slug":"unity-generate-spritesheets-at-runtime","status":"publish","type":"post","link":"https:\/\/davikingcode.com\/blog\/unity-generate-spritesheets-at-runtime\/","title":{"rendered":"Unity &#8211; generate SpriteSheets at runtime!"},"content":{"rendered":"<p>Unity and plugins provide many great ways to build Sprite Sheets. However they&#8217;re used directly into Unity Editor or with an external software which is perfect in many case, but none provide the ability to generate SpriteSheets at runtime. So we made our own library.<\/p>\n<p>The goal of a sprite sheet is to pack as many sub-textures as possible in one big texture. So the first thing to do was a packing algorithm. Fortunately we remembered the one made and open-sourced by <a href=\"https:\/\/villekoskela.org\/2012\/08\/12\/rectangle-packing\/\" target=\"_blank\">Ville Koskela<\/a> in AS3, so we started with a Unity C# port.<br \/>\n<a href=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/RuntimeSpriteSheetsGenerator\" target=\"_blank\">Click here<\/a> to view the Unity rectangle packing example running in your browser in WebGL!<br \/>\n<a href=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/RuntimeSpriteSheetsGenerator\"><img loading=\"lazy\" src=\"http:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/2017-01-20-16.46.43-291x300.png\" alt=\"\" width=\"291\" height=\"300\" class=\"alignnone size-medium wp-image-603\" srcset=\"https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/2017-01-20-16.46.43-291x300.png 291w, https:\/\/davikingcode.com\/blog\/wp-content\/uploads\/2017\/01\/2017-01-20-16.46.43.png 535w\" sizes=\"(max-width: 291px) 100vw, 291px\" \/><\/a><\/p>\n<p>Once the packing algorithm done, we worked on a cache system so the generated sprite sheets are written and saved on disk for a future loading. The generator process won&#8217;t be needed anymore unless you increase your cache version!<\/p>\n<p>Give a try to <a href=\"https:\/\/github.com\/DaVikingCode\/UnityRuntimeSpriteSheetsGenerator\" target=\"_blank\">UnityRuntimeSpriteSheetsGenerator<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unity and plugins provide many great ways to build Sprite Sheets. However they&#8217;re used directly into Unity Editor or with an external software which is perfect in many case, but none provide the ability to generate SpriteSheets at runtime. So we made our own library. The goal of a sprite sheet is to pack as &hellip; <a href=\"https:\/\/davikingcode.com\/blog\/unity-generate-spritesheets-at-runtime\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Unity &#8211; generate SpriteSheets at runtime!<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_discordance_state":"","_discordance_checked":true},"categories":[15],"tags":[5],"_links":{"self":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts\/575"}],"collection":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/comments?post=575"}],"version-history":[{"count":8,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts\/575\/revisions"}],"predecessor-version":[{"id":605,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/posts\/575\/revisions\/605"}],"wp:attachment":[{"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/media?parent=575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/categories?post=575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davikingcode.com\/blog\/wp-json\/wp\/v2\/tags?post=575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}