![]() |
Magical Box
1.15
Modular Particle Engine for Unity3D
|
Creating your own emitter types involves the following steps:
In this example we want to create a simple point emitter that sets the initial heading to a random vector. First we create our class:
[MBEmitterTypeInfo(Menu = "3D/Point w Rnd Hdg")] public class MBPointRndEmitter : MBEmitterType { }
The MBEmitterTypeInfo attribute informs the editor about our new class and defines its name in the Change Type dropdown list. Let's add some functionality...
When spawning particles, an emitter asks its attached emitter type to return both position and heading of the new particle. As our point emitter needs no offset from the emitter's position, we don't need to overwrite MBEmitterType.GetPosition() to change it. The heading is defined by MBEmitterType.GetHeading() and by default handles the built-in heading types (Center,Fixed,Trail). We want to ignore all this and just return a random heading:
public override Vector3 GetHeading(MBParticle PT) { return Random.insideUnitSphere; }
That's it. But usually you create more complex emitter types with initialization and GUI support, so here's a brief overview of methods you want to override in your future custom emitter types:
| Method | Purpose |
|---|---|
| MBEmitterType.GetPosition() | Set particle position in particle system's space |
| MBEmitterType.GetHeading() | Set particle heading |
| MBEmitterType.OnPlay() | Initialization, called when emitter starts playing |
| MBEmitterType.Validate() | Validate properties set in the editor |
| MBEmitterType.DoGizmos() | Drawing gizmos |
While our custom emitter type will work now, we need to provide a GUI handler class to integrate it in the editor. First we create a handler class:
[MBEmitterTypeHandler(typeof(MBPointRndEmitter))] public class MBEditorPointRndEmitterHandler : MBEditorEmitterTypeHandler { public override void OnGUI() { // omit default GUI // base.OnGUI(); } }
The MBEmitterTypeHandler attribute informs the editor about our GUI handler. We override MBEditorEmitterTypeHandler.OnGUI() to place our custom GUI code. In this example we just omit the drawing of the default GUI because our point emitter ignores all these settings.
You're done, congratulation to your first custom emitter type!