public CustomSpring(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float restLength, float strength, float damping) { if (particleSystem == null) { throw new System.ArgumentNullException("particleSystem", "Cannot supply null as ParticleSystem to CustomSpring"); } if (particle1 == null) { throw new System.ArgumentNullException("particle1", "Cannot supply null as Particle1 to CustomSpring"); } if (particle2 == null) { throw new System.ArgumentNullException("particle2", "Cannot supply null as Particle2 to CustomSpring"); } this.CustomParticleSystem = particleSystem; this.CustomParticleSystem.Springs.Add(this); this.Particle1 = particle1; this.Particle2 = particle2; this.RestLength = restLength; this.Strength = strength; this.Damping = damping; }
IEnumerator StartEmission(CustomParticleSystem system, float time) { foreach (var burst in system.Bursts) { yield return(new WaitForSeconds(burst.Time)); system.Ps.Emit(burst.Count); } }
private CustomParticle addNewParticle(CustomParticleSystem particleSystem, float mass, Vector3 position, Vector3 velocity, bool bFixed, float lifeSpan) { if (ParticlePrefab != null) { CustomParticle particle = (Instantiate(ParticlePrefab) as GameObject).GetComponent <CustomParticle>(); particle.Initialize(particleSystem, mass, position, velocity, bFixed, lifeSpan); return(particle); } else { throw new System.NullReferenceException("ERROR: No particle prefab set on GameController!"); } }
private CustomParticleSystem addNewParticleSystem(Vector3 systemGravity, float systemDrag, Vector3 initialPosition, float samplingRate) { if (ParticleSystemPrefab != null) { CustomParticleSystem particleSystem = (Instantiate(ParticleSystemPrefab) as GameObject).GetComponent <CustomParticleSystem>(); particleSystem.Initialize(systemGravity, systemDrag, samplingRate, initialPosition); ParticleSystems.Add(particleSystem); return(particleSystem); } else { throw new System.NullReferenceException("ERROR: No particle system prefab set on GameController!"); } }
public CustomAttraction(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float strength, float minimumDistance) { if (particleSystem == null) throw new System.ArgumentNullException("particleSystem", "Cannot supply null as ParticleSystem to CustomAttraction"); if (particle1 == null) throw new System.ArgumentNullException("particle1", "Cannot supply null as Particle1 to CustomAttraction"); if (particle2 == null) throw new System.ArgumentNullException("particle2", "Cannot supply null as Particle2 to CustomAttraction"); this.CustomParticleSystem = particleSystem; this.CustomParticleSystem.Attractions.Add(this); this.Particle1 = particle1; this.Particle2 = particle2; this.Strength = strength; this.MinimumDistance = minimumDistance; }
public CustomSpring(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float restLength, float strength, float damping) { if (particleSystem == null) throw new System.ArgumentNullException("particleSystem", "Cannot supply null as ParticleSystem to CustomSpring"); if (particle1 == null) throw new System.ArgumentNullException("particle1", "Cannot supply null as Particle1 to CustomSpring"); if (particle2 == null) throw new System.ArgumentNullException("particle2", "Cannot supply null as Particle2 to CustomSpring"); this.CustomParticleSystem = particleSystem; this.CustomParticleSystem.Springs.Add(this); this.Particle1 = particle1; this.Particle2 = particle2; this.RestLength = restLength; this.Strength = strength; this.Damping = damping; }
public CustomParticle Initialize(CustomParticleSystem particleSystem, float mass, Vector3 position, Vector3 velocity, bool bFixed, float lifeSpan) { if (particleSystem == null) throw new System.ArgumentNullException("particleSystem", "Cannot supply null as ParticleSystem to CustomParticle"); this.CustomParticleSystem = particleSystem; this.CustomParticleSystem.Particles.Add(this); this.Mass = mass; this.Position = position; this.Velocity = velocity; this.SetFixed(bFixed); this.LifeSpan = lifeSpan; this.Age = 0f; this.ClearForce(); this.transform.parent = this.CustomParticleSystem.transform; this.name = "Particle " + this.CustomParticleSystem.Particles.IndexOf(this).ToString(); return this; }
public CustomAttraction(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float strength, float minimumDistance) { if (particleSystem == null) { throw new System.ArgumentNullException("particleSystem", "Cannot supply null as ParticleSystem to CustomAttraction"); } if (particle1 == null) { throw new System.ArgumentNullException("particle1", "Cannot supply null as Particle1 to CustomAttraction"); } if (particle2 == null) { throw new System.ArgumentNullException("particle2", "Cannot supply null as Particle2 to CustomAttraction"); } this.CustomParticleSystem = particleSystem; this.CustomParticleSystem.Attractions.Add(this); this.Particle1 = particle1; this.Particle2 = particle2; this.Strength = strength; this.MinimumDistance = minimumDistance; }
public CustomParticle Initialize(CustomParticleSystem particleSystem, float mass, Vector3 position, Vector3 velocity, bool bFixed, float lifeSpan) { if (particleSystem == null) { throw new System.ArgumentNullException("particleSystem", "Cannot supply null as ParticleSystem to CustomParticle"); } this.CustomParticleSystem = particleSystem; this.CustomParticleSystem.Particles.Add(this); this.Mass = mass; this.Position = position; this.Velocity = velocity; this.SetFixed(bFixed); this.LifeSpan = lifeSpan; this.Age = 0f; this.ClearForce(); this.transform.parent = this.CustomParticleSystem.transform; this.name = "Particle " + this.CustomParticleSystem.Particles.IndexOf(this).ToString(); return(this); }
private GUIStyle m_guiStyle = new GUIStyle(); //For smaller text public override void OnInspectorGUI() { serializedObject.Update(); m_guiStyle.fontSize = 9; //Reference to the CustomParticleSystem CustomParticleSystem myTarget = (CustomParticleSystem)target; //General options myTarget.p_EmitterType = (CustomParticleSystem.EmitterType)EditorGUILayout.EnumPopup("Particle System", myTarget.p_EmitterType); Show(serializedObject.FindProperty("p_ParticleReferences")); myFlag = myTarget.p_EmitterType; if (myFlag == CustomParticleSystem.EmitterType.Radial) { myTarget.p_NumberOfParticles = EditorGUILayout.IntField("Particles Per Burst", myTarget.p_NumberOfParticles); } else { myTarget.p_NumberOfParticles = EditorGUILayout.IntField("Number Of Particles", myTarget.p_NumberOfParticles); } myTarget.p_ParticleSpeed = EditorGUILayout.FloatField("Particle Speed", myTarget.p_ParticleSpeed); //Repeat Toggle + Value myTarget.p_isRepeating = EditorGUILayout.Toggle("Repeating", myTarget.p_isRepeating); if (myTarget.p_isRepeating) { EditorGUI.indentLevel += 1; myTarget.p_repeatSpeed = EditorGUILayout.FloatField("Repeat Speed", myTarget.p_repeatSpeed); EditorGUI.indentLevel -= 1; GUILayout.Space(10); } //Fade Toggle + Value myTarget.p_isFading = EditorGUILayout.Toggle("Fading", myTarget.p_isFading); if (myTarget.p_isFading) { EditorGUI.indentLevel += 1; myTarget.p_fadeSpeed = EditorGUILayout.FloatField("Fade Speed", myTarget.p_fadeSpeed); myTarget.p_destroyOnFade = EditorGUILayout.Toggle("Destroy On Fade?", myTarget.p_destroyOnFade); EditorGUI.indentLevel -= 1; GUILayout.Space(10); } if (myFlag == CustomParticleSystem.EmitterType.Radial) { //Radial options myTarget.p_rotateTowardsVelocity = EditorGUILayout.Toggle("Rotate Towards Velocity", myTarget.p_rotateTowardsVelocity); myTarget.p_arcBurst = EditorGUILayout.Toggle("Arc Burst", myTarget.p_arcBurst); if (myTarget.p_arcBurst) { myTarget.p_burstArc = EditorGUILayout.FloatField("Burst Arc", myTarget.p_burstArc); myTarget.p_rotationBurstInDegrees = EditorGUILayout.FloatField("Rotation", myTarget.p_rotationBurstInDegrees); } } if (myFlag == CustomParticleSystem.EmitterType.Emitter) { //Emitter options myTarget.p_arcWidth = EditorGUILayout.FloatField("Arc Of Emission", myTarget.p_arcWidth); GUILayout.BeginHorizontal(); GUILayout.Space(140); GUILayout.Label("Default direction is straight up on the Y Axis", m_guiStyle); GUILayout.EndHorizontal(); myTarget.p_rotationInDegrees = EditorGUILayout.FloatField("Rotation Of Emission", myTarget.p_rotationInDegrees); } if (myFlag == CustomParticleSystem.EmitterType.Trail) { //Trail options } serializedObject.ApplyModifiedProperties(); }
private CustomSpring addNewSpring(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float restLength, float strength, float damping) { return(new CustomSpring(particleSystem, particle1, particle2, restLength, strength, damping)); }
private void addNewBeamSystem() { Vector3 gravity = playerRef.transform.forward.normalized; float drag = 0.1f; int particleCount = 30; float particleMass = 10f, particleLifeSpan = 60f; float samplingRate = 10f; // 10 ms float springRestLength = 3f, springStrength = 3f, springDamping = 0.75f; CustomParticleSystem beamSystem = addNewParticleSystem(gravity, drag, playerRef.transform.position, samplingRate); beamSystem.name = "BEAM SYSTEM"; CustomParticle leaderParticle = addNewParticle(beamSystem, particleMass, beamSystem.Position + new Vector3(0f, 1f, 0f), Vector3.zero, true, particleLifeSpan); leaderParticle.name = "Leader Particle"; leaderParticle.transform.rotation = playerRef.transform.rotation; List <CustomParticle> stream1 = new List <CustomParticle>(), stream2 = new List <CustomParticle>(), stream3 = new List <CustomParticle>(), stream4 = new List <CustomParticle>(); for (int i = 0; i < Mathf.RoundToInt(particleCount / 4f); i++) { Vector3 pos = beamSystem.Position - playerRef.transform.forward.normalized * (float)(i + 1); CustomParticle particle = addNewParticle(beamSystem, particleMass, pos, Vector3.zero, false, particleLifeSpan); particle.name = "Stream_1-" + i.ToString(); stream1.Add(particle); CustomParticle particle2 = addNewParticle(beamSystem, particleMass, pos, Vector3.zero, false, particleLifeSpan); particle2.name = "Stream_2-" + i.ToString(); stream2.Add(particle2); CustomParticle particle3 = addNewParticle(beamSystem, particleMass, pos, Vector3.zero, false, particleLifeSpan); particle3.name = "Stream_3-" + i.ToString(); stream3.Add(particle3); CustomParticle particle4 = addNewParticle(beamSystem, particleMass, pos, Vector3.zero, false, particleLifeSpan); particle4.name = "Stream_4-" + i.ToString(); stream4.Add(particle4); if (i > 0) { addNewSpring(beamSystem, stream1[i], stream1[i - 1], springRestLength, springStrength, springDamping); addNewSpring(beamSystem, stream2[i], stream2[i - 1], springRestLength, springStrength, springDamping); addNewSpring(beamSystem, stream3[i], stream3[i - 1], springRestLength, springStrength, springDamping); addNewSpring(beamSystem, stream4[i], stream4[i - 1], springRestLength, springStrength, springDamping); } else { addNewSpring(beamSystem, leaderParticle, particle, springRestLength, springStrength * 1.5f, springDamping); addNewSpring(beamSystem, leaderParticle, particle2, springRestLength, springStrength * 1.5f, springDamping); addNewSpring(beamSystem, leaderParticle, particle3, springRestLength, springStrength * 1.5f, springDamping); addNewSpring(beamSystem, leaderParticle, particle4, springRestLength, springStrength * 1.5f, springDamping); } } }
private CustomAttraction addNewAttraction(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float strength, float minimumDistance) { return(new CustomAttraction(particleSystem, particle1, particle2, strength, minimumDistance)); }
public CustomParticle Initialize(CustomParticleSystem particleSystem) { return Initialize(particleSystem, Mass, Vector3.zero, Vector3.zero, Fixed, LifeSpan); }
private CustomParticle addNewParticle(CustomParticleSystem particleSystem, float mass, Vector3 position, Vector3 velocity, bool bFixed, float lifeSpan) { if (ParticlePrefab != null) { CustomParticle particle = (Instantiate(ParticlePrefab) as GameObject).GetComponent<CustomParticle>(); particle.Initialize(particleSystem, mass, position, velocity, bFixed, lifeSpan); return particle; } else { throw new System.NullReferenceException("ERROR: No particle prefab set on GameController!"); } }
private CustomAttraction addNewAttraction(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float strength, float minimumDistance) { return new CustomAttraction(particleSystem, particle1, particle2, strength, minimumDistance); }
private CustomSpring addNewSpring(CustomParticleSystem particleSystem, CustomParticle particle1, CustomParticle particle2, float restLength, float strength, float damping) { return new CustomSpring(particleSystem, particle1, particle2, restLength, strength, damping); }
void Update() { if (Input.GetKeyDown(KeyCode.B)) { addNewBeamSystem(); } if (Input.GetKeyDown(KeyCode.Delete) || Input.GetKeyDown(KeyCode.Backspace)) { if (this.ParticleSystems.Count > 0) { Destroy(ParticleSystems[0].gameObject, 1f); this.ParticleSystems.RemoveAt(0); Debug.Log("DELETED 0th particle system in list"); } } if (ParticleSystems.Count > 0) { foreach (CustomParticleSystem beamSystem in ParticleSystems) { if (beamSystem.Particles.Count > 0) { for (int i = 0; i < beamSystem.Particles.Count; i++) { CustomParticle particle = beamSystem.Particles[i]; if (!particle.Fixed) { particle.Velocity += Random.insideUnitSphere; } else { if (!particle.bProhibitMovement) { particle.transform.position += particle.transform.forward.normalized / 4f; } } } } } CustomParticleSystem lastBeam = ParticleSystems[ParticleSystems.Count - 1]; if (lastBeam != null && lastBeam.Particles.Count > 0) { CustomParticle leaderParticle = lastBeam.Particles[0]; if (leaderParticle != null) { Vector3 leaderPos = leaderParticle.Position; if (lastBeam.GetComponentInChildren <Camera>() == null) { beamCamera = (Instantiate(Resources.Load("BeamCamera")) as GameObject).GetComponent <Camera>(); beamCamera.transform.parent = lastBeam.transform; beamCamera.transform.localPosition = leaderPos + new Vector3(5f, 20f, 0f); beamCamera.transform.LookAt(leaderParticle.transform.position); beamCamera.transform.localPosition += new Vector3(0f, 0f, 20f); } else { beamCamera.transform.localPosition = leaderPos + new Vector3(5f, 20f, 0f); beamCamera.transform.LookAt(leaderParticle.transform.position); beamCamera.transform.localPosition += new Vector3(0f, 0f, 20f); } } } } }
public CustomParticle Initialize(CustomParticleSystem particleSystem) { return(Initialize(particleSystem, Mass, Vector3.zero, Vector3.zero, Fixed, LifeSpan)); }