[MoonSharp] How can I draw to the screen using lua?

What I am planning to do is to create lua scripts, executed by MoonSharp, which will handle my screen area, with them being able to control not only the canvas but also the camera and world etc.

However, I do not know how to go about this; I know from reading that you can initialize variables within moonsharp by passing the class and type to the object, but I don’t know how I would go about initializing new classes or modifying the canvas from the script, since I would need to pass in GameObject etc, which I can’t current fathom.

If anyone could help me that’d be great - I’d only need some small sample code that does something similar to what I want, then I could build off of that; I’m currently stuck since I don’t know how to proceed with my plan.

My reason for doing this is that I would like to build my entire ui using lua and run the scripts, allowing users to create their own custom scripts within the game, customising and creating their own ui etc.

The LUA-in-Unity3D interfaces I have seen basically map parts (or all) of the Unity API to make it accessible from LUA.

You can “draw to the screen” in any number of ways with Unity:

  • make LineRenderer objects with the requisite parameters to draw lines (or license something like Vectrosity)
  • emplace, scale, or rotate sprites onto the screen to effect your drawing.
  • place a blank bitmap onscreen via some geometry or UI element and then modify the pixels in that bitmap.
  • make 3D geometry out of primitives or prefabs
  • etc. etc. etc…

Your LUA code will simply have to do one (or more) of the above things in precisely the same way you would do it if you were using Unity3D “normally.” I suggest you learn how to do the above things in C# first, because you’ll see immediately how to do it in LUA.