public IEnumerator ShrinkOverTime(float length) { float elapsedTime = 0.0f; float startLife, endLife, currLife; startLife = currLife = ps.startLifetime; endLife = endLifetime; while (elapsedTime < length) { ps.startLifetime = currLife; currLife = Mathf.Lerp(startLife, endLifetime, elapsedTime / length); // alpha stuff CurAlpha = Mathf.Lerp(CurAlpha, EndAlpha, elapsedTime * 0.1f / length); ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.maxParticles]; int numParticles = ps.GetParticles(particles); for (int i = 0; i < numParticles; i++) { particles[i].color = new Color(particles[i].color.r, particles[i].color.g, particles[i].color.b, CurAlpha); } ps.SetParticles(particles, numParticles); elapsedTime += Time.deltaTime; yield return new WaitForEndOfFrame(); } ps.enableEmission = false; Destroy(gameObject); }
/// <summary> /// Move all the alive particles to there positions on the unit /// </summary> public void moveParticls(){ emissionRate += 0.05f; ParticleSystem.EmissionModule emission = PS.emission; ParticleSystem.MinMaxCurve rate = emission.rate; rate.constantMax = emissionRate; emission.rate = rate; moveOverTimeMultiplyer += 0.02f; float tempParticalMoveAmount = particleMoveAmount * moveOverTimeMultiplyer; particles = new ParticleSystem.Particle[PS.particleCount]; int numberP = PS.GetParticles(particles); int x = 0; int y = 0; for(int i = 0; i < numberP; i++){ tempParticalMoveAmount *= particles[i].startLifetime - particles[i].lifetime; particles[i].position = Vector3.MoveTowards(particles[i].position, endLocations[x, y], tempParticalMoveAmount); x++; if(x >= widthOfParticals){ x = 0; y++; } } if(numberP == numberOfParticles){ if(!timeHasBeenFound && particles[numberOfParticles - 1].position == endLocations[widthOfParticals - 1, widthOfParticals - 1]){ Destroy(gameObject, 0.1f); /* Debug.Log("Time to compleat is " + time); //uncoment this to find time timeHasBeenFound = true; */ } } PS.SetParticles(particles, numberP); }
// An alternative collision system from within the particle system's script // It's butters slow!! void CheckCollision() { bool hitSummat = false; ParticleSystem.Particle[] particles = new ParticleSystem.Particle[_particleBullets.maxParticles]; int numParts = _particleBullets.GetParticles(particles); if(numParts == 0) return; for(int i = 0; i < numParts; i++) { Collider[] hit = Physics.OverlapSphere(particles[i].position, particles[i].size * 0.5f, enemyLayer); if(hit.Length == 0) continue; // next iter if no collision foreach( Collider col in hit) // hit enemy { CollisionTestWall wall = col.gameObject.GetComponent<CollisionTestWall>(); if(wall != null) wall.Die(); } particles[i].lifetime = 0; // kill particle hitSummat = true; } if(hitSummat) _particleBullets.SetParticles(particles, numParts); }
// Update is called once per frame void Update () { ParticleSystem.Particle[] currentParticles = new ParticleSystem.Particle[GetComponent<ParticleSystem>().particleCount]; GetComponent<ParticleSystem>().GetParticles(currentParticles); for(int i = 0; i < GetComponent<ParticleSystem>().particleCount; i++) { //Get vector from particle position to transform position Vector3 particleVector = currentParticles[i].position - transform.position; //Change vector into local space particleVector = Quaternion.Inverse(transform.rotation)*particleVector; //Remove z from local space //This is so falloff will only take X and Y distance into account particleVector.z = 0.0f; //Chanve vector back into world space particleVector = transform.rotation*particleVector; //Alpha falloff based on X/Y distance float alpha = Mathf.Lerp(1.0f,0.0f,particleVector.sqrMagnitude*distanceFalloffMultiplier); Color newColor = currentParticles[i].color; newColor.a = alpha; currentParticles[i].color = newColor; } GetComponent<ParticleSystem>().SetParticles(currentParticles, GetComponent<ParticleSystem>().particleCount); }
public static void Hit(float accuracy) { ParticleSystem.Particle[] particles = new ParticleSystem.Particle[singleton.circlePs.particleCount]; singleton.circlePs.GetParticles(particles); singleton.circlePs.SetParticles(particles, singleton.circlePs.particleCount); singleton.circlePs.Emit((int)( 10 * accuracy)); }
public void OnBlow() { GameObject fogGO = GameObject.FindGameObjectWithTag("Fog"); if (!fogGO) return; ParticleSystem emitter = fogGO.GetComponent<ParticleSystem>(); if (!emitter) return; ParticleSystem.Particle[] particles = new ParticleSystem.Particle[emitter.maxParticles]; emitter.GetComponent<ParticleSystem>().GetParticles(particles); SphereCollider collider = vision.GetComponent<SphereCollider>(); List<ParticleSystem.Particle> particleList = new List<ParticleSystem.Particle>(); foreach (ParticleSystem.Particle particle in particles) { if (!collider.bounds.Contains(particle.position)) particleList.Add(particle); } emitter.SetParticles(particleList.ToArray(), particleList.Count); }
void Update() { var particles = new ParticleSystem.Particle[_particleSystem.maxParticles]; int aliveParticleNumber = _particleSystem.GetParticles(particles); Blob blob; int i = 0; while (i < aliveParticleNumber) { if (i >= _blobs.Count) { var blobGameObject = new GameObject("Blob"); blobGameObject.transform.parent = transform; blob = blobGameObject.AddComponent<Blob>(); _blobs.Add(blob); } else blob = _blobs[i]; blob.transform.position = _particleSystem.transform.position + _particleSystem.transform.rotation * particles[i].position; i++; } while (i < _blobs.Count) { blob = _blobs[i]; _blobs.RemoveAt(i); Destroy(blob.gameObject); } }
// Update is called once per frame void Update () { timer += Time.deltaTime; if (timer >= detonateDelay && !isDestroy) { detonate (); } if (isDamage) { damage_timer += Time.deltaTime; if (damage_timer >= 0.21f) { AudioSource.PlayClipAtPoint (detonateAudio.clip,transform.position); takeDamage (); } } if (isDestroy) { explosionEffectLight.intensity -= 1; ParticleSystem.Particle []particleList = new ParticleSystem.Particle[explosionEffectParticle.particleCount]; explosionEffectParticle.GetParticles(particleList); for(int i = 0; i < particleList.Length; ++i) { byte r = particleList [i].color.r; byte g = particleList [i].color.g; byte b = particleList [i].color.b; byte a = particleList [i].color.a; a--;a--; particleList[i].color = new Color32(r, g, b, a); } explosionEffectParticle.SetParticles(particleList, explosionEffectParticle.particleCount); destroy_timer += Time.deltaTime; if (destroy_timer >= 1.6f) destroy (); } }
public void AddProject(KSProject project, string positioning) { MasterSettings ms = MasterSettings.me; ParticleSystem.Particle temp = new ParticleSystem.Particle(); int arraySize = particleSystem.GetParticles(particles); temp.size = ms.WindowSize; temp.color = KSJSON.me.parentCatColors[project.parentCat]; temp.startLifetime = int.MaxValue; temp.lifetime = int.MaxValue; switch(positioning.ToLower()) { case "scatter": temp.position = ScatterPosition(project); break; case "bar": default: temp.position = BarPosition(arraySize); break; } Array.Resize<ParticleSystem.Particle>(ref particles, arraySize + 1); particles[arraySize] = temp; particleSystem.SetParticles(particles, arraySize + 1); }
void LateUpdate() { timer += Time.deltaTime; if(timer>=timeToUpdate){ timer = 0f; Mesh baked = new Mesh(); skin.BakeMesh(baked); int index = 0; int total = 0; Vector3 pos = Vector3.zero; ParticleSystem.Particle[] gos = new ParticleSystem.Particle[particleSystem.particleCount]; total = particleSystem.GetParticles(gos); while(index < total){ pos = gos[index].position; int indexV = (int)(((float)index/(float)total)*baked.vertices.Length); pos.x = baked.vertices[indexV%baked.vertices.Length].x; pos.y = baked.vertices[indexV%baked.vertices.Length].y; pos.z = baked.vertices[indexV%baked.vertices.Length].z; //pos = objectToPutParticlesOn.transform.TransformPoint(pos); gos[index].position = pos; index++; } particleSystem.SetParticles(gos,gos.Length); } }
private IEnumerator FadeParticles() { float startTime = Time.time; ParticleSystem particleSystem = mousePathRenderer.GetComponent<ParticleSystem>(); while (Time.time < startTime + mouseTrailFadeOutTime) { //This sets up an array container to hold all of the particles ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particleSystem.particleCount]; //get the particles particleSystem.GetParticles(particles); byte a = Convert.ToByte(255f*Mathf.Lerp(1f, 0f, (Time.time - startTime)/mouseTrailFadeOutTime)); Color32 newColor = new Color32(255, 255, 255, a); //then iterate through the array changing the color 1 by 1 for(int p = 0; p < particles.Length; p++) { particles[p].color = newColor; } //set the particles back to the system particleSystem.SetParticles(particles, particles.Length); yield return new WaitForEndOfFrame(); } particleSystem.SetParticles(new ParticleSystem.Particle[0], 0); }
void ParticlePull () { float sqrPullDistance = PullDistance * PullDistance; ParticleSystem.Particle[] x = new ParticleSystem.Particle[gameObject.GetComponent<ParticleSystem>().particleCount+1]; int y = GetComponent<ParticleSystem>().GetParticles(x); for (int i = 0; i < y; i++) { Vector3 offset = MagnetPoint.localPosition - x[i].position; //creates Vector3 variable based on the position of the target MagnetPoint (set by user) and the current particle position float sqrLen = offset.sqrMagnitude; //creats float type integer based on the square magnitude of the offset variable set above (faster than .Magnitude) if (sqrLen <= sqrPullDistance) { x[i].position = Vector3.Lerp(x[i].position, MagnetPoint.localPosition, Mathf.SmoothStep(0, 2, (Time.deltaTime / 0.1F))); /*Lerping moves an object between two vectors (syntax is FromVector, ToVector, Fraction) by a given fraction. In our example we take the position of particle i, of particle system x, and the local position of the MagnetPoint transform, and move the particles in from x[i] towards MagnetPoint over time. Lower the Time.deltaTime / # value to increase how fast the particle attracts*/ if ((x[i].position-MagnetPoint.localPosition).magnitude <= 30) { x[i].lifetime = 0; } } } gameObject.GetComponent<ParticleSystem>().SetParticles(x, y); return; }
void Update() { for(int j = 0; j<systems.Length; j++){ ParticleSystem system = systems[j]; Transform t = system.transform; ParticleSystem.Particle[] particles = new ParticleSystem.Particle[system.particleCount]; system.GetParticles(particles); for(int i=0; i<system.particleCount; i++){ Vector3 pos = particles[i].position;//t.TransformPoint(); Debug.DrawLine(pos, transform.position, new Color(1,0.5f, 0.5f, 0.25f)); Vector3 dir = transform.position - pos; float amount = (1 - dir.magnitude / radius) * power / maxPower; dir.Normalize(); /* float amount = Mathf.Clamp01(dir.magnitude / radius); dir = dir.normalized * power; particles[i].velocity = Vector3.Lerp(particles[i].velocity, dir, amount * Time.deltaTime); */ particles[i].velocity = Vector3.Lerp(particles[i].velocity, dir * speed, amount * Time.deltaTime); } system.SetParticles(particles, particles.Length); } }
void Start () { // Cache transform and particle system to improve performance _cacheTransform = transform; _cacheParticleSystem = GetComponent<ParticleSystem>(); // Calculate the actual spawn and fade distances _distanceToSpawn = range * distanceSpawn; _distanceToFade = range * distanceFade; // Scale particles if (_cacheParticleSystem == null) { // Throw an error if the object of this script has no particle system Debug.LogError("This script must be attached to a GameObject with a particle system. It is strongly recommended " + "that you use the SpaceParticles or SpaceFog prefab which have suitable particle systems)"); } // Spawn all new particles within a sphere in range of the object for (int i=0; i < maxParticles; i ++) { ParticleSystem.Particle _newParticle = new ParticleSystem.Particle(); _newParticle.position = _cacheTransform.position + (Random.insideUnitSphere * _distanceToSpawn); _newParticle.lifetime = Mathf.Infinity; Vector3 _velocity = new Vector3( Random.Range(minParticleDriftSpeed, maxParticleDriftSpeed) * driftSpeedMultiplier, Random.Range(minParticleDriftSpeed, maxParticleDriftSpeed) * driftSpeedMultiplier, Random.Range(minParticleDriftSpeed, maxParticleDriftSpeed) * driftSpeedMultiplier); _newParticle.velocity = _velocity; _newParticle.size = Random.Range(minParticleSize, maxParticleSize) * sizeMultiplier; GetComponent<ParticleSystem>().Emit(1); } }
void Update() { particles = new ParticleSystem.Particle[MAX_PARTICLES * MAX_PARTICLES]; for (int i = 0; i < MAX_PARTICLES * MAX_PARTICLES; i++) { particles[i] = new ParticleSystem.Particle(); particles[i].startLifetime = 10; particles[i].size = 1; particles[i].lifetime = 10; particles[i].color = Color.white; } for (int i = 0; i < MAX_PARTICLES; i++) { for (int j = 0; j < MAX_PARTICLES; j++) { float x = i; float y = j; particles[j * MAX_PARTICLES + i].position = new Vector3(x, 0, y); particles[j * MAX_PARTICLES + i].startLifetime = 10; Color color = Color.white; color.a = Mathf.Lerp(1, 0, Vector3.Distance(particles[j * MAX_PARTICLES + i].position, new Vector3(MAX_PARTICLES * 0.5f, 0, MAX_PARTICLES * 0.5f)) * 0.2f); particles[j * MAX_PARTICLES + i].color = color; } } system.SetParticles(particles, MAX_PARTICLES * MAX_PARTICLES); }
//ordered from least to greatest private void orderParticlesByCurrentDistance(){ int pNumb; ParticleSystem.Particle[] particles = new ParticleSystem.Particle[PS.maxParticles]; pNumb = PS.GetParticles(particles); orderOfParticlesByDistance = new int[pNumb]; float[] particleDistance = new float[pNumb]; for(int i = 0; i < pNumb; i++){ // simple sort orderOfParticlesByDistance[i] = i; particleDistance[i] = particles[i].position.x; } int offset = 1; while(particleDistance[offset] < particleDistance[offset - 1]){ //move current particle down the list int temp1 = orderOfParticlesByDistance[offset - 1]; float temp2 = particleDistance[offset - 1]; orderOfParticlesByDistance[offset - 1] = orderOfParticlesByDistance[offset]; particleDistance[offset - 1] = particleDistance[offset]; orderOfParticlesByDistance[offset] = temp1; particleDistance[offset] = temp2; offset++; } currentSizeIndex = pNumb - 1; }
public static void Beat(float amount) { ParticleSystem.Particle[] particles = new ParticleSystem.Particle[singleton.squarePs.particleCount]; singleton.squarePs.GetParticles(particles); singleton.squarePs.SetParticles(particles, singleton.squarePs.particleCount); singleton.squarePs.Emit((int)((ScoreManager.singleton.Combo+10) * amount)); }
/// <summary> /// Uses ColorsOnPainting evenly accross all particles in this particle system. /// http://answers.unity3d.com/questions/347675/how-to-change-particle-systems-color-over-lifetime.html /// </summary> private void setColors() { ParticleSystem.Particle[] ParticleList = new ParticleSystem.Particle[particles.particleCount]; particles.GetParticles(ParticleList); for (int i = 0; i < ParticleList.Length; ++i) { //cycle through available colors ParticleList[i].color = ColorsOnPainting[i % ColorsOnPainting.Length]; } particles.SetParticles(ParticleList, particles.particleCount); }
public override void UpdateSystem(MusicLoader ldr) { sysMySys.startSize = ldr.fKickPower * 2.0f; ParticleSystem.Particle[] particles = new ParticleSystem.Particle[sysMySys.particleCount]; sysMySys.GetParticles(particles); for (int i = 0; i < particles.Length; i++) { //particles[i].size = Mathf.Lerp(particles[i].size, ldr.fKickPower * 2.0f, 0.1f * Time.deltaTime * Time.timeScale); particles[i].size = (ldr.fKickPower * 2.0f) + 1.0f; } sysMySys.SetParticles(particles, particles.Length); }
void Update() { ParticleSystem.Particle[] particleList = new ParticleSystem.Particle[pSystem.particleCount]; pSystem.GetParticles(particleList); for (int i = 0; i < particleList.Length; i++) { Debug.DrawLine(transform.TransformPoint(particleList[i].position)/transform.lossyScale.x, Vector3.zero, Color.red); pSystem.SetParticles(particleList, pSystem.particleCount); } }
void SetParticles() { if (sources != null) { ParticleSystem.Particle[] parts = new ParticleSystem.Particle[sources.Length]; for (int i = 0; i < sources.Length; i++) { parts[i] = sources[i].particle; } particleSystem.SetParticles(parts, parts.Length); } }
private void LateUpdate() { int particlecount; ParticleSystem.Particle[] particles = new ParticleSystem.Particle[GetComponent<ParticleSystem>().particleCount]; { particlecount = GetComponent<ParticleSystem>().GetParticles( particles ); } for ( int particle = 0; particle < particlecount; particle++ ) { particles[particle].velocity = ( transform.position - particles[particle].position ).normalized * Time.deltaTime * 10000; } GetComponent<ParticleSystem>().SetParticles( particles, particlecount ); }
// Member Methods public void OnGalaxyCameraShifted(GameObject _GameObject, Vector3 _Translation) { foreach(ParticleSystem ps in GetComponentsInChildren<ParticleSystem>()) { ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.particleCount]; int num = ps.GetParticles(particles); for(int i = 0; i < num; ++i) { particles[i].position += _Translation; } ps.SetParticles(particles, num); } }
private IEnumerator RandomlyColorParticles() { yield return new WaitForEndOfFrame(); ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ ps.particleCount ]; int length = ps.GetParticles( particles ); for( int i = 0; i < length; i++ ) particles[i].color = new Color( Random.value, Random.value, Random.value, 1f ); ps.SetParticles( particles, length ); }
private ParticleSystem.Particle NewPoint(Vector3 center) { var result = new ParticleSystem.Particle(); result.position = Random.insideUnitSphere * radius; var colorVal = 0.8f + 0.2f * Random.value; result.startColor = new Color(colorVal, colorVal, colorVal); result.startSize = size; result.position += center; return result; }
// Update is called once per frame void Update () { ParticleSystem.Particle[] p = new ParticleSystem.Particle[snow.particleCount+1]; int l = snow.GetParticles(p); int i = 0; while (i < l) { p[i].velocity = new Vector3(-1*Util.percentDiff(-1*p[i].velocity.x,World.data.WindSpeed()*speed,0.05f), p[i].velocity.y, p[i].velocity.z); i++; } snow.SetParticles(p, l); }
/// <summary> /// Alter trancperincy of particals at random /// </summary> private void flickerParticals(){ ParticleSystem.Particle[] particals = new ParticleSystem.Particle[100]; int pNum; pNum = PS.GetParticles(particals); for (int i = 0; i < pNum; i++) { if(Random.Range(0,4) == 3){ // less likely to be clear particals[i].startColor = Color.clear; }else{ particals[i].startColor = Color.white; } } PS.SetParticles(particals,pNum); }
void Start() { this.numPoints = (int)Mathf.Clamp(this.numPoints,10,500); points = new ParticleSystem.Particle[numPoints]; for (int i = 0; i < numPoints; i++) { ParticleSystem.Particle part = new ParticleSystem.Particle(); part.position = new Vector3((i+1)*this.transform.localScale.x/numPoints,0f,0f); part.color = Color.red; part.size = 1.0f/numPoints * this.transform.localScale.x* 10.0f; points[i] = part; } }
private void AlterParticle( ParticleSystem _ParticleSystem ) { ParticleSystem.Particle [] parray = new ParticleSystem.Particle[ _ParticleSystem.particleCount ] ; int num = _ParticleSystem.GetParticles( parray ) ; Debug.Log( "num" + num ); for( int i = 0 ; i < num ; ++i ) { parray[i].position = Vector3.zero ; parray[i].color = Color.red ; // Debug.Log( "parray[i].position=" + parray[i].position ) ; } _ParticleSystem.SetParticles( parray , parray.Length ) ; }
public override void UpdateSystem(MusicLoader ldr) { sysMySys.startSize = ldr.fKickPower * 2.0f; ParticleSystem.Particle[] particles = new ParticleSystem.Particle[sysMySys.particleCount]; sysMySys.GetParticles(particles); for (int i = 0; i < particles.Length; i++) { particles[i].size = Mathf.Lerp(particles[i].size, ldr.fKickPower * 2.0f, 0.1f * Time.deltaTime * Time.timeScale); } sysMySys.SetParticles(particles, particles.Length); renSystemRenderer.material.color = Color.Lerp(renSystemRenderer.material.color, new Color(0.0f, 1.0f * ldr.fKickPower, 0.0f, 1.0f), 0.1f * Time.timeScale * Time.deltaTime); sysMySys.startColor = Color.Lerp(sysMySys.startColor, new Color(0.0f, 1.0f * ldr.fKickPower, 0.0f, 1.0f), 0.1f * Time.timeScale * Time.deltaTime); }
void Update() { for (int i = 0; i < particleSystems.Length; i++) { ParticleSystem.Particle[] particleArray = new ParticleSystem.Particle[particleSystems[i].particleCount]; particleSystems[i].GetParticles(particleArray); for (int j = 0; j < particleArray.Length; j++) { //Vector3 particleWorldPosition = particleSystems[i].transform.TransformPoint(particleArray[j].position); float distance = Vector3.Distance(particleArray[j].position, transform.position); if (distance <= radius) { Vector3 difference = transform.position - particleArray[j].position; particleArray[j].velocity += difference * intensity; //particleArray[j].position = new Vector3(particleArray[j].position.x, particleArray[j].position.y, -1); particleArray[j].startColor = Color.green; } } particleSystems[i].SetParticles(particleArray); } }
internal double GetSplinePercent(Wrap wrap, ParticleSystem.Particle particle, MotionType motionType) { float lifePercent = particle.remainingLifetime / particle.startLifetime; if (motionType == MotionType.FollowBackward) { lifePercent = 1f - lifePercent; } switch (wrap) { case Wrap.Default: return(DMath.Clamp01(startPercent + (1f - lifePercent) * cycleSpeed)); case Wrap.Loop: double loopPoint = startPercent + (1.0 - lifePercent) * cycleSpeed; if (loopPoint > 1.0) { loopPoint -= Mathf.FloorToInt((float)loopPoint); } return(loopPoint); } return(0.0); }
// Update is called once per frame void Update() { if (isSimulating) { ParticleSystem.Particle[] fluidParticles = new ParticleSystem.Particle[particleCount]; bool r = AcessDLL.ReadMemoryShare(memMapName, dataStream); psFluid.GetParticles(fluidParticles); //Debug.Log(fluidParticles.Length); //Debug.Log(dataStream.Length); int particleIndex = 0; for (int i = 0; i < dataStream.Length; i += 3) { Vector3 newPos = new Vector3(dataStream[i], dataStream[i + 1], dataStream[i + 2]); //fluidParticles[particleIndex].color = colors[ii]; fluidParticles[particleIndex].position = newPos; //Debug.DrawLine(newPos, new Vector3(newPos.x + 0.1f, newPos.y, newPos.z)); particleIndex++; } psFluid.SetParticles(fluidParticles, fluidParticles.Length); } }
// draw one mouse click, one brush to canvas void DrawPoint(Vector3 p) { var particle = new ParticleSystem.Particle(); particle.position = p; if (selectedColor < 10) { particle.color = allColors[selectedColor]; } else { particle.color = PickRandomColor(); } // a little organic swelling particle.size = brushBase + brushMultiplier * brushSize; //*Random.Range( brushBase, (brushBase * 100) );// * Random.Range( 0.5f, 1.5f ); particle.rotation = Random.Range(0f, 359f); pointList.Add(particle); }
// Update is called once per frame void Update() { timer += Time.deltaTime; if (timer >= detonateDelay && !isDestroy) { detonate(); } if (isDamage) { damage_timer += Time.deltaTime; if (damage_timer >= 0.21f) { AudioSource.PlayClipAtPoint(detonateAudio.clip, transform.position); takeDamage(); } } if (isDestroy) { explosionEffectLight.intensity -= 1; ParticleSystem.Particle [] particleList = new ParticleSystem.Particle[explosionEffectParticle.particleCount]; explosionEffectParticle.GetParticles(particleList); for (int i = 0; i < particleList.Length; ++i) { byte r = particleList [i].color.r; byte g = particleList [i].color.g; byte b = particleList [i].color.b; byte a = particleList [i].color.a; a--; a--; particleList[i].color = new Color32(r, g, b, a); } explosionEffectParticle.SetParticles(particleList, explosionEffectParticle.particleCount); destroy_timer += Time.deltaTime; if (destroy_timer >= 1.6f) { destroy(); } } }
static int get_angularVelocity(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name angularVelocity"); } else { LuaDLL.luaL_error(L, "attempt to index angularVelocity on a nil value"); } } ParticleSystem.Particle obj = (ParticleSystem.Particle)o; LuaScriptMgr.Push(L, obj.angularVelocity); return(1); }
private void OnEnable() { if (particles == null) { particles = gameObject.EnsureComponent <ParticleSystem>(); } mainNoiseModule = particles.noise; ParticleSystem.EmissionModule emission = particles.emission; emission.rateOverTime = new ParticleSystem.MinMaxCurve(0); emission.rateOverDistance = new ParticleSystem.MinMaxCurve(0); emission.enabled = true; ParticleSystem.MainModule main = particles.main; main.loop = false; main.playOnAwake = false; main.maxParticles = Mathf.Min(maxParticles, GlobalMaxParticles); main.simulationSpace = ParticleSystemSimulationSpace.World; ParticleSystem.ShapeModule shape = particles.shape; shape.enabled = false; MainParticleRenderer.sharedMaterial = lineMaterial; MainParticleRenderer.enabled = true; // Initialize our particles for (int i = 0; i < mainParticleArray.Length; i++) { ParticleSystem.Particle particle = mainParticleArray[i]; particle.startColor = Color.white; particle.startSize = 1f; particle.startLifetime = float.MaxValue; particle.remainingLifetime = float.MaxValue; particle.velocity = Vector3.zero; particle.angularVelocity = 0; mainParticleArray[i] = particle; } }
static int get_color(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name color"); } else { LuaDLL.luaL_error(L, "attempt to index color on a nil value"); } } ParticleSystem.Particle obj = (ParticleSystem.Particle)o; LuaScriptMgr.PushValue(L, obj.color); return(1); }
void CreateParticles() { fragments = new List <Fragment>(); var cols = inputTex.GetPixels(); var width = inputTex.width; var height = inputTex.height; var offset = new Vector3(-width, -height) * 0.5f; for (int x = 0; x < width; x += 2) { for (int y = 0; y < height; y += 2) { var col = cols[x + y * width]; if (col.a > 0) { var f = new Fragment(); f.home = (offset + new Vector3(x, y, 0)) * 0.05f; f.col = col; fragments.Add(f); } } } particles = new ParticleSystem.Particle[fragments.Count]; for (int i = 0; i < fragments.Count; i++) { var p = new ParticleSystem.Particle(); p.position = fragments[i].home; p.color = fragments[i].col; p.color = new Color32(p.color.r, p.color.g, p.color.b, 255); p.lifetime = float.PositiveInfinity; p.size = 0.4f; p.startLifetime = float.PositiveInfinity; particles[i] = p; } ps.SetParticles(particles, particles.Length); Debug.Log("Count: " + fragments.Count); }
public void InitializePS(int count, Transform targetTf) { // Parent the effect to the target GameObject this.transform.parent = targetTf; this.transform.localPosition = Vector3.zero; this.transform.localRotation = Quaternion.identity; //lerpFactors = new float[count]; // lerp Based bRandomOffsets = new float[count]; distFromTarget = new float[count]; noiseFreq = new float[count]; noiseAmp = new float[count]; // Creates particles if (count >= 50) { Debug.LogError(count + " verts for new " + this.name + ". CPU said :'("); } else { print(count + " verts for new " + this.name); } PS.Emit(count); ParticleSystem.Particle[] particles = new ParticleSystem.Particle[count]; PS.GetParticles(particles); for (int i = 0; i < count; i++) { // lerpFactors[i] = Random.Range(minMaxLerp.x, minMaxLerp.y); // lerp based bRandomOffsets[i] = Random.Range(1 - (bVelOffset / 2), 1 + (bVelOffset / 2)); noiseAmp[i] = Random.Range(bMinMaxNoiseAmp.x, bMinMaxNoiseAmp.y); noiseFreq[i] = Random.Range(bMinMaxNoiseFreq.x, bMinMaxNoiseFreq.y); particles[i].position = targetTf.position; } PS.SetParticles(particles, count); }
// Update is called once per frame void Update() { ParticleSystem.Particle[] particles = new ParticleSystem.Particle[pSys.particleCount]; birdPos = bird.transform.position; pSys.GetParticles(particles); for (int i = 0; i < particles.Length; i++) { Vector3 diff = birdPos - particles[i].position; if (diff.y > 0) { diff.Normalize(); float num = 0.9f; particles[i].velocity = new Vector3((particles[i].velocity.x + diff.x) * num, (particles[i].velocity.y + diff.y) * num, (particles[i].velocity.z + diff.z) * num); } else { if (particles[i].totalVelocity.y < 0) { if (diff.magnitude > 5) { diff.Normalize(); particles[i].velocity += diff; } else { Debug.Log("SLOW"); diff.Normalize(); float num = 0.9f; particles[i].velocity = new Vector3((particles[i].velocity.x + diff.x) * num, (particles[i].velocity.y + diff.y) * num, (particles[i].velocity.z + diff.z) * num); } } } } pSys.SetParticles(particles, particles.Length); }
} // End of Init public override void CreatePoints() { // Getting the size of the density grid. int dim0 = density.GetLength(0); int dim1 = density.GetLength(1); int dim2 = density.GetLength(2); Vector3 indices = Vector3.zero; for (int x = 0; x < dim0; x++) { for (int y = 0; y < dim1; y++) { for (int z = 0; z < dim2; z++) { indices.x = x; indices.y = y; indices.z = z; Color c = Color.blue; // arbitrary c.a = (density[x, y, z] / densityAmplitude); // Somewhat arbitrary too, but guarantees 0 <= c.a <= 1. // Here, we cull. float size = particleScale * inverseDelta.x; // Assumes delta.x == delta.y == delta.z. For now, that's true, but it might change. if (c.a > ALPHA_THRESHOLD) { ParticleSystem.Particle particle = new ParticleSystem.Particle(); Vector3 p = new Vector3(0f, 0f, 0f); p = Vector3.Scale(inverseDelta, (indices - fudgeFactor)) + origin; particle.position = p; particle.color = c; particle.size = size; dynPoints.Add(particle); } } } } } // End of CreatePoints
protected virtual IEnumerator SetRepulsionParticles(GameObject whichCube, GameObject fx, ParticleSystem ps) { while (ps.IsAlive()) { fx.transform.position = transform.position; Vector3 lookPos = new Vector3(whichCube.transform.position.x, fx.transform.position.y, whichCube.transform.position.z); fx.transform.LookAt(lookPos); float dist = Vector3.Distance(transform.position, whichCube.transform.position); float lifeTime = aFactor2 * dist + bFactor2; ps.startLifetime = lifeTime; ParticleSystem.Particle[] particlesList = new ParticleSystem.Particle[ps.particleCount]; ps.GetParticles(particlesList); distance = Vector3.Distance(transform.position, whichCube.transform.position); for (int i = 0; i < ps.particleCount; i++) { dist = Vector3.Distance(transform.position, ps.transform.TransformPoint(particlesList[i].position)); if (dist >= distance) { particlesList[i].startLifetime = 0; } else { particlesList[i].startLifetime = lifeTime; } } ps.SetParticles(particlesList, particlesList.Length); yield return(new WaitForFixedUpdate()); } }
void OnPointCloudChanged(ARPointCloudUpdatedEventArgs eventArgs) { var points = s_Vertices; points.Clear(); foreach (var point in m_PointCloud.positions) { s_Vertices.Add(point); } int numParticles = points.Count; if (m_Particles == null || m_Particles.Length < numParticles) { m_Particles = new ParticleSystem.Particle[numParticles]; } var color = m_ParticleSystem.main.startColor.color; var size = m_ParticleSystem.main.startSize.constant; for (int i = 0; i < numParticles; ++i) { m_Particles[i].startColor = color; m_Particles[i].startSize = size; m_Particles[i].position = points[i]; m_Particles[i].remainingLifetime = 1f; } // Remove any existing particles by setting remainingLifetime // to a negative value. for (int i = numParticles; i < m_NumParticles; ++i) { m_Particles[i].remainingLifetime = -1f; } m_ParticleSystem.SetParticles(m_Particles, Math.Max(numParticles, m_NumParticles)); m_NumParticles = numParticles; }
/// <summary>Called when a particle leaves the trigger.</summary> /// <author>Liam Ireland</author> private void OnParticleTrigger() { List <ParticleSystem.Particle> particles = new List <ParticleSystem.Particle>(); List <ParticleSystem.Particle> newParticles = new List <ParticleSystem.Particle>(); // an arraycontaining the particles to be added foreach (ParticleSystem.Particle particle in particles) // for every particle that just left a trigger { Collider closestCollider = closestStaticCollider(particle.position); Vector3 closestPointOnStaticCollider = closestCollider.bounds.ClosestPoint(particle.position); // get the distance from the particle to the shock wave origin float distanceFromParticleToOrigin = Vector3.Distance(particle.position, particleEmitter.transform.position); // get the distance from the closest point on the collider the particle nearlly missed to the shock wave origin float distanceFromColliderToOrigin = Vector3.Distance(closestPointOnStaticCollider, particleEmitter.transform.position); // if the distance from the particle to the shockwave origin is greater than the closest point to the particle on the collider we're checking to the shockwave origin - it makes sense in my mind, I don't know how to explain it easisly if (distanceFromParticleToOrigin > distanceFromColliderToOrigin) { // doesn't quite work as intended yet - need to find a better check // TODO - find a better check above if (particle.velocity.y <= 0) // pretty dumb, need more robust solution { for (int i = 0; i < 4; i++) // create multiple new particles for every near miss of a static collider { ParticleSystem.Particle newParticle = new ParticleSystem.Particle(); newParticle = particle; newParticle.velocity = new Vector3(newParticle.velocity.x + UnityEngine.Random.Range(-1, 1), newParticle.velocity.y - (i * 0.75F), newParticle.velocity.z + UnityEngine.Random.Range(-1, 1)); newParticle.startColor = new Color32(255, 0, 0, 255); newParticles.Add(newParticle); } } } } ParticleSystem.Particle[] oldParticles = new ParticleSystem.Particle[particleEmitter.particleCount]; particleEmitter.GetParticles(oldParticles); ParticleSystem.Particle[] finalParticles = new ParticleSystem.Particle[oldParticles.Length + newParticles.Count]; oldParticles.CopyTo(finalParticles, 0); newParticles.ToArray().CopyTo(finalParticles, oldParticles.Length); particleEmitter.SetParticles(finalParticles, finalParticles.Length); }
void LateUpdate() { if (target != null) { ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.particleCount]; ps.GetParticles(particles); for (int i = 0; i < particles.Length; i++) { ParticleSystem.Particle p = particles[i]; Vector3 particleWorldPosition; if (ps.main.simulationSpace == ParticleSystemSimulationSpace.Local) { particleWorldPosition = transform.TransformPoint(p.position); } else if (ps.main.simulationSpace == ParticleSystemSimulationSpace.Custom) { particleWorldPosition = ps.main.customSimulationSpace.TransformPoint(p.position); } else { particleWorldPosition = p.position; } Vector3 directionToTarget = (target.position - particleWorldPosition).normalized; Vector3 seekForce = (directionToTarget * force) * Time.deltaTime; p.velocity += seekForce; particles[i] = p; } ps.SetParticles(particles, particles.Length); } }
private ParticleSystem.Particle steer(ParticleSystem.Particle currentParticle) { var currentPos = currentParticle.position; var currentVelocity = currentParticle.velocity; Vector3 alignmentSteering = new Vector3(); Vector3 cohesionSteering = new Vector3(); int boidsSeen = 0; foreach (var particle in particles) { float dist = Vector3.Distance(currentPos, particle.position); if (dist < perceptionRadius) { alignmentSteering += particle.velocity.normalized; cohesionSteering += particle.position; boidsSeen++; } } if (boidsSeen > 0) { alignmentSteering /= boidsSeen; alignmentSteering -= currentVelocity; alignmentSteering = Vector3.ClampMagnitude(alignmentSteering, maxAlignment); cohesionSteering /= boidsSeen; cohesionSteering -= currentPos; cohesionSteering -= currentVelocity; cohesionSteering = Vector3.ClampMagnitude(cohesionSteering, maxCohesion); } currentParticle.velocity += cohesionSteering; currentParticle.velocity += alignmentSteering; if (beatsFFT) { currentParticle.velocity *= beatsFFT.scaledAvgFreq * 10f; } return(currentParticle); }
void Update() { ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.particleCount]; //Debug.Log("ps.particleCount "+ ps.particleCount+ "particles.Length: "+ particles.Length); ps.GetParticles(particles); for (int i = 0; i < particles.Length; i++) { ParticleSystem.Particle p = particles[i]; Vector3 particleWorldPosition; if (ps.main.simulationSpace == ParticleSystemSimulationSpace.Local) { particleWorldPosition = transform.TransformPoint(p.position); } else if (ps.main.simulationSpace == ParticleSystemSimulationSpace.Custom) { particleWorldPosition = ps.main.customSimulationSpace.TransformPoint(p.position); } else { particleWorldPosition = p.position; } Vector3 directionToTarget = (target.position - particleWorldPosition).normalized;//normalized:把向量轉換成長度 1 的「單位向量」 Vector3 seekForce = (directionToTarget * force) * Time.deltaTime; p.velocity += seekForce; particles[i] = p; //Debug.Log(particles[0].velocity); } ps.SetParticles(particles, particles.Length); }
private void OnTriggerEnter(Collider other) { if (other.tag != "Player" || !doesDamage) { return; } ParticleSystem.Particle[] splashParticles = new ParticleSystem.Particle[pSystem.particleCount]; pSystem.GetParticles(splashParticles); for (int i = 0; i < splashParticles.Length; i++) { // add the vector from player to this, multiply by random, disperse splashParticles[i].position += ((transform.position - other.transform.position) * Random.Range(1f, 5) + Random.insideUnitSphere); splashParticles[i].velocity = ((transform.position - other.transform.position) * 10 + Random.insideUnitSphere); } audioManager.PlayObstacle(); pSystem.SetParticles(splashParticles); GetComponent <SphereCollider>().enabled = false; //turn off the collider to avoid double hits Time.timeScale = 0; // game over code //disconnect the player controller and camera PlayerCamera = Move.staticAccess.posObj.GetComponentInChildren <Camera>(); PlayerCamera.transform.SetParent(null, true); gameManager.distanceText.gameObject.SetActive(false); gameManager.gemsText.gameObject.SetActive(false); gameManager.gameOverSplashText.transform.GetChild(1).GetChild(0).GetComponent <Text>() .text = "Distance Traveled: " + Move.staticAccess.distance.ToString("#.##") + "m"; gameManager.gameOverSplashText.transform.GetChild(1).GetChild(1).GetComponent <Text>() .text = "Gems Collected: " + gameManager.gems + " X 5 = " + (gameManager.gems *= 5); gameManager.gameOverSplashText.transform.GetChild(1).GetChild(2).GetComponent <Text>() .text = "Final Score: " + (Move.staticAccess.distance + (float)gameManager.gems).ToString("#.##"); gameManager.gameOverSplashText.SetActive(true); //GameManager.staticManager.ParticleSystem.SetActive(true); Move.staticAccess.enabled = false; //standby for reload StartCoroutine(DieAndRespawn()); }
private void OnParticleCollision(GameObject other) { int numCollisionEvents = Spray.GetCollisionEvents(other, collisionEvents); if (numCollisionEvents > 0) { ParticleReactor reactiveObject = other.GetComponent <ParticleReactor>(); if (reactiveObject != null) { reactiveObject.OnCollision(numCollisionEvents, collisionEvents[0].intersection, collisionEvents[0].normal); } else if (SpawnCrystals == true) { ParticleSystem.Particle newCrystalParticle = new ParticleSystem.Particle(); newCrystalParticle.position = collisionEvents[0].intersection; newCrystalParticle.startSize = CrystalSize * Random.Range(0.5f, 1.5f); newCrystalParticle.rotation3D = Quaternion.LookRotation(Random.onUnitSphere).eulerAngles; //newCrystalParticle.startLifetime = 10f; CrystalParticles.Add(newCrystalParticle); } } }
private ParticleSystem.Particle[] CreateSomePoints(float delta, char axis, float slope) { ParticleSystem.Particle[] somePoints = new ParticleSystem.Particle[resolution]; for (int i = 0; i < resolution; i++) { float variable = i * delta; if (axis == 'x') { somePoints[i].position = new Vector3(variable, slope * variable, 0f); } else if (axis == 'z') { somePoints[i].position = new Vector3(0f, slope * variable, variable); } somePoints[i].startColor = new Color(Math.Abs(variable), 0f, 0f, 0.5f); somePoints[i].startSize = 0.1f; } return(somePoints); }
private void LateUpdate() { Init(); // GetParticles is allocation free because we reuse the m_Particles buffer between updates int numParticlesAlive = m_CachedParticleSystem.GetParticles(m_ParticleSpawners); // Change only the particles that are alive for (int i = 0; i < numParticlesAlive; i++) { ParticleSystem.Particle p = m_ParticleSpawners[i]; if (Vector3.Distance(p.position, m_PrevPosition[i]) > m_DistanceBetweenParticles) { m_EmitParams.startSize = p.GetCurrentSize(m_CachedParticleSystem); m_EmitParams.position = p.position + Random.insideUnitSphere * m_PosDeviation; m_PlumeParticles.Emit(m_EmitParams, 1); } m_PrevPosition[i] = p.position; } // Apply the particle changes to the particle system m_CachedParticleSystem.SetParticles(m_ParticleSpawners, numParticlesAlive); }
IEnumerator LateStart(float waitTime) { yield return(new WaitForSeconds(waitTime)); ParticleSystem.Particle[] parts = new ParticleSystem.Particle[ps.main.maxParticles]; // GetParticles is allocation free because we reuse the parts buffer between updates int numParticlesAlive = ps.GetParticles(parts); // Change only the particles that are alive for (int i = 0; i < numParticlesAlive; i++) { var objToSpawn = new GameObject("treeCollider"); objToSpawn.isStatic = true; objToSpawn.transform.position = parts[i].position; objToSpawn.transform.parent = transform; //Add Components CapsuleCollider c = objToSpawn.AddComponent <CapsuleCollider>(); Vector3 size = parts[i].startSize3D; c.radius = (size.x + size.z) / 2.0f; c.height = size.y * 4f; c.center = new Vector3(0, c.height / 2f, 0); } }
void Update() { //Alloc but w/e. Simpler this way since we store only the positions ParticleSystem.Particle[] _particles = new ParticleSystem.Particle[_ps.particleCount]; _ps.GetParticles(_particles); for (int i = 0; i < _particles.Length; ++i) { ParticleSystem.Particle p = _particles[i]; if (i >= _lrs.Count) { GameObject newGo = Instantiate(LineRendererPrefab, transform); LineRenderer newRenderer = newGo.GetComponent <LineRenderer>(); _lrs.Add(new LineRendererWithPositions(newRenderer, p.position)); newRenderer.widthMultiplier = _sizeMultiplier; } else { _lrs[i].AddPosition(p.position); } } }
void update_particles() { int count = grid.GridPointCount(MinSamples); ParticleSystem.Particle[] particles = new ParticleSystem.Particle[count]; Vector3f camPos = Camera.main.transform.position; int index = 0; foreach (Vector3f v in grid.GridPoints(MinSamples)) { particles[index].position = v; // this doesn't work... float fDist = camPos.Distance(v); float t = MathUtil.Clamp(1.0f - fDist / 2.0f, 0.1f, 1.0f); particles[index].startColor = new Colorf(t); particles[index].startSize = particleSize; index++; } currentPS.SetParticles(particles, count); }
private IEnumerator TimeDelay() { yield return(new WaitForSeconds(ParticleDelay)); ParticleSystem.Particle[] particles = new ParticleSystem.Particle[Particlefollow.particleCount]; while (true) { particles = new ParticleSystem.Particle[Particlefollow.particleCount]; Particlefollow.GetParticles(particles); // Modifying the particles for (int i = 0; i < particles.GetLength(0); i++) { float ForceToAdd = (particles[i].startLifetime - particles[i].remainingLifetime) * (SpeedMult * Vector3.Distance(Target.position, particles[i].position)); particles[i].velocity = (Target.position - particles[i].position).normalized * ForceToAdd; } Particlefollow.SetParticles(particles, particles.Length); yield return(null); } }
void OnParticleTrigger() { // particles List <ParticleSystem.Particle> enter = new List <ParticleSystem.Particle>(); // get int numEnter = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter); // iterate for (int i = 0; i < numEnter; i++) { ParticleSystem.Particle p = enter[i]; // instantiate the Game Object GameObject obj = Instantiate(colliderToSpawn, p.position, Quaternion.identity); obj.SetActive(true); pStats.takePlayerDMG(fireDamage); enter[i] = p; } // set ps.SetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter); }
private IEnumerator alterParticles(PlayerController player) { yield return(new WaitForSeconds(0.15f)); ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particleSystem.particleCount]; int count = particleSystem.GetParticles(particles); for (float t = 0f; t < 1f; t += 0.1f) { for (int i = 0; i < count; i++) { particles[i].position = player.transform.position + Vector3.one * 0.05f;//Vector3.Lerp(particles[i].position, obj.transform.position, t); } particleSystem.SetParticles(particles, count); } ApplyEffect(player.gameObject); player.TakeDamage(damageAmount); yield return(new WaitForSeconds(1f)); particleSystem.Clear(); Die(); }
// Update is called once per frame void FixedUpdate() { if (active) { if (!built) { Build(); } ParticleSystem.Particle[] particles = new ParticleSystem.Particle[25]; // constantly update particle array, room for optimization here partSys.GetParticles(particles); // get particles ParticleUpdate(particles); partSys.SetParticles(particles, 25); // set particles } else { built = false; if (partSys) { partSys.Clear(); } } }
private void LateUpdate() { ParticleSystem.Particle[] p = new ParticleSystem.Particle[parSys.particleCount + 1]; int l = parSys.GetParticles(p); if (affectedByTime) { for (int i = 0; i < l; i++) { p[i].velocity = new Vector3(1f, particleVelocity * timeManager.timeVelocity, 1f); } } else { for (int i = 0; i < l; i++) { p[i].velocity = new Vector3(1f, particleVelocity, 1f); } } parSys.SetParticles(p, l); }