public static void SetParticleCount(PlaygroundParticlesC playgroundParticles, int amount) { if (playgroundParticles.isSettingParticleCount) return; if (playgroundParticles.isPrewarming) return; if (amount<0) amount = 0; if (playgroundParticles.internalRandom01==null) playgroundParticles.RefreshSystemRandom(); playgroundParticles.particleCount = amount; playgroundParticles.previousParticleCount = amount; // Create Particles playgroundParticles.particleCache = new ParticleSystem.Particle[amount]; playgroundParticles.shurikenParticleSystem.Emit(amount); playgroundParticles.shurikenParticleSystem.GetParticles(playgroundParticles.particleCache); playgroundParticles.inTransition = false; playgroundParticles.hasActiveParticles = true; playgroundParticles.threadHadNoActiveParticles = false; playgroundParticles.isSettingParticleCount = true; PlaygroundC.RunAsync(()=>{ if (!playgroundParticles.isSettingParticleCount) return; if (playgroundParticles.playgroundCache==null) playgroundParticles.playgroundCache = new PlaygroundCache(); // Rebuild Cache playgroundParticles.playgroundCache.size = new float[amount]; playgroundParticles.playgroundCache.birth = new float[amount]; playgroundParticles.playgroundCache.death = new float[amount]; playgroundParticles.playgroundCache.rebirth = new bool[amount]; playgroundParticles.playgroundCache.birthDelay = new float[amount]; playgroundParticles.playgroundCache.life = new float[amount]; playgroundParticles.playgroundCache.lifetimeSubtraction = new float[amount]; playgroundParticles.playgroundCache.rotation = new float[amount]; playgroundParticles.playgroundCache.lifetimeOffset = new float[amount]; playgroundParticles.playgroundCache.emission = new bool[amount]; playgroundParticles.playgroundCache.changedByProperty = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertyColor = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertyColorLerp = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertyColorKeepAlpha = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertySize = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertyTarget = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertyDeath = new bool[amount]; playgroundParticles.playgroundCache.propertyTarget = new int[amount]; playgroundParticles.playgroundCache.propertyId = new int[amount]; playgroundParticles.playgroundCache.excludeFromManipulatorId = new int[amount]; playgroundParticles.playgroundCache.propertyColorId = new int[amount]; playgroundParticles.playgroundCache.manipulatorId = new int[amount]; playgroundParticles.playgroundCache.color = new Color32[amount]; playgroundParticles.playgroundCache.scriptedColor = new Color32[amount]; playgroundParticles.playgroundCache.initialColor = new Color32[amount]; playgroundParticles.playgroundCache.lifetimeColorId = new int[amount]; playgroundParticles.playgroundCache.noForce = new bool[amount]; playgroundParticles.playgroundCache.position = new Vector3[amount]; playgroundParticles.playgroundCache.targetPosition = new Vector3[amount]; playgroundParticles.playgroundCache.targetDirection = new Vector3[amount]; playgroundParticles.playgroundCache.previousTargetPosition = new Vector3[amount]; playgroundParticles.playgroundCache.previousParticlePosition = new Vector3[amount]; playgroundParticles.playgroundCache.collisionParticlePosition = new Vector3[amount]; playgroundParticles.playgroundCache.localSpaceMovementCompensation = new Vector3[amount]; playgroundParticles.playgroundCache.scatterPosition = new Vector3[amount]; playgroundParticles.playgroundCache.velocity = new Vector3[amount]; playgroundParticles.playgroundCache.isMasked = new bool[amount]; playgroundParticles.playgroundCache.maskAlpha = new float[amount]; playgroundParticles.playgroundCache.isNonBirthed = new bool[amount]; playgroundParticles.playgroundCache.isFirstLoop = new bool[amount]; playgroundParticles.playgroundCache.simulate = new bool[amount]; playgroundParticles.playgroundCache.isCalculatedThisFrame = new bool[amount]; playgroundParticles.playgroundCache.maskSorting = null; for (int i = 0; i<amount; i++) { playgroundParticles.particleCache[i].size = 0f; playgroundParticles.playgroundCache.rebirth[i] = true; playgroundParticles.playgroundCache.simulate[i] = true; playgroundParticles.playgroundCache.isNonBirthed[i] = true; playgroundParticles.playgroundCache.isFirstLoop[i] = true; // Set color gradient id if (playgroundParticles.colorSource==COLORSOURCEC.LifetimeColors && playgroundParticles.lifetimeColors.Count>0) { playgroundParticles.lifetimeColorId++;playgroundParticles.lifetimeColorId=playgroundParticles.lifetimeColorId%playgroundParticles.lifetimeColors.Count; playgroundParticles.playgroundCache.lifetimeColorId[i] = playgroundParticles.lifetimeColorId; } } // Set sizes SetSizeRandom(playgroundParticles, playgroundParticles.sizeMin, playgroundParticles.sizeMax); playgroundParticles.previousSizeMin = playgroundParticles.sizeMin; playgroundParticles.previousSizeMax = playgroundParticles.sizeMax; // Set rotations playgroundParticles.playgroundCache.initialRotation = RandomFloat(amount, playgroundParticles.initialRotationMin, playgroundParticles.initialRotationMax, playgroundParticles.internalRandom01); playgroundParticles.playgroundCache.rotationSpeed = RandomFloat(amount, playgroundParticles.rotationSpeedMin, playgroundParticles.rotationSpeedMax, playgroundParticles.internalRandom01); playgroundParticles.previousInitialRotationMin = playgroundParticles.initialRotationMin; playgroundParticles.previousInitialRotationMax = playgroundParticles.initialRotationMax; playgroundParticles.previousRotationSpeedMin = playgroundParticles.rotationSpeedMin; playgroundParticles.previousRotationSpeedMax = playgroundParticles.rotationSpeedMax; // Set velocities SetVelocityRandom(playgroundParticles, playgroundParticles.initialVelocityMin, playgroundParticles.initialVelocityMax); SetLocalVelocityRandom(playgroundParticles, playgroundParticles.initialLocalVelocityMin, playgroundParticles.initialLocalVelocityMax); // Set Emission Emission(playgroundParticles, playgroundParticles.emit, false); // Make sure scatter is available first lifetime cycle if (playgroundParticles.applySourceScatter) playgroundParticles.RefreshScatter(); playgroundParticles.isDoneThread = true; playgroundParticles.isSettingParticleCount = false; }); }
/// <summary> /// Refreshes source scatter for this Particle System. /// </summary> /// <param name="playgroundParticles">Playground particles.</param> public static void RefreshScatter (PlaygroundParticlesC playgroundParticles) { playgroundParticles.RefreshScatter(); }
// Sets the amount of particles and initiates the necessary arrays public static void SetParticleCount (PlaygroundParticlesC playgroundParticles, int amount) { if (amount<0) amount = 0; playgroundParticles.particleCount = amount; // Create Particles playgroundParticles.particleCache = new ParticleSystem.Particle[amount]; playgroundParticles.shurikenParticleSystem.Emit(amount); playgroundParticles.shurikenParticleSystem.GetParticles(playgroundParticles.particleCache); PlaygroundC.RunAsync(()=>{ if (playgroundParticles.playgroundCache==null) playgroundParticles.playgroundCache = new PlaygroundCache(); for (int i = 0; i<amount; i++) { playgroundParticles.particleCache[i].position = PlaygroundC.initialTargetPosition; playgroundParticles.particleCache[i].size = 0f; } playgroundParticles.inTransition = false; // Rebuild Cache playgroundParticles.playgroundCache.size = new float[amount]; playgroundParticles.playgroundCache.birth = new float[amount]; playgroundParticles.playgroundCache.death = new float[amount]; playgroundParticles.playgroundCache.rebirth = new bool[amount]; playgroundParticles.playgroundCache.birthDelay = new float[amount]; playgroundParticles.playgroundCache.life = new float[amount]; playgroundParticles.playgroundCache.rotation = new float[amount]; playgroundParticles.playgroundCache.lifetimeOffset = new float[amount]; playgroundParticles.playgroundCache.emission = new bool[amount]; playgroundParticles.playgroundCache.changedByProperty = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertyColor = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertyColorLerp = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertyColorKeepAlpha = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertySize = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertyTarget = new bool[amount]; playgroundParticles.playgroundCache.changedByPropertyDeath = new bool[amount]; playgroundParticles.playgroundCache.propertyTarget = new int[amount]; playgroundParticles.playgroundCache.propertyId = new int[amount]; playgroundParticles.playgroundCache.propertyColorId = new int[amount]; playgroundParticles.playgroundCache.color = new Color32[amount]; playgroundParticles.playgroundCache.scriptedColor = new Color32[amount]; playgroundParticles.playgroundCache.initialColor = new Color32[amount]; playgroundParticles.playgroundCache.lifetimeColorId = new int[amount]; playgroundParticles.playgroundCache.position = new Vector3[amount]; playgroundParticles.playgroundCache.targetPosition = new Vector3[amount]; playgroundParticles.playgroundCache.targetDirection = new Vector3[amount]; playgroundParticles.playgroundCache.previousTargetPosition = new Vector3[amount]; playgroundParticles.playgroundCache.previousParticlePosition = new Vector3[amount]; playgroundParticles.playgroundCache.collisionParticlePosition = new Vector3[amount]; playgroundParticles.playgroundCache.localSpaceMovementCompensation = new Vector3[amount]; playgroundParticles.playgroundCache.scatterPosition = new Vector3[amount]; playgroundParticles.playgroundCache.velocity = new Vector3[amount]; playgroundParticles.playgroundCache.isMasked = new bool[amount]; playgroundParticles.playgroundCache.maskAlpha = new float[amount]; playgroundParticles.previousParticleCount = playgroundParticles.particleCount; // Set sizes SetSizeRandom(playgroundParticles, playgroundParticles.sizeMin, playgroundParticles.sizeMax); playgroundParticles.previousSizeMin = playgroundParticles.sizeMin; playgroundParticles.previousSizeMax = playgroundParticles.sizeMax; // Set rotations playgroundParticles.playgroundCache.initialRotation = RandomFloat(amount, playgroundParticles.initialRotationMin, playgroundParticles.initialRotationMax); playgroundParticles.playgroundCache.rotationSpeed = RandomFloat(amount, playgroundParticles.rotationSpeedMin, playgroundParticles.rotationSpeedMax); playgroundParticles.previousInitialRotationMin = playgroundParticles.initialRotationMin; playgroundParticles.previousInitialRotationMax = playgroundParticles.initialRotationMax; playgroundParticles.previousRotationSpeedMin = playgroundParticles.rotationSpeedMin; playgroundParticles.previousRotationSpeedMax = playgroundParticles.rotationSpeedMax; // Set velocities SetVelocityRandom(playgroundParticles, playgroundParticles.initialVelocityMin, playgroundParticles.initialVelocityMax); SetLocalVelocityRandom(playgroundParticles, playgroundParticles.initialLocalVelocityMin, playgroundParticles.initialLocalVelocityMax); // Set Emission Emission(playgroundParticles, playgroundParticles.emit, false); // Make sure scatter is available first lifetime cycle if (playgroundParticles.applySourceScatter) playgroundParticles.RefreshScatter(); playgroundParticles.isDoneThread = true; }); }