“I had a blank screen, and everything
happened in the code, not on the
scene, so I’d like to keep that
workflow as much as Unity allows it.”
This is totally possible with Unity, but it requires some work.
First, you’ll need an empty scene with a Camera in it. Then you’ll need to attach a C# script to the camera, and that’s basically your entry point for the rest of your code. You can update your generic game objects in the Camera’s Update() method. For example, lets say you have a class called Baddie:
class Baddie
{
float x = 0;
float y = 0;
public void Update()
{
// baddie AI code
}
}
You’d call the Baddie’s Update() method in the Camera’s Update() method.
Rendering is a lot trickier, and I don’t have very good example code at the moment. There are probably multiple (better) approaches, but this is how I did it:
Basically, if you want to render textures manually, you’ll need to create a Mesh object that contains the vertices and UVs of the textures you want to draw. Then, in the Camera’s OnPostRender() method, you can call Graphics.DrawMeshNow(). IIRC, you’ll also need a SpriteRenderer attached to the Camera and call SetPass before DrawMeshNow. The SpriteRenderer will also need to have the relevant Texture object set as its mainTexture. Basically, this is how it might look:
void OnPostRender()
{
spriteRenderer.material.mainTexture = myBaddieTexture;
spriteRenderer.material.SetPass(0);
// update your mesh's vertices and UV coordinates.
Graphics.DrawMeshNow(mesh, Vector3.zero, Quaternion.identity);
}
You can also improve performance by exporting all of your graphics onto the same texture and including all of your sprite coordinates in the same Mesh. (I’m using TexturePacker to help with this.) Depending on your game’s art, this may or may not be feasible, but the less drawing calls you make the better.
Hope this helps point you in the right direction. I used this approach to port my game from XNA/Monogame to Unity, and I had to do very little rewriting at all.