void Update() { // Ensure particle system is ready before we use it if (!particles.IsReady()) { return; } // Emit _emitTimer += Time.deltaTime / emitTime; if (_emitTimer >= 1f) { // Emit onto the initial position of the spline Vector3 emitPos = spline.GetPoint(0); particles.Emit(emitPos, Vector3.zero, color); _emitTimer = 0; } // Ensure correct length of scatter positions (upon changing particle count) if (applyPositionScatter && particles.particleCount != _scatterPosition.Length) { GenerateScatter(); } // Position for (int i = 0; i < particles.particleCount; i++) { // If Playground Cache is resized while in here we need to exit the loop if (applyPositionScatter && particles.playgroundCache.simulate.Length != _scatterPosition.Length) { break; } // Check if the particle is simulating if (particles.playgroundCache.simulate[i]) { // Normalize the time for the particle float t = Mathf.Min(particles.playgroundCache.life[i] / (particles.lifetime - particles.playgroundCache.lifetimeSubtraction[i]), .99f); // Create a position on the spline along with the generated scattering Vector3 pos = spline.GetPoint(t); if (applyPositionScatter) { pos += applyScatterLifetimeMultiplier? _scatterPosition[i] * positionScatterLifetimeMultiplier.Evaluate(t) : _scatterPosition[i]; } // Set the position of the particle particles.ParticlePosition(i, pos); } } }
PlaygroundParticlesC particles; // Cached reference to the particle system IEnumerator Start() { // Cache a reference to the particle system particles = GetComponent <PlaygroundParticlesC>(); // Set a particle as sticky if a negative value isn't set if (stickyParticle > -1) { while (!particles.IsReady()) { yield return(null); } particles.SetSticky(stickyParticle, stickyTransform.position + stickyOffset, stickyTransform.up, particles.stickyCollisionsSurfaceOffset, stickyTransform); } }
IEnumerator Start() { PlaygroundParticlesC particles = GetComponent <PlaygroundParticlesC>(); while (!particles.IsReady()) { yield return(null); } Vector3 position = particles.particleSystemTransform.position; for (int i = 0; i < particles.particleCount; i++) { float iCircle = 360f * ((i * 1f) / (particles.particleCount * 1f)); Vector3 direction = new Vector3(Mathf.Cos(Mathf.Deg2Rad * iCircle) * width, Mathf.Sin(Mathf.Deg2Rad * iCircle) * height, 0); particles.Emit(position, direction * velocity, color); } }
IEnumerator FreezeRoutine() { if (conditionalParticleSystem == null || freezeParticleSystem == null) { yield break; } // Wait while the conditional particle system isn't ready to begin or while it's still alive while (!conditionalParticleSystem.IsReady() || conditionalParticleSystem.IsAlive()) { yield return(null); } // Wait extra time if specified if (extraWaitingTime > 0) { yield return(new WaitForSeconds(extraWaitingTime)); } // Freeze the particle system by setting time scale to 0 now when the conditional particle system isn't alive any longer freezeParticleSystem.particleTimescale = 0; }
void Update() { if (!_ready || !particles.IsReady() || particles.particleCount < 2) { return; } // Generate new interpolation positions if needed if (_spiralInterpolations.Length != particles.particleCount || _startPos != start.position || _endPos != end.position || !Mathf.Approximately(_i, swirlIterations) || !Mathf.Approximately(_r, radius)) { GenerateSpiralInterpolations(); } for (int i = 0; i < particles.particleCount; i++) { // If particles cache is resized in the middle of execution we need to exit the loop if (_spiralInterpolations.Length != particles.playgroundCache.simulate.Length) { break; } // Emit or position particles to the calculated spiral position if (!particles.playgroundCache.simulate[i]) { particles.Emit(_spiralInterpolations[i]); } else { particles.ParticlePosition(i, _spiralInterpolations[i]); } } }
void Update() { // Clamp values maxPoints = Mathf.Clamp(maxPoints, 2, 32767); // Set asynchronous available values if (billboardTransform != null) { _billboardTransformPosition = billboardTransform.position; } // Early out if no particles exist yet if (playgroundSystem == null || !playgroundSystem.IsReady() || playgroundSystem.IsSettingParticleCount() || playgroundSystem.IsSettingLifetime() || playgroundSystem.particleCache == null || playgroundSystem.particleCache.Length == 0) { return; } // Reset trails if a crucial state is changed if (_currentParticleCount != playgroundSystem.particleCount || _currentParticleMinLifetime != playgroundSystem.lifetimeMin || _currentParticleMaxLifetime != playgroundSystem.lifetime || _localSpace != (playgroundSystem.shurikenParticleSystem.simulationSpace == ParticleSystemSimulationSpace.Local)) { ResetTrails(); } // Set calculation matrix if this is local space if (_localSpace) { _localMatrix.SetTRS(playgroundSystem.particleSystemTransform.position, playgroundSystem.particleSystemTransform.rotation, playgroundSystem.particleSystemTransform.lossyScale); } // Check material if (material != _materialCache) { SetMaterial(material); } // Remove any trails that has ended if (_isDoneThread) { for (int i = 0; i < _trails.Count; i++) { if (_trails[i].trailPoints != null && _trails[i].trailPoints.Count > 1 && _trails[i].trailPoints[_trails[i].trailPoints.Count - 1] != null && _trails[i].CanRemoveTrail()) { RemoveTrail(i); i--; if (i < 0) { i = 0; } continue; } } } // Consume the particle birth queue while (_birthQueue.Count > 0) { AddTrail(_birthQueue.Dequeue()); } // Update all trail meshes and their render settings for (int i = 0; i < _trails.Count; i++) { ParticlePlaygroundTrail trail = _trails[i]; // Set shadow casting/receiving trail.trailRenderer.receiveShadows = receiveShadows; #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 trail.trailRenderer.castShadows = castShadows; #else trail.trailRenderer.shadowCastingMode = shadowCastingMode; #endif if (_isDoneThread) { trail.UpdateMesh(); } } // Finally calculate all trails if (multithreading) { if (_isDoneThread) { _calculationStartTime = Application.isPlaying? Time.time : Time.realtimeSinceStartup; _isDoneThread = false; PlaygroundC.RunAsync(() => { lock (_locker) { if (_isDoneThread) { return; } CalculateTrail(); _isDoneThread = true; } }); } } else { _calculationStartTime = Application.isPlaying? Time.time : Time.realtimeSinceStartup; CalculateTrail(); } }
void Update() { // Clamp values maxPoints = Mathf.Clamp(maxPoints, 2, 32767); // Set asynchronous available values if (billboardTransform != null) { _billboardTransformPosition = billboardTransform.position; } // Early out if no particles exist yet if (playgroundSystem == null || !playgroundSystem.IsReady() || playgroundSystem.IsSettingParticleCount() || playgroundSystem.IsSettingLifetime() || playgroundSystem.particleCache == null || playgroundSystem.particleCache.Length == 0) { return; } // Reset trails if a crucial state is changed if (_currentParticleCount != playgroundSystem.particleCount || _currentLoopValue != playgroundSystem.loop || _currentParticleMinLifetime != playgroundSystem.lifetimeMin || _currentParticleMaxLifetime != playgroundSystem.lifetime || _localSpace != (playgroundSystem.shurikenParticleSystem.simulationSpace == ParticleSystemSimulationSpace.Local)) { ResetTrails(); } // Set calculation matrix if this is local space if (_localSpace) { _localMatrix.SetTRS(playgroundSystem.particleSystemTransform.position, playgroundSystem.particleSystemTransform.rotation, playgroundSystem.particleSystemTransform.lossyScale); } // Check material if (material != _materialCache) { SetMaterial(material); } // Consume the particle birth queue while (_isDoneThread && _birthQueue.Count > 0) { // Reuse or create new trails bool canReuseTrail = trails.Count > 0 && _trailReuseQueue.Count > 0; int reuseQueuePeekValue = canReuseTrail? _trailReuseQueue.Peek() : 0; if (canReuseTrail && (reuseQueuePeekValue < 0 || reuseQueuePeekValue > trails.Count - 1 || !trails[reuseQueuePeekValue].IsQueuedForReuse())) { _trailReuseQueue.Dequeue(); canReuseTrail = false; } if (canReuseTrail) { ReuseTrail(_trailReuseQueue.Dequeue(), _birthQueue.Dequeue()); } else { CreateTrail(_birthQueue.Dequeue()); } } // Remove any trails that has ended if (_isDoneThread) { for (int i = 0; i < trails.Count; i++) { if (trails[i].trailPoints != null && trails[i].trailPoints.Count > 1 && trails[i].trailPoints[trails[i].trailPoints.Count - 1] != null && trails[i].CanRemoveTrail()) { if (!trails[i].IsQueuedForReuse()) { _trailReuseQueue.Enqueue(i); trails[i].QueueForReuse(); } } } } // Update all trail meshes and their render settings for (int i = 0; i < trails.Count; i++) { ParticlePlaygroundTrail trail = trails[i]; // Set shadow casting/receiving trail.trailRenderer.receiveShadows = receiveShadows; #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 trail.trailRenderer.castShadows = castShadows; #else trail.trailRenderer.shadowCastingMode = shadowCastingMode; #endif if (_isDoneThread && !trail.IsQueuedForReuse()) { trail.UpdateMesh(); } } // Check if there's any event listeners _hasTrailPointEventListener = trailPointEvent != null; // Check that the calculation delegate is assigned if (_trailsCalculationAction == null) { _trailsCalculationAction = CalculationDelegate; } _calculationStartTime = Application.isPlaying? Time.time : Time.realtimeSinceStartup; // Finally calculate all trails if (multithreading) { if (_isDoneThread) { _isDoneThread = false; PlaygroundC.RunAsync(_trailsCalculationAction); } } else { _isDoneThread = false; _trailsCalculationAction(); } }