Skip to main content

GenericVFXController

A class in Root.Township, Features.

Networked trigger for a list of pooled particle effects. The server says which effect to play or stop (by index, or -1 for all) and clients spawn them at spawnPoint.

Constructors​

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

Fields​

10 private and internal fields
MemberWhat it is
private readonly List<PooledParticleSystem> activePooledSystemsClient: effects currently playing.
private const int AllIndex-1, meaning every effect in the list.
private bool btnPlayInspector button that calls PlayAll.
private bool btnStopInspector button that calls StopAll.
private static readonly Logger loggerNLog logger for this class.
private PooledObjectDefinition[] poolDefinitionsPooled particle effects, addressed by index.
private Transform spawnPointWhere effects spawn, and their rotation.
private MethodSyncStruct<int> syncParticleActivationMethod sync for play messages.
private MethodSyncStruct<int> syncParticleStopMethod sync for stop messages.
private const int ToMilliseconds1000, used to turn effect durations into a delay.

Methods​

MemberWhat it is
override void Initialize()Creates the play and stop syncs on VfxControllerPlay and VfxControllerStop.
void PlayAll()Server: plays every effect on clients.
void PlayVfxAtIndex(int index)Server: tells clients in the chunk to play the effect at the index (or all for -1).
void StopAll()Server: stops every effect on clients.
void StopVfxFromIndex(int index)Server: tells clients to stop the effect at the index (or all for -1).
12 private and internal methods
MemberWhat it is
private bool CanPlayPooledParticleEffect(PooledObjectDefinition pooledObjectDefinition)True on clients or local test when the definition exists; never on a dedicated server.
private bool IsValidIndex(int index)True for -1 or an index inside poolDefinitions.
private bool IsValidLocalTest(Stream stream)True when reading in a local test, so the effect also plays there.
private void PlayAllPooledParticleEffects()Client: plays each effect in the list.
private async void PlayPooledParticleEffect(PooledObjectDefinition pooledObjectDefinition)Client: spawns the pooled effect at the spawn point and, if it auto-disables, stops it after its duration.
private void PlayVfxOnClient(int index)Client: plays the effect at the index, or all of them.
private void StopAllTargetSystems(PooledParticleSystem[] pooledParticleSystems)Client: stops all the given systems.
private void StopAllTargetSystemsWithIndex(PooledParticleSystem[] pooledParticleSystems, int index)Client: stops the given systems that came from the pool at the index.
private void StopTargetSystem(PooledParticleSystem targetPooledParticleSystem)Deactivates and releases a system back to its pool, and forgets it.
private void StopVfxOnClient(int index)Client: stops active effects for the index, or all of them.
private void SyncParticleActivationToClient(IPlayer player, Stream stream, int index)Sends the index and plays it on remote clients.
private void SyncParticleStopToClient(IPlayer player, Stream stream, int index)Sends the index and stops it on remote clients.