I’m writing a particle system. (for a game and a particle editor)
In this system there are a 0 to n modifiers.
Those modify the particles in the particle system every frame.
For example you could have a predefined modifier called “GravityModifier” that only does the following to every particle every frame: “particle.Velocity.Y += 9.81” or something like that.
Now I want the user to be able to write additional modifiers at runtime (in the editor).
I would like to be able to just use C# for this.
And since the particle systems are written to JSON files, the custom modifier scripts should be written as sourcecode (maybe base64 encoded) to the file.
—
My question is:
Assume the game wants to load such a particle system file. How do I compile the custom modifiers into executable code?
Another very important thing to consider when answering this question: Note that this will be a particle system for a game. The compiled code will be called more than 3000 times every frame. (mostly at 60fps)
So it’s very important that the compiled code doesn’t take much longer to execute than other game-functions.
It would be nice to have the modifier scripts compiled into delegates of the form:
delegate void ModifyParticle(ref Particle p);
Is this possible? If so, how?
Yes,
This is possible and quite simple using the CSScript library.