I spend most my days these days in Unity and I really love it. There really isn’t much you can’t do in it and it is such a great sandbox for learning new things in C#. Quite a bit of my time lately has been focused on the application architecture, but also the UI, and it has been such a fantastic learning experience all in all and I have delved deep into design patterns, generics and some more advanced topics in .net.

While working heavily with UI in the past months, so many ideas kept popping into my head that I’d love to create… one of the ideas that I was most fond of was in-app paint like functionality where the user can draw on the screen with their mouse/pointer. Of course, Unity doesn’t have a built in feature for this, but they do give you all the things to do it (and is relatively easy to do too!). You could go on the Unity Asset Store and there are a whole bunch on there, but that would be cheating right?! Here is a little demo of where I got to over a weekend…

Unity Paint

This isn’t as complete as I would like, but was a lot of fun to make. I did run into a memory leak… ALWAYS REMEMBER TO DISPOSE OF YOUR RENDER TEXTURES!!! This tripped me up for a while as I was baffled why it was consuming like 3GB+ memory and counting and build was crashing, kinda obvious after I realised what I forgot to do… but we all make silly mistakes! 🙂 Also, to keep the texture size from getting stupid large (say 8K display) I have limited to 1080×720 (or pre-scaled canvas dimensions), this only applies to the Screenspace Overlay mode as Camera Overlay doesn’t scale apparently. I also added a simple colour picker based on Unity’s own… this is quick and dirty, I originally wanted to do it with a Line Renderer, but it started getting way too complex and I eventually did it with imagery instead as it was way quicker. Not the nicest solution, but it works.

If you want to see how it works, you can check out the project here…

https://github.com/DanimoSite/ScreenSpacePixelDrawing

Other things I would like to add when I get some time (no promises) are :-

  • Undo/Redo
  • Pixel Fill, like the paint bucket in MS Paint
  • Import sketches
  • Layers
  • Different brush textures
  • Gradients
  • Anti-Aliasing effects

The project is free to use and do with it as you wish, but I won’t be supporting any development for it so if you do choose to integrate it in your own projects then do so at your own risk and development cost. I hope you do find it useful though! 🙂

Advertisement