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;
            });
        }
        public static void SetLifetime(PlaygroundParticlesC playgroundParticles, SORTINGC sorting, float time)
        {
            if (!playgroundParticles.enabled) return;
            if (playgroundParticles.isSettingLifetime || playgroundParticles.isSettingParticleCount) return;

            if (playgroundParticles.internalRandom01==null)
                playgroundParticles.RefreshSystemRandom();

            SetLifetimeThreadSafe (playgroundParticles, sorting, time);
        }
		public static void SetLifetime (PlaygroundParticlesC playgroundParticles, SORTINGC sorting, float time) {
			if (!playgroundParticles.enabled) return;
			if (playgroundParticles.isSettingLifetime || playgroundParticles.isSettingParticleCount) return;
			
			if (playgroundParticles.internalRandom01==null)
				playgroundParticles.RefreshSystemRandom();

			playgroundParticles.isSettingLifetime = true;
			if (playgroundParticles.multithreadedStartup)
			{
				PlaygroundC.RunAsync(()=>{
					SetLifetimeAsyncFriendly (playgroundParticles, sorting, time);
				});
			}
			else
			{
				SetLifetimeAsyncFriendly (playgroundParticles, sorting, time);
			}
		}
		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);
			
			// Clear collision cache
			playgroundParticles.collisionCache = null; 
			
			playgroundParticles.inTransition = false;
			playgroundParticles.hasActiveParticles = true;
			playgroundParticles.threadHadNoActiveParticles = false;
			
			playgroundParticles.isSettingParticleCount = true;
			if (playgroundParticles.multithreadedStartup)
			{
				PlaygroundC.RunAsync(()=>{
					SetParticleCountAsyncFriendly(playgroundParticles, amount);
				}, ThreadPoolMethod.ThreadPool);
			}
			else SetParticleCountAsyncFriendly(playgroundParticles, amount);

		}
        public static void SetLifetime(PlaygroundParticlesC playgroundParticles, SORTINGC sorting, float time)
        {
            if (!playgroundParticles.enabled) return;
            if (playgroundParticles.isSettingLifetime || playgroundParticles.isSettingParticleCount) return;

            if (playgroundParticles.internalRandom01==null)
                playgroundParticles.RefreshSystemRandom();

            playgroundParticles.isSettingLifetime = true;
            PlaygroundC.RunAsync(()=>{
                playgroundParticles.lifetime = time;
                SetLifetimeSubtraction(playgroundParticles);
                playgroundParticles.playgroundCache.lifetimeOffset = new float[playgroundParticles.particleCount];
                int pCount = playgroundParticles.playgroundCache.lifetimeOffset.Length;
                if (playgroundParticles.source!=SOURCEC.Script) {
                    switch (sorting) {
                    case SORTINGC.Scrambled:
                        for (int r = 0; r<playgroundParticles.particleCount; r++) {
                            if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                            playgroundParticles.playgroundCache.lifetimeOffset[r] = RandomRange(playgroundParticles.internalRandom01, 0f, playgroundParticles.lifetime);
                        }
                    break;
                    case SORTINGC.ScrambledLinear:
                        float slPerc;
                        for (int sl = 0; sl<playgroundParticles.particleCount; sl++) {
                            if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                            slPerc = (sl*1f)/(playgroundParticles.particleCount*1f);
                            playgroundParticles.playgroundCache.lifetimeOffset[sl] = playgroundParticles.lifetime*slPerc;
                        }
                        for (int i = playgroundParticles.playgroundCache.lifetimeOffset.Length-1; i>0; i--) {
                            if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                            int r = playgroundParticles.internalRandom01.Next(0,i);
                            float tmp = playgroundParticles.playgroundCache.lifetimeOffset[i];
                            playgroundParticles.playgroundCache.lifetimeOffset[i] = playgroundParticles.playgroundCache.lifetimeOffset[r];
                            playgroundParticles.playgroundCache.lifetimeOffset[r] = tmp;
                        }
                    break;
                    case SORTINGC.Burst:
                        // No action needed for spawning all particles at once
                    break;
                    case SORTINGC.Reversed:
                        float lPerc;
                        for (int l = 0; l<playgroundParticles.particleCount; l++) {
                            if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                            lPerc = (l*1f)/(playgroundParticles.particleCount*1f);
                            playgroundParticles.playgroundCache.lifetimeOffset[l] = playgroundParticles.lifetime*lPerc;
                        }
                    break;
                    case SORTINGC.Linear:
                        float rPerc;
                        int rInc = 0;
                        for (int r = playgroundParticles.particleCount-1; r>=0; r--) {
                            if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                            rPerc = (rInc*1f)/(playgroundParticles.particleCount*1f);
                            rInc++;
                            playgroundParticles.playgroundCache.lifetimeOffset[r] = playgroundParticles.lifetime*rPerc;
                        }
                    break;
                    case SORTINGC.NearestNeighbor:
                        playgroundParticles.nearestNeighborOrigin = Mathf.Clamp(playgroundParticles.nearestNeighborOrigin, 0, playgroundParticles.particleCount-1);
                        float[] nnDist = new float[playgroundParticles.particleCount];
                        float nnHighest = 0;
                        int nn = 0;
                        for (; nn<playgroundParticles.particleCount; nn++) {
                            if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                            nnDist[nn%playgroundParticles.particleCount] = Vector3.Distance(playgroundParticles.playgroundCache.targetPosition[playgroundParticles.nearestNeighborOrigin%playgroundParticles.particleCount], playgroundParticles.playgroundCache.targetPosition[nn%playgroundParticles.particleCount]);
                            if (nnDist[nn%playgroundParticles.particleCount]>nnHighest)
                                nnHighest = nnDist[nn%playgroundParticles.particleCount];
                        }
                        if (nnHighest>0) {
                            for (nn = 0; nn<playgroundParticles.particleCount; nn++) {
                                if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                                playgroundParticles.playgroundCache.lifetimeOffset[nn%playgroundParticles.particleCount] = Mathf.Lerp(playgroundParticles.lifetime, 0, (nnDist[nn%playgroundParticles.particleCount]/nnHighest));
                            }
                        } else {
                            for (nn = 0; nn<playgroundParticles.particleCount; nn++) {
                                if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                                playgroundParticles.playgroundCache.lifetimeOffset[nn%playgroundParticles.particleCount] = 0;
                            }
                        }
                    break;
                    case SORTINGC.NearestNeighborReversed:
                        playgroundParticles.nearestNeighborOrigin = Mathf.Clamp(playgroundParticles.nearestNeighborOrigin, 0, playgroundParticles.particleCount-1);
                        float[] nnrDist = new float[playgroundParticles.particleCount];
                        float nnrHighest = 0;
                        int nnr = 0;
                        for (; nnr<playgroundParticles.particleCount; nnr++) {
                            if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                            nnrDist[nnr%playgroundParticles.particleCount] = Vector3.Distance(playgroundParticles.playgroundCache.targetPosition[playgroundParticles.nearestNeighborOrigin], playgroundParticles.playgroundCache.targetPosition[nnr%playgroundParticles.particleCount]);
                            if (nnrDist[nnr%playgroundParticles.particleCount]>nnrHighest)
                                nnrHighest = nnrDist[nnr%playgroundParticles.particleCount];
                        }
                        if (nnrHighest>0) {
                            for (nnr = 0; nnr<playgroundParticles.particleCount; nnr++) {
                                if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                                playgroundParticles.playgroundCache.lifetimeOffset[nnr%playgroundParticles.particleCount] = Mathf.Lerp(0, playgroundParticles.lifetime, (nnrDist[nnr%playgroundParticles.particleCount]/nnrHighest));
                            }
                        } else {
                            for (nnr = 0; nnr<playgroundParticles.particleCount; nnr++) {
                                if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                                playgroundParticles.playgroundCache.lifetimeOffset[nnr%playgroundParticles.particleCount] = 0;
                            }
                        }
                    break;
                    case SORTINGC.Custom:
                        for (int cs = playgroundParticles.particleCount-1; cs>=0; cs--) {
                            if (pCount!=playgroundParticles.playgroundCache.lifetimeOffset.Length) {playgroundParticles.isSettingLifetime = false; return;}
                            playgroundParticles.playgroundCache.lifetimeOffset[cs] = playgroundParticles.lifetime*playgroundParticles.lifetimeSorting.Evaluate(cs*1f/playgroundParticles.particleCount*1f);
                        }
                    break;
                    }
                }

                SetEmissionRate(playgroundParticles);
                SetParticleTimeNow(playgroundParticles);
                playgroundParticles.previousLifetime = playgroundParticles.lifetime;
                playgroundParticles.previousNearestNeighborOrigin = playgroundParticles.nearestNeighborOrigin;
                playgroundParticles.previousSorting = playgroundParticles.sorting;
                playgroundParticles.isDoneThread = true;
                playgroundParticles.isSettingLifetime = false;
                playgroundParticles.lastTimeUpdated = PlaygroundC.globalTime;
            });
        }