playMaker

Author Topic: ArrayListSetParticles  (Read 1713 times)

cwmanley

  • Full Member
  • ***
  • Posts: 107
ArrayListSetParticles
« on: January 22, 2016, 06:01:32 AM »
Sets the positions of particles in a particle system using an array.

On the Ecosystem or https://snipt.net/cwmanley/

Code: [Select]
// License: Attribution 4.0 International (CC BY 4.0)
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
// Keywords: Particle System Array List

using UnityEngine;
using System.Collections;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("ArrayMaker/ArrayList")]
[Tooltip("Sets the Position, Rotation, Size, Velocity, Color, or Lifetime of Particles in a Particle System using an Array.")]
public class ArrayListSetParticles : ArrayListActions
{

[ActionSection("Set up")]

[RequiredField]
[Tooltip("The GameObject with the PlayMaker ArrayList Proxy component.")]
[CheckForComponent(typeof(PlayMakerArrayListProxy))]
public FsmOwnerDefault gameObject;

[Tooltip("Author defined Reference of the PlayMaker ArrayList Proxy component ( necessary if several component coexists on the same GameObject.")]
public FsmString reference;

public bool everyFrame;

[ActionSection("Source")]

[RequiredField]
[Tooltip("The GameObject with the Particle System.")]
[CheckForComponent(typeof(ParticleSystem))]
public FsmGameObject particleSystem;

[Tooltip("The Particle System's Parameters.")]
public Parameters parameters;

public enum Parameters

{
Position,
Rotation,
Size,
Velocity,
Color,
Lifetime
}


private ParticleSystem _ps;
private Vector3 newVector3;
private float newFloat;
private Color newColor;
private int arrayListCount;


public override void Reset()
{
parameters = Parameters.Position;
everyFrame = false;
}

public override void OnEnter()
{
_ps = particleSystem.Value.GetComponent<ParticleSystem>();

if ( SetUpArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value) )
ArrayList();

if (!everyFrame)
Finish();

}

public override void OnUpdate()
{
if ( SetUpArrayListProxyPointer(Fsm.GetOwnerDefaultTarget(gameObject),reference.Value) )
ArrayList();
}

public void ArrayList()
{
if (!isProxyValid ())
return;
{
switch (parameters)
{
case Parameters.Position:
{
arrayListCount = proxy.arrayList.Count;

ParticleSystem.Particle []particlesArray = new    ParticleSystem.Particle[_ps.particleCount];

_ps.GetParticles(particlesArray);

for(int i = 0; i < _ps.particleCount; ++i)
{
if (i < arrayListCount)
newVector3 = (Vector3) proxy.arrayList[i];
particlesArray[i].position = newVector3;
}     
_ps.SetParticles(particlesArray, _ps.particleCount);
}
break;

case Parameters.Rotation:
{
arrayListCount = proxy.arrayList.Count;

ParticleSystem.Particle []particlesArray = new    ParticleSystem.Particle[_ps.particleCount];

_ps.GetParticles(particlesArray);

for(int i = 0; i < _ps.particleCount; ++i)
{
if (i < arrayListCount)
newFloat = (float) proxy.arrayList[i];
particlesArray[i].rotation = newFloat;
}     
_ps.SetParticles(particlesArray, _ps.particleCount);
}
break;

case Parameters.Size:
{
arrayListCount = proxy.arrayList.Count;

ParticleSystem.Particle []particlesArray = new    ParticleSystem.Particle[_ps.particleCount];

_ps.GetParticles(particlesArray);

for(int i = 0; i < _ps.particleCount; ++i)
{
if (i < arrayListCount)
newFloat = (float) proxy.arrayList[i];
particlesArray[i].startSize = newFloat;
}     
_ps.SetParticles(particlesArray, _ps.particleCount);
}
break;

case Parameters.Velocity:
{
arrayListCount = proxy.arrayList.Count;

ParticleSystem.Particle []particlesArray = new    ParticleSystem.Particle[_ps.particleCount];

_ps.GetParticles(particlesArray);

for(int i = 0; i < _ps.particleCount; ++i)
{
if (i < arrayListCount)
newVector3 = (Vector3) proxy.arrayList[i];
particlesArray[i].velocity = newVector3;
}     
_ps.SetParticles(particlesArray, _ps.particleCount);
}
break;

case Parameters.Color:
{
arrayListCount = proxy.arrayList.Count;

ParticleSystem.Particle []particlesArray = new    ParticleSystem.Particle[_ps.particleCount];

_ps.GetParticles(particlesArray);

for(int i = 0; i < _ps.particleCount; ++i)
{
if (i < arrayListCount)
newColor = (Color) proxy.arrayList[i];
particlesArray[i].startColor = newColor;
}     
_ps.SetParticles(particlesArray, _ps.particleCount);
}
break;

case Parameters.Lifetime:
{
arrayListCount = proxy.arrayList.Count;

ParticleSystem.Particle []particlesArray = new    ParticleSystem.Particle[_ps.particleCount];

_ps.GetParticles(particlesArray);

for(int i = 0; i < _ps.particleCount; ++i)
{
if (i < arrayListCount)
newFloat = (float) proxy.arrayList[i];
particlesArray[i].lifetime = newFloat;
}     
_ps.SetParticles(particlesArray, _ps.particleCount);
}
break;
}
//
}
}

}
}
« Last Edit: February 15, 2017, 02:24:38 PM by cwmanley »

cwmanley

  • Full Member
  • ***
  • Posts: 107
Re: ArrayListSetParticles
« Reply #1 on: January 24, 2016, 06:57:55 PM »
//Updated

Name changed

Sets the Position, Rotation, Size, Velocity, Color, or Lifetime of Particles in a Particle System using an Array.

Particles that are not one the list use the property in the last item of the array.