Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: qholmes on August 15, 2011, 10:52:06 AM

Title: Particle On Off
Post by: qholmes on August 15, 2011, 10:52:06 AM
Here is a little Action i made to turn on and off a particle system... I have since read and managed to get working the Auto Destroy function which would have worked for me at the time.. But i made this instead. And then removed my particle system anyway.

For the delay i used the Wait Action as a template so if that is a bad way to do that then maybe someone else has a better way. But it seemed to work fine.

This Action will work as a basic switch with no Delay Value set or  as a Delayed Toggle if you set a Delay value.. So you can either Toggle it on then off or the other way around

Q

Code: [Select]

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Turns a Particle Emitter on and off with optional delay.")]
public class particleEmitterOnOff : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
[Tooltip("Set to True to turn it on and False to turn it off.")]
public FsmBool emitOnOff;
[Tooltip("If 0 it just acts like a switch. Values cause it to Toggle value after delay time (sec).")]
public FsmFloat delay;
public FsmEvent finishEvent;
public bool realTime;

private float startTime;
private float timer;
private GameObject go;

public override void Reset()
{
gameObject = null;
emitOnOff = false;
delay = 0f;
finishEvent = null;
realTime = false;
go = null;
}

public override void OnEnter()
{
go = Fsm.GetOwnerDefaultTarget(gameObject);
go.particleEmitter.emit = emitOnOff.Value;

if (delay.Value <= 0)
{
Finish();
return;
}

startTime = Time.realtimeSinceStartup;
timer = 0f;
}

public override void OnUpdate()
{
// update time

if (realTime)
{
timer = Time.realtimeSinceStartup - startTime;
}
else
{
timer += Time.deltaTime;
}

if (timer > delay.Value){
go.particleEmitter.emit = !emitOnOff.Value;
Finish();
if(finishEvent != null) Fsm.Event(finishEvent);
}
}

}
}
Title: Re: Particle On Off
Post by: FractalCore on January 04, 2012, 10:39:35 PM
I still find this action very useful, thanks. However it doesn't seem to work with the new particle system in Unity 3.5. Not surprising since it's so different now. I don't supposed an updated version would be possible would it?
Title: Re: Particle On Off
Post by: qholmes on January 05, 2012, 11:19:12 PM
Well i am sure that would be possible. I have not bothered with 3.5 as i am in the middle of a big project so no time for messing with beta software. I am sure someone could update it for you or i can when i get into 3.5

Q
Title: Re: Particle On Off
Post by: FractalCore on January 08, 2012, 04:16:41 AM
That's cool, no rush. I just wanted to point it out so it's known. To be honest the new particle system hasn't grown on me yet. So I don't mind using the old one still.
Title: Re: Particle On Off
Post by: FractalCore on January 19, 2012, 05:02:28 AM
Was just poking around with Set Property and it works on the new Particle System. It allows you to set an Enable Emission Bool for turning it on and off. Awesome.
Title: Re: Particle On Off
Post by: Pikamus on April 20, 2012, 02:03:33 AM
FractalCore just wondering how you done this? can you explain.
i'm trying to do the same thing!
thank you for your help
Title: Re: Particle On Off
Post by: FractalCore on April 20, 2012, 02:43:03 AM
Happy to...

In this example I'm adding Playmaker Actions to the particle system itself. But that's not necessary. The way this is set up, pressing space will toggle the particles emitting on/off. That's what the Bool is for, unticked is off, ticked is on.

The first picture highlights the component label you have to drag and drop on to the Set Property part you see in the last image where it says Particle System. Then you get the options specific to it.

Hopefully the pictures can explain it. Let me know if you need more info.

There's a quirk where if you want to assign a component from one object to a Playmaker FSM assigned to another, you have to turn on Lock so you don't deselect it in the process. This is why for this example I put the FSM on the Particle System itself.
Title: Re: Particle On Off
Post by: Pikamus on April 29, 2012, 02:59:35 AM
Thanks Fractal Core,
Works like a charm
^_^
Title: Re: Particle On Off
Post by: justifun on April 30, 2012, 03:39:38 PM
Has anyone had an issue with dragging a component from an object prefab that's not on your current prefab?

eg: a character accessing a treasure chest's component?
Title: Re: Particle On Off
Post by: MrMitch on September 20, 2012, 06:37:01 PM
Thanks for this it still works without any issues :)
Title: Re: Particle On Off
Post by: ZeroSigma on November 30, 2012, 05:33:14 AM
Thanks for this script, I was looking for it.

Here is an updated version seeing as 'particleEmitter' has been depreciated.
Please feel free to modify as needed but remember to share. ;)

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Turns a Particle Emitter on and off with optional delay.")]
public class particleEmitterOnOff : FsmStateAction
{
[RequiredField]
[Tooltip("The particle system component owner.")]
public FsmOwnerDefault gameObject;
[Tooltip("Set to True to turn it on and False to turn it off.")]
public FsmBool emitOnOff;
[Tooltip("If 0 it just acts like a switch. Values cause it to Toggle value after delay time (sec).")]
public FsmFloat delay;
[Tooltip("The event is fired after the delay has been reached. NOTE: only works when delay > 0")]
public FsmEvent finishEvent;
public bool realTime;

private float startTime;
private float timer;
private ParticleSystem ps;
private GameObject go;

public override void Reset()
{
gameObject = null;
emitOnOff = false;
delay = 0f;
finishEvent = null;
realTime = false;
ps = null;
}

public override void OnEnter()
{
ps = Fsm.GetOwnerDefaultTarget(gameObject).GetComponent<ParticleSystem>();

if (emitOnOff.Value) ps.Play(); else ps.Stop();

if (delay.Value <= 0)
{
Finish();
return;
}

startTime = Time.realtimeSinceStartup;
timer = 0f;
}

public override void OnUpdate()
{
// update time

if (realTime)
{
timer = Time.realtimeSinceStartup - startTime;
}
else
{
timer += Time.deltaTime;
}

if (timer > delay.Value)
{
if (!emitOnOff.Value) ps.Play(); else ps.Stop();

Finish();
if(finishEvent != null) Fsm.Event(finishEvent);
}
}

}
}
Title: Re: Particle On Off
Post by: dudebxl on November 02, 2015, 09:47:38 AM
+1 add to ecosystem

 :P
Title: Re: Particle On Off
Post by: Headtrip on October 31, 2016, 01:32:23 AM
Thanks!!! this works perfectly