I have a 2D / 3D library that I have written in C# that I would like to use for procedural / runtime mesh creation in Unity as part of a VR application. I have updated the code to strip out any Windows dependencies so it’s now callable from Unity. However, going forwards I would like to still be able to compile it for use on Windows as well as using it in Unity - maintaining a single code base but with optimised geometry / types for the build target.
One thing I want to do is switch my code to use some of Unity math / geometry types - e.g. vectors, etc. to make the code fast / efficient and to remove unnecessary data transformations. I can think of some approaches to doing this, including:
- Using pre-processor definitions and build targets. What’s the easiest way of doing this if there are lots of instances of a class type in use that needs to be substituted?
- Refactoring the code to use interfaces, factories and some sort of IOC container and switching out the concrete type at runtime based on Unity or Windows.
- Using some form of template generation - e.g. T4?
- Give up and create a dedicated Unity version of the code base.
I also have a strong suspicion that this code would be ideal for the C# job system and a data driven design. I certainly want to push a lot of the processing to background tasks or worker threads and will be operating on transform / mesh data.
Thoughts?