Pixelpart 1.10.0
Unity Plugin
Loading...
Searching...
No Matches
Scripting

A Pixelpart effect that is rendered using a PixelpartEffect component in your scene can be controlled and modified at runtime with scripts. This can be used to dynamically change the effect and let it react to other objects in the scene.

The PixelpartEffect component provides methods and properties to start, pause and restart the effect simulation. You can also access the properties visible in the inspector.

  • RestartEffect - Restart the effect from the beginning.
  • Playing - Whether is the effect is playing or paused.
  • Loop - If enabled, the effect is repeated after the time specified in LoopTime.
  • LoopTime - Time in seconds after which the effect is repeated. Only has an effect if Loop is enabled.
  • WarmupTime - Time in seconds the effect is pre-simulated before being rendered. This value impacts performance and should be kept as low as possible.
  • Speed - Multiplier for the playback speed of the effect. For example, setting Speed to 0.5 shows the effect in slow motion.
  • FrameRate - How many iterations are simulated per second. Can be used to improve performance for complex effects.
  • Seed - Seed used to initialize the effect simulation. This seed is used if RandomSeed is not enabled.
  • RandomSeed - Whether to use a random seed to initialize the effect simulation.
  • EffectScale - Multiplier for the size of the effect. Adjust this value if the effect appears too small or too large in the scene.
  • FlipH - Whether the effect is flipped horizontally.
  • FlipV - Whether the effect is flipped vertically.

The following example illustrates how to start playing an effect in slow motion:

// Get effect component of game object
var effect = GetComponent<PixelpartEffect>();
// Start playing in slow motion
effect.Playing = true;
effect.Speed = 0.5;

You might also want to get notified when an effect is finished and no particles are visible anymore. You can do so by subscribing to the Finished event. Of course this only works for effects without repeating emitters.

void Awake()
{
// Get effect component of game object
var effect = GetComponent<PixelpartEffect>();
// Get notified when effect is finished
effect.Finished += OnFinished;
}
private void OnFinished(object sender, EventArgs e)
{
// Effect is now finished
}

Inputs

Effect inputs are the primary technique to dynamically modify effect properties. The following example shows how the value of an effect input, which has been defined in the Pixelpart editor, can be changed from a script:

// Get effect component of game object
var effect = GetComponent<PixelpartEffect>();
// Set effect input "Size" to 2.0
effect.SetInputFloat("Size", 2.0f);

Depending on the data type, several set methods are available to change the value of effect inputs:

To retrieve the currently set input value, use the corresponding get methods:

Triggers

Triggers are used to make effects react to events in your game. The following example shows how a trigger can be activated from a script using the ActivateTrigger method:

// Get effect component of game object
var effect = GetComponent<PixelpartEffect>();
// Activate the trigger "MyTrigger"
effect.ActivateTrigger("MyTrigger");

Use IsTriggerActivated to check if a trigger has already been activated.

Events

In contrast to triggers, events are used to make the game react to something happening in the effect, for example to play an audio clip when an emitter starts producing particles. You can subscribe to EffectEvent to get notified when effect events occur:

void Awake()
{
// Get effect component of game object
var effect = GetComponent<PixelpartEffect>();
// Get notified about effect events
effect.EffectEvent += OnEffectEvent;
}
private void OnEffectEvent(object sender, PixelpartEffectEventArgs e)
{
if (e.EventName == "MyEvent")
{
// Do something, e.g. play an audio clip
}
}