Skip to main content

PooledParticleSystemManipulator

A class in Root.Township, Features.Visual_Effects.General_Scripts.

Pooled particle effect that, after a delay, pulls its live particles towards targets (a player's hands, body or custom transforms), plays an arrival effect, then returns itself to the pool. Client side.

Constructors​

MemberWhat it is
PooledParticleSystemManipulator()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

10 private and internal fields
MemberWhat it is
private float cachedParticleAccelerationAcceleration added to the move speed each frame.
private float cachedParticleSpeedBase move distance per frame.
private float cachedTimeToStartMovingSeconds to wait before the particles start moving.
private bool hasPlayedDestinationEffectWhether the arrival effect has played this use.
private static Logger loggerNLog logger for this class.
private ParticleSystem.Particle[] movingParticlesBuffer for reading and writing particles.
private HashSet<ParticleSystem> particleSystemsAtDestinationSystems that have had at least one particle arrive.
private ParticleSystem[] particleSystemsToMoveParticle systems whose particles are pulled to the targets.
private const float SqrDistanceToBeConsideredAtDestinationSquared distance (0.02) at which a particle counts as arrived and is killed.
private ParticleSystem[] waitForParticleSystemBeforeReleaseOptional systems that must finish before the object goes back to the pool.

Properties​

1 private and internal property
MemberWhat it is
private bool IsStillWaitingForParticlesToComplete { get; }True while any of the wait-for systems still has particles.

Methods​

MemberWhat it is
void MoveToCustom(PooledObjectDefinition onTransformEffect, float particleSpeed, float particleAcceleration, float timeToStartMoving, Transform[] targets)Starts moving the particles to the given transforms.
void MoveToPlayer(IPlayer player, PooledObjectDefinition onTransformEffect, ParticleDestination destination, float particleSpeed, float particleAcceleration, float timeToStartMoving)Starts moving the particles to the player's hands or body. Logs an error if the player or controller is null.
void PostBake()Build step that removes missing particle systems from both lists.
10 private and internal methods
MemberWhat it is
private void AddTargetsForCustomDestination(Transform[] customTargets, ref List<Transform> targets)Adds the custom targets, logging an error if there are none.
private void AddTargetsForPlayerBody(PlayerController playerController, ref List<Transform> targets)Adds the player's body transform, using the local player if none is given.
private void AddTargetsForPlayerHands(PlayerController playerController, ref List<Transform> targets)Adds both of the player's grip points, using the local player if none is given.
private void CacheParticleMovementSettings(float particleSpeed, float particleAcceleration, float timeToStartMoving)Stores the speed, acceleration and start delay for the movement routine.
private List<Transform> GetParticleTargets(ParticleDestination destination, PlayerController playerController, Transform[] customTargets)Builds the target transform list for the destination type.
private void OnDisable()Resets the arrival effect flag for the next use.
private IEnumerator ParticleMovementRoutine(ParticleDestination destination, PooledObjectDefinition onTransformEffect, PlayerController playerController = null, Transform[] customTargets = null) (iterator)Waits, then moves particles to the targets each frame until none are left, then waits for the wait-for systems and releases to the pool.
private void SetupMovingParticles()Allocates the particle buffer sized to the largest system's max particles.
private void TryPlayDestinationEffect(PooledObjectDefinition onTransformEffect, List<Transform> targets)Once every system has had a particle arrive, spawns the arrival effect on each target, once per use.
private void UpdateParticlesForSystem(ParticleSystem particleSystemToMove, List<Vector3> targets, float maxDistanceDelta, int particleCount)Moves each particle towards its target (spread round-robin over targets), killing those that arrive.