Join our Discord Channel
// 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; } // } } }}