FlatFX is a pack of simple geometry-based 2D effects for your Unity game or project. Here's an introduction trailer:
- Five different effects each with its own customizable colors, size, duration and few more settings.
- Setting can be modified in editor or from code, stored and loaded from external file.
- The geometry (mesh) is generated by a C# script, no sprites are used. This way FlatFX don't take additional video memory and allows to scale effects to any size and set any duration.
- Supports sorting layers in the same way sprites do.
How to use
To start using FlatFXjust click Game Object > Effects > FlatFX in Unity's main menu. Or do the same by right-clicking the Hierarchy panel. This will add a new FlatFX object at 0,0,0 of your scene. You can place it wherever you want on X and Y axes - when you spawn new effect, you'll set the coordinates for them in Vector2 form. Z-position of the effects will be taken from object's position. Here's an example code to add an effect to your scene:
//Find the object in your scene by its name //and get a reference to the FlatFX component. //It's better to do this once in Start() or Awake() FlatFX flatfx=GameObject.Find("FlatFX").GetComponent
(); //Adding the explosion effect at x=0, y=0. //Effects are numbered from 0 to 4 flatfx.AddEffect(Vector2.zero,0);
Effects can be customized from inspector or from code. Each effect has its own settings. Most of them are self explanatory but some of them may need a little clarification.
Sector count is a number of sides the circular shape will have.
Lifetime sets a number of seconds the effect will exist.
Easing function is how the transition from start to end state will be eased. Usully any kind of "ease out" looks better then just linear transition from one state to another.
Randomize position sets a distance from your target position by which to randomize the spawning of new effect. If set to 0, effect will spawn precisely where you set it to spawn.
Start and End states define how the next spawned effect will be animated.
Size is a full width or height of the effect.
Thickness is a bit tricky. It's a total width of a crossection of the effect. So in case of a donut it's a sum of widths of both of its walls. And in case of the explosion (cutout circle) it will decide the maximum width of it's wall. You don't need to think about this when configuring the effects, but it can be useful to know this.
Inner color and outer color set the color of vertices for the effect. If you don't want to create a gradient, you can always set inner and outer colors to be the same.
All settings can be changed at runtime. So if you need want to control size, color or anything else from code, it can be done easily. Here's the example:
//Set lifetime, start size and end size of a "Ripple" effect flatfx.settings.lifetime=1f; flatfx.settings.start.size=0f; flatfx.settings.end.size=4f;
There are also "Import..." and "Export..." buttons on top of FlatFX's inspector. They allow to save/load all settings for all effects as one JSON file. So it's possible to save different kinds of presets. This would be useful if you're experimenting with different settings.
That's pretty much it. I plan to keep optimizing this asset and add new effects if I come up with them, make it more flexible and easier to customize. If you have any suggestions or questions, feel free to message me on Unity's Forums, on Twitter or by email.