protected virtual void GetParticleSystem() { _particleSystem = GetComponentInChildren <ParticleSystem>(); particleRenderer = GetComponentInChildren <ParticleSystemRenderer>(); // Modules - for ease of access mainModule = _particleSystem.main; collisionModule = _particleSystem.collision; colorBySpeedModule = _particleSystem.colorBySpeed; colorOverTimeModule = _particleSystem.colorOverLifetime; customDataModule = _particleSystem.customData; emissionModule = _particleSystem.emission; externalForcesModule = _particleSystem.externalForces; forceOverTimeModule = _particleSystem.forceOverLifetime; inheritVelocityModule = _particleSystem.inheritVelocity; lightsModule = _particleSystem.lights; limitVelocityOverTimeModule = _particleSystem.limitVelocityOverLifetime; noiseModule = _particleSystem.noise; rotationBySpeedModule = _particleSystem.rotationBySpeed; sizeBySpeedModule = _particleSystem.sizeBySpeed; sizeOverTimeModule = _particleSystem.sizeOverLifetime; trailModule = _particleSystem.trails; triggerModule = _particleSystem.trigger; shapeModule = _particleSystem.shape; velOverTimeModule = _particleSystem.velocityOverLifetime; }
private void Awake() { if (!_isReady) { DebugLog.ToConsole($"Warning - Awake() ran when _isReady is false!", OWML.Common.MessageType.Warning); return; } _particleSystem = GetComponent <ParticleSystem>(); if (_particleSystem == null) { DebugLog.ToConsole($"Error - _particleSystem is null.", OWML.Common.MessageType.Error); _isReady = false; return; } _rotation = transform.rotation; _mainModule = _particleSystem.main; _mainModule.simulationSpace = ParticleSystemSimulationSpace.Custom; _mainModule.customSimulationSpace = _simulationSpace; _velocityOverLifetimeModule = _particleSystem.velocityOverLifetime; _velocityOverLifetimeVector = new RelativisticParticleSystem.ModuleVector(_velocityOverLifetimeModule.x, _velocityOverLifetimeModule.y, _velocityOverLifetimeModule.z); _limitVelocityOverLifetimeModule = _particleSystem.limitVelocityOverLifetime; _limitVelocityOverLifetimeVector = new RelativisticParticleSystem.ModuleVector(_limitVelocityOverLifetimeModule.limitX, _limitVelocityOverLifetimeModule.limitY, _limitVelocityOverLifetimeModule.limitZ); _forceOverLifetimeModule = _particleSystem.forceOverLifetime; _forceOverLifetimeVector = new RelativisticParticleSystem.ModuleVector(_forceOverLifetimeModule.x, _forceOverLifetimeModule.y, _forceOverLifetimeModule.z); }
public void ChangeParticleSystem() { if (index == 0) { index = 1; } else { index = 0; } bool isActive = settingsPanel.activeSelf; particleSystem = particleSystemsArray[index]; settingsPanel.SetActive(false); settingsPanel = settingsPanelArray[index]; if (isActive) { settingsPanel.SetActive(true); } main = particleSystem.main; shape = particleSystem.shape; sizeBySpeed = particleSystem.sizeBySpeed; limitVelocityOverLifetime = particleSystem.limitVelocityOverLifetime; launcher.UpdateParticleSystem(); }
public void Explode(Vector3 position, Color initialColor, Color endColor) { if (particles == null) { particles = gameObject.GetComponentInChildren <ParticleSystem> (); } Gradient gradient = new Gradient(); GradientColorKey[] colorKeys = new GradientColorKey[] { new GradientColorKey(initialColor, 0.0f), new GradientColorKey(endColor, 1.0f) }; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) }; gradient.SetKeys(colorKeys, alphaKeys); ParticleSystem.ColorOverLifetimeModule colorOverLifetime = particles.colorOverLifetime; //will not compile if using ps.colorOverLifetime.color = someColor directly colorOverLifetime.enabled = true; colorOverLifetime.color = gradient; ParticleSystem.LimitVelocityOverLifetimeModule limitVelocityOverLifetime = particles.limitVelocityOverLifetime; limitVelocityOverLifetime.dampen = 0.1f; transform.position = position; particles.Play(); particles.Emit(UnityEngine.Random.Range(particlesPerChip, maxParticles)); }
//破壊時の効果音 IEnumerator playse1() { se1.PlayOneShot(se1.clip);//再生 //破壊エフェクト ps.Stop(); ps.Clear(); ParticleSystem.MainModule main = ps.main; main.loop = false; main.duration = 0.15f; main.maxParticles = 500; main.startLifetime = 0.5f; main.startSpeed = 60; main.startSize = 2.0f; ParticleSystem.EmissionModule emi = ps.emission; emi.rateOverTime = 300; ParticleSystem.LimitVelocityOverLifetimeModule LVOL = ps.limitVelocityOverLifetime; LVOL.enabled = true; LVOL.dampen = 0.3f; LVOL.limit = 5; ps.Play(); //破壊して見えなくする Destroy(this.GetComponent <Collider2D>()); Destroy(this.GetComponent <MeshFilter>()); //効果音再生待ち yield return(new WaitForSeconds(se1.clip.length)); //オブジェクト破棄 Destroy(this.gameObject); }
void Start() { main = particleSystem.main; shape = particleSystem.shape; sizeBySpeed = particleSystem.sizeBySpeed; limitVelocityOverLifetime = particleSystem.limitVelocityOverLifetime; launcher = GetComponent <ParticleLauncher>(); }
void Start() { particleSystem = particleSystemsArray[index]; settingsPanel = settingsPanelArray[index]; main = particleSystem.main; shape = particleSystem.shape; sizeBySpeed = particleSystem.sizeBySpeed; limitVelocityOverLifetime = particleSystem.limitVelocityOverLifetime; launcher = GetComponent <ParticleLauncher>(); }
void Start() { pSystem = GetComponent <ParticleSystem>(); noiseModule = pSystem.noise; mainModule = pSystem.main; startSpeedMax = mainModule.startSpeed.constantMax; limVelModule = pSystem.limitVelocityOverLifetime; velLifeModule = pSystem.velocityOverLifetime; emissionModule = pSystem.emission; colLifeModule = pSystem.colorOverLifetime; rotSpeedModule = pSystem.rotationBySpeed; }
public void StartZoom(Vector3 particleAim) { localSystem = GetComponent <ParticleSystem>(); particles = new ParticleSystem.Particle[localSystem.maxParticles]; //We will never need more space than this this.particleAim = particleAim; AnimationCurve newCurve = new AnimationCurve(); newCurve.AddKey(0, 0); //Constant zero throughout curve newCurve.AddKey(1, 0); ParticleSystem.LimitVelocityOverLifetimeModule limitModule = localSystem.limitVelocityOverLifetime; limitModule.limit = new ParticleSystem.MinMaxCurve(0, newCurve); //Freeze our particles particleCount = localSystem.GetParticles(particles); //Cache our particles and set our count started = true; }
private void Awake() { _particleSystem = GetComponent <ParticleSystem>(); _rotation = transform.rotation; _mainModule = _particleSystem.main; _mainModule.simulationSpace = ParticleSystemSimulationSpace.Custom; _mainModule.customSimulationSpace = _simulationSpace; _velocityOverLifetimeModule = _particleSystem.velocityOverLifetime; _velocityOverLifetimeVector = new ModuleVector(_velocityOverLifetimeModule.x, _velocityOverLifetimeModule.y, _velocityOverLifetimeModule.z); _limitVelocityOverLifetimeModule = _particleSystem.limitVelocityOverLifetime; _limitVelocityOverLifetimeVector = new ModuleVector(_limitVelocityOverLifetimeModule.limitX, _limitVelocityOverLifetimeModule.limitY, _limitVelocityOverLifetimeModule.limitZ); _forceOverLifetimeModule = _particleSystem.forceOverLifetime; _forceOverLifetimeVector = new ModuleVector(_forceOverLifetimeModule.x, _forceOverLifetimeModule.y, _forceOverLifetimeModule.z); }
//Setup particle effects for rendering private void ParticleEffects() { ParticleSystem[] particles = GetComponentsInChildren <ParticleSystem>(); particles = particles.OrderBy(x => x.name).ToArray(); for (int i = 0; i < particles.Length; i++) { particles[i].transform.localEulerAngles = new Vector3(-90f, 0f, 0f); ParticleSystem.EmissionModule emission = particles[i].emission; emission.rateOverTimeMultiplier = 4f; if (Model.Particles[i].ColorIndex != 0) { ParticleSystem.ColorOverLifetimeModule colorOverLifetime = particles[i].colorOverLifetime; ParticleColor particleColors = ParticleColors[Model.Particles[i].ColorIndex - 11]; if (particleColors != null) { Gradient gradient = new Gradient(); GradientColorKey[] colorKeys = new GradientColorKey[3]; colorKeys[0] = new GradientColorKey(particleColors.Start, 0f); colorKeys[1] = new GradientColorKey(particleColors.Mid, 0.5f); colorKeys[2] = new GradientColorKey(particleColors.End, 1f); GradientAlphaKey[] alphaKeys = new GradientAlphaKey[3]; alphaKeys[0] = new GradientAlphaKey(particleColors.Start.a, 0f); alphaKeys[1] = new GradientAlphaKey(particleColors.Mid.a, 0.5f); alphaKeys[2] = new GradientAlphaKey(particleColors.End.a, 1f); gradient.SetKeys(colorKeys, alphaKeys); colorOverLifetime.color = gradient; } } ParticleSystem.LimitVelocityOverLifetimeModule limitVelocityOverLifetime = particles[i].limitVelocityOverLifetime; limitVelocityOverLifetime.enabled = true; limitVelocityOverLifetime.drag = Model.Particles[i].Drag; limitVelocityOverLifetime.multiplyDragByParticleSize = false; limitVelocityOverLifetime.multiplyDragByParticleVelocity = true; ParticleSystemRenderer renderer = particles[i].GetComponent <ParticleSystemRenderer>(); Material material = ParticleMaterial(Model.Particles[i].Blend); particles[i].transform.localScale = transform.lossyScale; if (name.Contains("right") && (Model.Particles[i].Flags & 512) == 0) { renderer.flip = new Vector3(1f, 0f, 0f); } renderer.material.shader = material.shader; renderer.material.CopyPropertiesFromMaterial(material); Texture2D temp = textures[Model.Particles[i].Textures[0]]; Texture2D texture = new Texture2D(temp.width, temp.height, TextureFormat.ARGB32, false); texture.SetPixels32(temp.GetPixels32()); texture.Apply(); renderer.material.SetTexture("_MainTex", texture); renderer.material.renderQueue = 3100; } }
public static void SpawnEffect(Vector3 pos, float radius) { GameObject o = new GameObject("__SHOUTPARTICLES__"); o.transform.position = pos + Vector3.down; o.transform.rotation = Quaternion.Euler(90, 0, 0); o.transform.localScale = Vector3.one * radius / 50; GameObject.Destroy(o, 1); ParticleSystem ps = o.AddComponent <ParticleSystem>(); ParticleSystem.MainModule main = ps.main; ParticleSystem.EmissionModule emission = ps.emission; ParticleSystem.ShapeModule shape = ps.shape; ParticleSystem.LimitVelocityOverLifetimeModule limit = ps.limitVelocityOverLifetime; ParticleSystemRenderer rend = ps.GetComponent <ParticleSystemRenderer>(); main.loop = false; main.duration = 0.5f; main.startLifetime = 0.5f; main.startSpeed = 200; main.startSize = 4; main.startColor = new Color(0.8f, 0.255f, 0.0545f, 0.49f); main.gravityModifier = -2; emission.rateOverTime = 2000; shape.shapeType = ParticleSystemShapeType.Circle; limit.dampen = 0.2f; limit.limit = 1; if (particleMaterial == null) { particleMaterial = new Material(Shader.Find("Particles/Additive")) { mainTexture = Res.ResourceLoader.GetTexture(111), mainTextureScale = new Vector2(30, 1) }; particleMaterial.SetColor("_TintColor", new Color(0.7f, 0.5f, 0f, 0.6f)); } rend.material = particleMaterial; rend.renderMode = ParticleSystemRenderMode.Stretch; rend.lengthScale = 2.5f; }
public IEnumerator SpawnFirework(float comboMod, Vector3 startPosition) { GameObject firework = Instantiate(fireworkPrefab); firework.transform.position = startPosition; ParticleSystem pSystem = firework.GetComponent <ParticleSystem>(); float comboBonusScalar = 1; //Applied to the size during these special ones Vector3 toAim; float yieldTime = .2f; if (DoctorMatchGameManager.Instance.comboController.ComboLevel == 2) //Big combo bonus { pSystem.startColor = Color.blue; comboBonusScalar = 1.1f; toAim = comboTransform.position; yieldTime = .6f; } else if (DoctorMatchGameManager.Instance.comboController.ComboLevel == 1) //Small combo bonus { pSystem.startColor = Color.green; comboBonusScalar = 1.1f; toAim = scoreTransform.position; yieldTime = .4f; } else { toAim = selectorTransform.position; } ParticleSystem.LimitVelocityOverLifetimeModule emissionModule = pSystem.limitVelocityOverLifetime; //HACK: Currently, you cannot modify particle system module curves directly, so we save it here and modify it later AnimationCurve ourCurve = new AnimationCurve(); for (float i = 0; i <= 1; i += .1f) { ourCurve.AddKey(i, 250 * Mathf.Pow(i - 1, 4)); //Kind of like quadratic but it gets roughly flat after .5 } emissionModule.limit = new ParticleSystem.MinMaxCurve((1 + comboMod / 20) * comboBonusScalar, ourCurve); pSystem.startSize *= (1 + comboMod / 10) * comboBonusScalar; yield return(new WaitForSeconds(yieldTime)); //Need to wait for the burst to fully stretch before we move it pSystem.GetComponent <ParticleZoom>().StartZoom(toAim); }
protected override void ReadFromImpl(object obj) { base.ReadFromImpl(obj); ParticleSystem.LimitVelocityOverLifetimeModule uo = (ParticleSystem.LimitVelocityOverLifetimeModule)obj; enabled = uo.enabled; limitX = uo.limitX; limitXMultiplier = uo.limitXMultiplier; limitY = uo.limitY; limitYMultiplier = uo.limitYMultiplier; limitZ = uo.limitZ; limitZMultiplier = uo.limitZMultiplier; limit = uo.limit; limitMultiplier = uo.limitMultiplier; dampen = uo.dampen; separateAxes = uo.separateAxes; space = uo.space; drag = uo.drag; dragMultiplier = uo.dragMultiplier; multiplyDragByParticleSize = uo.multiplyDragByParticleSize; multiplyDragByParticleVelocity = uo.multiplyDragByParticleVelocity; }
private void MapLimitVelocityOverLifetimeParameters(ParticleSystem pSystem, int i) { ParticleSystem.LimitVelocityOverLifetimeModule limitVelocityOverLifetimeModule = pSystem.limitVelocityOverLifetime; try { limitVelocityOverLifetimeModule.enabled = GetBoolParam(i, "limitVelocityOverLifetime_enabled"); } catch (NullReferenceException) { limitVelocityOverLifetimeModule.enabled = false; return; } limitVelocityOverLifetimeModule.space = (ParticleSystemSimulationSpace)GetIntParam(i, "limitVelocityOverLifetime_space"); limitVelocityOverLifetimeModule.separateAxes = GetBoolParam(i, "limitVelocityOverLifetime_separateAxes"); limitVelocityOverLifetimeModule.multiplyDragByParticleSize = GetBoolParam(i, "limitVelocityOverLifetime_multiplyDragBySize"); limitVelocityOverLifetimeModule.multiplyDragByParticleVelocity = GetBoolParam(i, "limitVelocityOverLifetime_multiplyDragByVelocity"); limitVelocityOverLifetimeModule.dampen = GetFloatParam(i, "limitVelocityOverLifetime_dampen"); limitVelocityOverLifetimeModule.limit = NodeFXUtilities.InterpretStringToCurve(GetStringParam(i, "limitVelocityOverLifetime_speed")); limitVelocityOverLifetimeModule.drag = NodeFXUtilities.InterpretStringToCurve(GetStringParam(i, "limitVelocityOverLifetime_drag")); return; }
static void WriteParticleSystemLimitVelocityOverLifetime(ParticleSystem.LimitVelocityOverLifetimeModule module) { m_writer.Write(module.enabled); if (!module.enabled) { return; } m_writer.Write(module.separateAxes); if (module.separateAxes) { WriteMinMaxCurve(module.limitX); WriteMinMaxCurve(module.limitY); WriteMinMaxCurve(module.limitZ); m_writer.Write((int)module.space); } else { WriteMinMaxCurve(module.limit); } m_writer.Write(module.dampen); }
protected override object WriteToImpl(object obj) { obj = base.WriteToImpl(obj); ParticleSystem.LimitVelocityOverLifetimeModule uo = (ParticleSystem.LimitVelocityOverLifetimeModule)obj; uo.enabled = enabled; uo.limitX = limitX; uo.limitXMultiplier = limitXMultiplier; uo.limitY = limitY; uo.limitYMultiplier = limitYMultiplier; uo.limitZ = limitZ; uo.limitZMultiplier = limitZMultiplier; uo.limit = limit; uo.limitMultiplier = limitMultiplier; uo.dampen = dampen; uo.separateAxes = separateAxes; uo.space = space; uo.drag = drag; uo.dragMultiplier = dragMultiplier; uo.multiplyDragByParticleSize = multiplyDragByParticleSize; uo.multiplyDragByParticleVelocity = multiplyDragByParticleVelocity; return(uo); }
public void OnEvent(FCEvent fcEvent, GameObject gameObject) { if (fcEvent == FCEvent.END) { Transform lowest = GetLowestChildTransform(gameObject.transform); Material material = lowest.GetComponent <Renderer> ().material; Color materialColor = material.color; Texture2D albedoTexture = (Texture2D)material.mainTexture; if (albedoTexture != null) { materialColor = albedoTexture.GetPixel(20, 20); } Gradient gradient = new Gradient(); GradientColorKey[] colorKeys = new GradientColorKey[] { new GradientColorKey(materialColor, 0.0f), new GradientColorKey(materialColor, 1.0f) }; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) }; gradient.SetKeys(colorKeys, alphaKeys); ParticleSystem.ColorOverLifetimeModule colorOverLifetime = ps.colorOverLifetime; //will not compile if using ps.colorOverLifetime.color = someColor directly colorOverLifetime.enabled = true; colorOverLifetime.color = gradient; ParticleSystem.LimitVelocityOverLifetimeModule limitVelocityOverLifetime = ps.limitVelocityOverLifetime; limitVelocityOverLifetime.dampen = 1 - 1f * gameObject.transform.childCount / maxChips; ps.transform.position = new Vector3(lowest.position.x, lowest.position.y - 0.1f, lowest.position.z); ps.Play(); ps.Emit(Mathf.Min(gameObject.transform.childCount * particlesPerChip, maxParticles)); } }
private void SetupFlameParticleSystem(ParticleSystem ps, Int32 skinIndex, FlamePSInfo psi) { ParticleSystem.MainModule main = ps.main; main.duration = 1f; main.loop = true; main.prewarm = false; main.startDelay = 0f; main.startLifetime = new ParticleSystem.MinMaxCurve { mode = ParticleSystemCurveMode.Constant, constant = 0.65f }; main.startSpeed = new ParticleSystem.MinMaxCurve { mode = ParticleSystemCurveMode.Constant, constant = psi.startSpeed }; main.startSize3D = false; main.startSize = new ParticleSystem.MinMaxCurve { mode = ParticleSystemCurveMode.Constant, constant = psi.startSize * 0.75f }; main.startRotation3D = false; main.startRotation = new ParticleSystem.MinMaxCurve { mode = ParticleSystemCurveMode.TwoConstants, constantMin = 0f, constantMax = 360f }; main.flipRotation = 0f; main.startColor = new ParticleSystem.MinMaxGradient { mode = ParticleSystemGradientMode.Color, color = new Color(1f, 1f, 1f, 1f) }; main.gravityModifier = new ParticleSystem.MinMaxCurve { mode = ParticleSystemCurveMode.Constant, constant = psi.gravity }; main.simulationSpace = ParticleSystemSimulationSpace.Local; main.simulationSpeed = 1f; main.useUnscaledTime = false; main.scalingMode = ParticleSystemScalingMode.Local; main.playOnAwake = true; main.emitterVelocityMode = ParticleSystemEmitterVelocityMode.Transform; main.maxParticles = 1000; main.stopAction = ParticleSystemStopAction.None; main.cullingMode = ParticleSystemCullingMode.AlwaysSimulate; main.ringBufferMode = ParticleSystemRingBufferMode.Disabled; ParticleSystem.EmissionModule emission = ps.emission; emission.enabled = true; emission.rateOverTime = new ParticleSystem.MinMaxCurve { mode = ParticleSystemCurveMode.Constant, constant = 10f }; emission.rateOverDistance = new ParticleSystem.MinMaxCurve { mode = ParticleSystemCurveMode.Constant, constant = 0f }; emission.rateOverDistanceMultiplier = 0f; emission.rateOverTimeMultiplier = psi.rate; ParticleSystem.ShapeModule shape = ps.shape; shape.enabled = true; shape.shapeType = ParticleSystemShapeType.Cone; shape.angle = 38.26f; shape.radius = psi.radius * 0.75f; shape.radiusThickness = 1f; shape.arc = 360f; shape.arcMode = ParticleSystemShapeMultiModeValue.Random; shape.arcSpread = 0f; shape.position = psi.position; shape.rotation = psi.rotation; shape.scale = psi.scale; shape.alignToDirection = false; ParticleSystem.VelocityOverLifetimeModule velOverLife = ps.velocityOverLifetime; velOverLife.enabled = false; ParticleSystem.LimitVelocityOverLifetimeModule limVelOverLife = ps.limitVelocityOverLifetime; limVelOverLife.enabled = false; ParticleSystem.InheritVelocityModule inheritVel = ps.inheritVelocity; inheritVel.enabled = false; ParticleSystem.ForceOverLifetimeModule forceOverLife = ps.forceOverLifetime; forceOverLife.enabled = false; ParticleSystem.ColorOverLifetimeModule colorOverLife = ps.colorOverLifetime; colorOverLife.enabled = true; colorOverLife.color = new ParticleSystem.MinMaxGradient { mode = ParticleSystemGradientMode.Gradient, gradient = new Gradient { mode = GradientMode.Blend, colorKeys = new GradientColorKey[1] { new GradientColorKey(new Color(1f, 1f, 1f), 0f) }, alphaKeys = new GradientAlphaKey[4] { new GradientAlphaKey(0f, 0f), new GradientAlphaKey(0.9f, 0.1f), new GradientAlphaKey(0.6f, 0.6f), new GradientAlphaKey(0f, 1f) } } }; ParticleSystem.ColorBySpeedModule colorBySpeed = ps.colorBySpeed; colorBySpeed.enabled = false; ParticleSystem.SizeOverLifetimeModule sizeOverLife = ps.sizeOverLifetime; sizeOverLife.enabled = true; sizeOverLife.size = new ParticleSystem.MinMaxCurve { mode = ParticleSystemCurveMode.Curve, curve = new AnimationCurve { postWrapMode = WrapMode.Clamp, preWrapMode = WrapMode.Clamp, keys = new Keyframe[3] { new Keyframe(0f, 0.2f), new Keyframe(0.47f, 0.71f), new Keyframe(1f, 0.025f) } } }; sizeOverLife.sizeMultiplier = 1f; ParticleSystem.SizeBySpeedModule sizeBySpeed = ps.sizeBySpeed; sizeBySpeed.enabled = false; ParticleSystem.RotationOverLifetimeModule rotOverLife = ps.rotationOverLifetime; rotOverLife.enabled = true; rotOverLife.separateAxes = false; rotOverLife.z = new ParticleSystem.MinMaxCurve { mode = ParticleSystemCurveMode.Constant, constant = 3f }; ParticleSystem.RotationBySpeedModule rotBySpeed = ps.rotationBySpeed; rotBySpeed.enabled = false; ParticleSystem.ExternalForcesModule extForce = ps.externalForces; extForce.enabled = false; ParticleSystem.NoiseModule noise = ps.noise; noise.enabled = false; ParticleSystem.CollisionModule col = ps.collision; col.enabled = false; ParticleSystem.TriggerModule trig = ps.trigger; trig.enabled = false; ParticleSystem.SubEmittersModule subEmit = ps.subEmitters; subEmit.enabled = false; ParticleSystem.TextureSheetAnimationModule texSheet = ps.textureSheetAnimation; texSheet.enabled = false; ParticleSystem.LightsModule light = ps.lights; light.enabled = false; ParticleSystem.TrailModule trails = ps.trails; trails.enabled = false; ParticleSystem.CustomDataModule custData = ps.customData; custData.enabled = false; }
public static void CreateEffect(Vector3 pos, float dist) { try { ParticleSystem ps = new GameObject().AddComponent <ParticleSystem>(); ps.transform.position = pos; ps.transform.rotation = Quaternion.Euler(-90, 0, 0); ps.gameObject.AddComponent <SnapFreeze>(); //hitParticleSystem = ps; ParticleSystem.MainModule main = ps.main; ParticleSystem.EmissionModule emission = ps.emission; ParticleSystem.ShapeModule shape = ps.shape; ParticleSystem.ColorOverLifetimeModule color = ps.colorOverLifetime; ParticleSystem.LimitVelocityOverLifetimeModule limit = ps.limitVelocityOverLifetime; ParticleSystemRenderer rend = ps.GetComponent <ParticleSystemRenderer>(); main.startSize = 0.4f; main.startSpeed = new ParticleSystem.MinMaxCurve(dist, dist * 2); main.duration = 0.52f; main.startLifetime = 1.5f; main.startColor = new ParticleSystem.MinMaxGradient(new Color(0.22f, 0.43f, 0.71f, 0.4f)); main.startRotation = 0; main.loop = false; emission.rateOverTime = 500; shape.shapeType = ParticleSystemShapeType.Circle; shape.radius = 0.001f; shape.arc = 360; shape.arcMode = ParticleSystemShapeMultiModeValue.Random; //shape.arcSpeed = 2; limit.enabled = true; limit.limit = 0; limit.dampen = 0.14f; color.enabled = true; color.color = new ParticleSystem.MinMaxGradient(new Color(1, 1, 1, 1), new Color(1, 1, 1, 0)); rend.renderMode = ParticleSystemRenderMode.Stretch; rend.lengthScale = 1.3f; rend.velocityScale = 0.84f; rend.normalDirection = 1; Material mat1 = new Material(Shader.Find("Particles/Additive")) { mainTexture = Res.ResourceLoader.GetTexture(128) }; rend.material = mat1; ps.Play(); } catch (Exception e) { ModAPI.Console.Write(e.ToString()); } RaycastHit[] hits = Physics.SphereCastAll(pos, dist, Vector3.one); for (int i = 0; i < hits.Length; i++) { if (hits[i].transform.CompareTag("enemyCollide")) { CreateHitEffect(hits[i].point); } } }
internal ParticleElementTemplate(ParticleElement element) { this.element = element; this.partSys = element.partSys; this.partRend = element.partRend; this.main = this.partSys.main; this.collision = this.partSys.collision; this.collision.enabled = false; this.colorBySpeed = this.partSys.colorBySpeed; this.colorBySpeed.enabled = false; this.colorOverLifetime = this.partSys.colorOverLifetime; this.colorOverLifetime.enabled = false; this.customData = this.partSys.customData; this.customData.enabled = false; this.emission = this.partSys.emission; this.emission.enabled = false; this.externalForces = this.partSys.externalForces; this.externalForces.enabled = false; this.forceOverLifetime = this.partSys.forceOverLifetime; this.forceOverLifetime.enabled = false; this.inheritVelocity = this.partSys.inheritVelocity; this.inheritVelocity.enabled = false; this.lights = this.partSys.lights; this.lights.enabled = false; this.limitVelocityOverLifetime = this.partSys.limitVelocityOverLifetime; this.limitVelocityOverLifetime.enabled = false; this.noise = this.partSys.noise; this.noise.enabled = false; this.rotationBySpeed = this.partSys.rotationBySpeed; this.rotationBySpeed.enabled = false; this.rotationOverLifetime = this.partSys.rotationOverLifetime; this.rotationOverLifetime.enabled = false; this.shape = this.partSys.shape; this.shape.enabled = false; this.sizeBySpeed = this.partSys.sizeBySpeed; this.sizeBySpeed.enabled = false; this.sizeOverLifetime = this.partSys.sizeOverLifetime; this.sizeOverLifetime.enabled = false; this.subEmitters = this.partSys.subEmitters; this.subEmitters.enabled = false; this.textureSheetAnimation = this.partSys.textureSheetAnimation; this.textureSheetAnimation.enabled = false; this.trails = this.partSys.trails; this.trails.enabled = false; this.trigger = this.partSys.trigger; this.trigger.enabled = false; this.velocityOverLifetime = this.partSys.velocityOverLifetime; this.velocityOverLifetime.enabled = false; }
internal static GameObject CreatePlasmaBurnPrefab() { var obj = PrefabsCore.CreatePrefab("PlasmaBurn", false); var holder = new GameObject("Particles"); holder.transform.parent = obj.transform; var mainPs = holder.AddComponent <ParticleSystem>(); var mainPsr = holder.AddOrGetComponent <ParticleSystemRenderer>(); mainPs .BurnMain() .BurnEmission() .BurnShape() .BurnCOL() .BurnSOL(); mainPsr .BurnRenderer(); ParticleSystem.VelocityOverLifetimeModule mainPsVol = mainPs.velocityOverLifetime; mainPsVol.enabled = false; ParticleSystem.LimitVelocityOverLifetimeModule mainPsLvol = mainPs.limitVelocityOverLifetime; mainPsLvol.enabled = false; ParticleSystem.InheritVelocityModule mainPsIvel = mainPs.inheritVelocity; mainPsIvel.enabled = false; ParticleSystem.ForceOverLifetimeModule mainPsFol = mainPs.forceOverLifetime; mainPsFol.enabled = false; ParticleSystem.ColorBySpeedModule mainPsCbs = mainPs.colorBySpeed; mainPsCbs.enabled = false; ParticleSystem.SizeBySpeedModule mainPsSbs = mainPs.sizeBySpeed; mainPsSbs.enabled = false; ParticleSystem.RotationOverLifetimeModule mainPsRol = mainPs.rotationOverLifetime; mainPsRol.enabled = false; ParticleSystem.RotationBySpeedModule mainPsRbs = mainPs.rotationBySpeed; mainPsRbs.enabled = false; ParticleSystem.ExternalForcesModule mainPsExt = mainPs.externalForces; mainPsExt.enabled = false; ParticleSystem.NoiseModule mainPsNoise = mainPs.noise; mainPsNoise.enabled = false; ParticleSystem.CollisionModule mainPsColl = mainPs.collision; mainPsColl.enabled = false; ParticleSystem.TriggerModule mainPsTrig = mainPs.trigger; mainPsTrig.enabled = false; ParticleSystem.SubEmittersModule mainPsSub = mainPs.subEmitters; mainPsSub.enabled = false; ParticleSystem.TextureSheetAnimationModule mainPsTex = mainPs.textureSheetAnimation; mainPsTex.enabled = false; ParticleSystem.LightsModule mainPsLigh = mainPs.lights; mainPsLigh.enabled = false; ParticleSystem.TrailModule mainPsTrail = mainPs.trails; mainPsTrail.enabled = false; ParticleSystem.CustomDataModule mainPsData = mainPs.customData; mainPsData.enabled = false; return(obj); }
public void Awake() { _particleSystem = (gameObject.AddComponent <ParticleSystem>()) as ParticleSystem; if (gameObject.GetComponent <ParticleSystemRenderer>()) { _psRenderer = gameObject.GetComponent <ParticleSystemRenderer>(); } else { _psRenderer = (gameObject.AddComponent <ParticleSystemRenderer>()) as ParticleSystemRenderer; } _psEmitParams = new ParticleSystem.EmitParams(); _psEmission = _particleSystem.emission; _psMain = _particleSystem.main; _psVelocityOverLifetime = _particleSystem.limitVelocityOverLifetime; _psSizeOverLifetime = _particleSystem.sizeOverLifetime; _psColorOverLifetime = _particleSystem.colorOverLifetime; _psShape = _particleSystem.shape; _psMain.loop = false; _psMain.startSpeed = 0f; _psMain.flipRotation = .5f; _psEmission.rateOverTime = 0; _psEmission.SetBursts(new ParticleSystem.Burst[] { new ParticleSystem.Burst(0.0f, 1, 1) }); _psVelocityOverLifetime.enabled = true; _psVelocityOverLifetime.separateAxes = true; _psVelocityOverLifetime.limitX = .1f; _psVelocityOverLifetime.limitY = .1f; _psVelocityOverLifetime.limitZ = .1f; _psVelocityOverLifetime.space = ParticleSystemSimulationSpace.World; _psShape.enabled = true; _psShape.shapeType = ParticleSystemShapeType.Sphere; _psShape.radius = 0.1f; _psRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On; _psRenderer.receiveShadows = true; //Just to start and make sure there is no interference _psEmission.enabled = false; _particleSystem.hideFlags = HideFlags.HideAndDontSave; _psVelocityOverLifetime.dampen = _baseDamping; _psRenderer.maxParticleSize = maxScreenSize; _psRenderer.material = material; _psRenderer.material.color = Color.white; //Defaulting to a linear curve if (!useExplicitSizeCurve) { SizeOverLifetimeCurve.AddKey(0.0f, 0.1f); SizeOverLifetimeCurve.AddKey(1.0f, 1.0f); } _psSoLMMCurve = new ParticleSystem.MinMaxCurve(2, SizeOverLifetimeCurve); _psSizeOverLifetime.size = _psSoLMMCurve; if (explodeOnAwake) { Explode(); } }
private static void BasicSetup(ParticleSystem ps) { ParticleSystem.EmissionModule ps1Emission = ps.emission; ps1Emission.enabled = false; ParticleSystem.ShapeModule ps1Shape = ps.shape; ps1Shape.enabled = false; ParticleSystem.VelocityOverLifetimeModule ps1VOL = ps.velocityOverLifetime; ps1VOL.enabled = false; ParticleSystem.LimitVelocityOverLifetimeModule ps1LimVOL = ps.limitVelocityOverLifetime; ps1LimVOL.enabled = false; ParticleSystem.InheritVelocityModule ps1InhVel = ps.inheritVelocity; ps1InhVel.enabled = false; ParticleSystem.ForceOverLifetimeModule ps1FOL = ps.forceOverLifetime; ps1FOL.enabled = false; ParticleSystem.ColorOverLifetimeModule ps1COL = ps.colorOverLifetime; ps1COL.enabled = false; ParticleSystem.ColorBySpeedModule ps1CBS = ps.colorBySpeed; ps1CBS.enabled = false; ParticleSystem.SizeOverLifetimeModule ps1SOL = ps.sizeOverLifetime; ps1SOL.enabled = false; ParticleSystem.SizeBySpeedModule ps1SBS = ps.sizeBySpeed; ps1SBS.enabled = false; ParticleSystem.RotationOverLifetimeModule ps1ROL = ps.rotationOverLifetime; ps1ROL.enabled = false; ParticleSystem.RotationBySpeedModule ps1RBS = ps.rotationBySpeed; ps1RBS.enabled = false; ParticleSystem.ExternalForcesModule ps1ExtFor = ps.externalForces; ps1ExtFor.enabled = false; ParticleSystem.NoiseModule ps1Noise = ps.noise; ps1Noise.enabled = false; ParticleSystem.CollisionModule ps1Collis = ps.collision; ps1Collis.enabled = false; ParticleSystem.TriggerModule ps1Trig = ps.trigger; ps1Trig.enabled = false; ParticleSystem.SubEmittersModule ps1SubEmit = ps.subEmitters; ps1SubEmit.enabled = false; ParticleSystem.TextureSheetAnimationModule ps1TexAnim = ps.textureSheetAnimation; ps1TexAnim.enabled = false; ParticleSystem.LightsModule ps1Light = ps.lights; ps1Light.enabled = false; ParticleSystem.TrailModule ps1Trails = ps.trails; ps1Trails.enabled = false; ParticleSystem.CustomDataModule ps1Cust = ps.customData; ps1Cust.enabled = false; }
public void Scale(ParticleSystem particleSystem, float scale) { if (particleSystem == null) { return; } particleSystem.transform.localPosition *= scale; // Particle system. ParticleSystem.MainModule main = particleSystem.main; ParticleSystem.ShapeModule shape = particleSystem.shape; ParticleSystem.VelocityOverLifetimeModule velocityOverLifetime = particleSystem.velocityOverLifetime; ParticleSystem.LimitVelocityOverLifetimeModule limitVelocityOverLifetime = particleSystem.limitVelocityOverLifetime; ParticleSystem.ForceOverLifetimeModule forceOverLifetime = particleSystem.forceOverLifetime; ParticleSystem.MinMaxCurve mmCurve; // Main. mmCurve = main.startSpeed; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; main.startSpeed = mmCurve; mmCurve = main.startSize; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; main.startSize = mmCurve; // Shape. shape.radius *= scale; shape.scale *= scale; shape.angle *= scale; shape.randomDirectionAmount *= scale; shape.sphericalDirectionAmount *= scale; shape.meshScale *= scale; shape.normalOffset *= scale; // Velocity over lifetime. mmCurve = velocityOverLifetime.x; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; velocityOverLifetime.x = mmCurve; mmCurve = velocityOverLifetime.y; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; velocityOverLifetime.y = mmCurve; mmCurve = velocityOverLifetime.z; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; velocityOverLifetime.z = mmCurve; // Force over lifetime. mmCurve = forceOverLifetime.x; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; forceOverLifetime.x = mmCurve; mmCurve = forceOverLifetime.y; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; forceOverLifetime.y = mmCurve; mmCurve = forceOverLifetime.z; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; forceOverLifetime.z = mmCurve; #if UNITY_EDITOR EditorUtility.SetDirty(particleSystem); #endif }
//Scale individiual particle system values private void ScaleParticleValues(ParticleSystem ps) { //BASE MODULE var main = ps.main; //StartSize ParticleSystem.MinMaxCurve sSize = main.startSize; main.startSize = MultiplyMinMaxCurve(sSize, scale); //Gravity ParticleSystem.MinMaxCurve sGrav = main.gravityModifier; main.gravityModifier = MultiplyMinMaxCurve(sGrav, scale); //StartSpeed ParticleSystem.MinMaxCurve sSpeed = main.startSpeed; main.startSpeed = MultiplyMinMaxCurve(sSpeed, scale); //MODULES //Shape (divided instead of multiplied) var shape = ps.shape; if (shape.enabled) { shape.radius /= scale; shape.scale = shape.scale / scale; } //Emisison Rate Time (divided instead of multiplied) ParticleSystem.EmissionModule em = ps.emission; if (em.enabled) { //Time ParticleSystem.MinMaxCurve emRateT = em.rateOverTime; em.rateOverTime = MultiplyMinMaxCurve(emRateT, scale, false); //Distance ParticleSystem.MinMaxCurve emRateD = em.rateOverDistance; em.rateOverDistance = MultiplyMinMaxCurve(emRateD, scale, false); } //Velocities ParticleSystem.VelocityOverLifetimeModule vel = ps.velocityOverLifetime; if (vel.enabled) { vel.x = MultiplyMinMaxCurve(vel.x, scale); vel.y = MultiplyMinMaxCurve(vel.y, scale); vel.z = MultiplyMinMaxCurve(vel.z, scale); } //ClampVelocities ParticleSystem.LimitVelocityOverLifetimeModule clampVel = ps.limitVelocityOverLifetime; if (clampVel.enabled) { clampVel.limitX = MultiplyMinMaxCurve(clampVel.limitX, scale); clampVel.limitY = MultiplyMinMaxCurve(clampVel.limitY, scale); clampVel.limitZ = MultiplyMinMaxCurve(clampVel.limitZ, scale); } //Forces ParticleSystem.ForceOverLifetimeModule force = ps.forceOverLifetime; if (force.enabled) { force.x = MultiplyMinMaxCurve(force.x, scale); force.y = MultiplyMinMaxCurve(force.y, scale); force.z = MultiplyMinMaxCurve(force.z, scale); } }
internal static GameObject CreateSmallAmmoTracer(Material mainMat, Material trailMat) { GameObject obj = PrefabsCore.CreatePrefab("Standard Tracer", false); Transform tracerHead = new GameObject("TracerHead").transform; tracerHead.parent = obj.transform; tracerHead.localPosition = Vector3.zero; tracerHead.localRotation = Quaternion.identity; //tracerHead.localEulerAngles = new Vector3( 0f, 90f, 0f ); tracerHead.localScale = Vector3.one; Transform tracerTail = new GameObject("TracerTail").transform; tracerTail.parent = obj.transform; tracerTail.localPosition = Vector3.zero; tracerTail.localRotation = Quaternion.identity; tracerTail.localScale = Vector3.one; Transform trail = new GameObject("trail").transform; trail.parent = tracerTail; trail.localPosition = Vector3.zero; trail.localRotation = Quaternion.identity; trail.localScale = Vector3.one; Transform headBeam = new GameObject("HeadBeam").transform; headBeam.parent = tracerTail; headBeam.localPosition = Vector3.zero; headBeam.localEulerAngles = new Vector3(0f, 90f, 0f); headBeam.localScale = Vector3.one; EffectComponent effectComp = obj.AddComponent <EffectComponent>(); Tracer tracer = obj.AddComponent <Tracer>(); VFXAttributes vfxAtrib = obj.AddComponent <VFXAttributes>(); Rigidbody headRb = tracerHead.AddComponent <Rigidbody>(); Rigidbody tailRb = tracerTail.AddComponent <Rigidbody>(); ParticleSystem mainPs = headBeam.AddComponent <ParticleSystem>(); ParticleSystemRenderer mainPsr = headBeam.AddOrGetComponent <ParticleSystemRenderer>(); ParticleSystem trailPs = trail.AddComponent <ParticleSystem>(); ParticleSystemRenderer trailPsr = trail.AddOrGetComponent <ParticleSystemRenderer>(); DestroyTracerOnDelay cleanup = obj.AddComponent <DestroyTracerOnDelay>(); cleanup.delay = 2f; cleanup.tracer = tracer; ZeroTracerLengthOverDuration zeroLength = obj.AddComponent <ZeroTracerLengthOverDuration>(); zeroLength.tracer = tracer; DestroyOnTimer timer = obj.AddComponent <DestroyOnTimer>(); timer.duration = 10f; effectComp.effectIndex = EffectIndex.Invalid; effectComp.positionAtReferencedTransform = false; effectComp.parentToReferencedTransform = false; effectComp.applyScale = false; effectComp.soundName = null; effectComp.disregardZScale = false; tracer.startTransform = null; tracer.beamObject = null; tracer.beamDensity = 0f; tracer.speed = 600f; tracer.headTransform = tracerHead; tracer.tailTransform = tracerTail; tracer.length = 20f; tracer.reverse = false; headRb.isKinematic = true; headRb.useGravity = false; tailRb.isKinematic = true; tailRb.useGravity = false; vfxAtrib.optionalLights = null; vfxAtrib.secondaryParticleSystem = null; vfxAtrib.vfxIntensity = VFXAttributes.VFXIntensity.Low; vfxAtrib.vfxPriority = VFXAttributes.VFXPriority.Always; mainPs.PlayOnStart(); mainPs.SetupSmallTracerMain(); mainPs.SetupSmallTracerEmission(); mainPs.SetupSmallTracerShape(); mainPs.SetupSmallTracerColorOverLifetime(); mainPs.SetupSmallTracerSizeOverLifetime(); mainPsr.SetupSmallTracerRenderer(mainMat); ParticleSystem.VelocityOverLifetimeModule mainPsVol = mainPs.velocityOverLifetime; mainPsVol.enabled = false; ParticleSystem.LimitVelocityOverLifetimeModule mainPsLvol = mainPs.limitVelocityOverLifetime; mainPsLvol.enabled = false; ParticleSystem.InheritVelocityModule mainPsIvel = mainPs.inheritVelocity; mainPsIvel.enabled = false; ParticleSystem.ForceOverLifetimeModule mainPsFol = mainPs.forceOverLifetime; mainPsFol.enabled = false; ParticleSystem.ColorBySpeedModule mainPsCbs = mainPs.colorBySpeed; mainPsCbs.enabled = false; ParticleSystem.SizeBySpeedModule mainPsSbs = mainPs.sizeBySpeed; mainPsSbs.enabled = false; ParticleSystem.RotationOverLifetimeModule mainPsRol = mainPs.rotationOverLifetime; mainPsRol.enabled = false; ParticleSystem.RotationBySpeedModule mainPsRbs = mainPs.rotationBySpeed; mainPsRbs.enabled = false; ParticleSystem.ExternalForcesModule mainPsExt = mainPs.externalForces; mainPsExt.enabled = false; ParticleSystem.NoiseModule mainPsNoise = mainPs.noise; mainPsNoise.enabled = false; ParticleSystem.CollisionModule mainPsColl = mainPs.collision; mainPsColl.enabled = false; ParticleSystem.TriggerModule mainPsTrig = mainPs.trigger; mainPsTrig.enabled = false; ParticleSystem.SubEmittersModule mainPsSub = mainPs.subEmitters; mainPsSub.enabled = false; ParticleSystem.TextureSheetAnimationModule mainPsTex = mainPs.textureSheetAnimation; mainPsTex.enabled = false; ParticleSystem.LightsModule mainPsLight = mainPs.lights; mainPsLight.enabled = false; ParticleSystem.TrailModule mainPsTrail = mainPs.trails; mainPsTrail.enabled = false; ParticleSystem.CustomDataModule mainPsData = mainPs.customData; mainPsData.enabled = false; trailPs.PlayOnStart(); trailPs.SetupSmallTracerTrailMain(); trailPs.SetupSmallTracerTrailEmission(); trailPs.SetupSmallTracerTrailNoise(); trailPs.SetupSmallTracerTrailTrail(); trailPsr.SetupSmallTracerTrailRenderer(trailMat); ParticleSystem.ShapeModule trailPsShape = trailPs.shape; trailPsShape.enabled = false; ParticleSystem.VelocityOverLifetimeModule trailPsVol = trailPs.velocityOverLifetime; trailPsVol.enabled = false; ParticleSystem.LimitVelocityOverLifetimeModule trailPsLvol = trailPs.limitVelocityOverLifetime; trailPsLvol.enabled = false; ParticleSystem.InheritVelocityModule trailPsIvel = trailPs.inheritVelocity; trailPsIvel.enabled = false; ParticleSystem.ForceOverLifetimeModule trailPsFol = trailPs.forceOverLifetime; trailPsFol.enabled = false; ParticleSystem.ColorOverLifetimeModule trailPsCol = trailPs.colorOverLifetime; trailPsCol.enabled = false; ParticleSystem.ColorBySpeedModule trailPsCbs = trailPs.colorBySpeed; trailPsCbs.enabled = false; ParticleSystem.SizeOverLifetimeModule trailPsSol = trailPs.sizeOverLifetime; trailPsSol.enabled = false; ParticleSystem.SizeBySpeedModule trailPsSbs = trailPs.sizeBySpeed; trailPsSbs.enabled = false; ParticleSystem.RotationOverLifetimeModule trailPsRol = trailPs.rotationOverLifetime; trailPsRol.enabled = false; ParticleSystem.RotationBySpeedModule trailPsRbs = trailPs.rotationBySpeed; trailPsRbs.enabled = false; ParticleSystem.ExternalForcesModule trailPsExt = trailPs.externalForces; trailPsExt.enabled = false; ParticleSystem.NoiseModule trailPsNoise = trailPs.noise; trailPsNoise.enabled = true; ParticleSystem.CollisionModule trailPsColl = trailPs.collision; trailPsColl.enabled = false; ParticleSystem.TriggerModule trailPsTrig = trailPs.trigger; trailPsTrig.enabled = false; ParticleSystem.SubEmittersModule trailPsSub = trailPs.subEmitters; trailPsSub.enabled = false; ParticleSystem.TextureSheetAnimationModule trailPsTex = trailPs.textureSheetAnimation; trailPsTex.enabled = false; ParticleSystem.LightsModule trailPsLigh = trailPs.lights; trailPsLigh.enabled = false; ParticleSystem.CustomDataModule trailPsData = trailPs.customData; trailPsData.enabled = false; return(obj); }
// ================================= // Nested classes and structures. // ================================= // ... // ================================= // Variables. // ================================= // ... // ================================= // Functions. // ================================= // Scales against self. public static void scale(this ParticleSystem particleSystem, float scale, bool scaleTransformLocalPosition) { // Transform. if (scaleTransformLocalPosition) { particleSystem.transform.localPosition *= scale; } // Particle system. ParticleSystem.MainModule main = particleSystem.main; ParticleSystem.ShapeModule shape = particleSystem.shape; ParticleSystem.VelocityOverLifetimeModule velocityOverLifetime = particleSystem.velocityOverLifetime; ParticleSystem.LimitVelocityOverLifetimeModule limitVelocityOverLifetime = particleSystem.limitVelocityOverLifetime; ParticleSystem.ForceOverLifetimeModule forceOverLifetime = particleSystem.forceOverLifetime; ParticleSystem.MinMaxCurve mmCurve; // Main. mmCurve = main.startSpeed; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; main.startSpeed = mmCurve; mmCurve = main.startSize; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; main.startSize = mmCurve; // Shape. shape.radius *= scale; shape.scale *= scale; shape.angle *= scale; shape.randomDirectionAmount *= scale; shape.sphericalDirectionAmount *= scale; shape.scale *= scale; shape.normalOffset *= scale; // Velocity over lifetime. mmCurve = velocityOverLifetime.x; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; velocityOverLifetime.x = mmCurve; mmCurve = velocityOverLifetime.y; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; velocityOverLifetime.y = mmCurve; mmCurve = velocityOverLifetime.z; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; velocityOverLifetime.z = mmCurve; // Force over lifetime. mmCurve = forceOverLifetime.x; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; forceOverLifetime.x = mmCurve; mmCurve = forceOverLifetime.y; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; forceOverLifetime.y = mmCurve; mmCurve = forceOverLifetime.z; mmCurve.constantMin *= scale; mmCurve.constantMax *= scale; forceOverLifetime.z = mmCurve; }
protected void InitializeParticleSystem(ParticleSystem ps, ParticleSystemRenderer renderer, int max_particles) { ParticleSystem.MainModule main = ps.main; main.loop = false; main.playOnAwake = false; main.maxParticles = max_particles; main.startColor = new ParticleSystem.MinMaxGradient(new Color(1.0f, 1.0f, 1.0f, 0.0f)); renderer.sortMode = ParticleSystemSortMode.Distance; renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; renderer.receiveShadows = false; renderer.enableGPUInstancing = true; Material particleMaterial = new Material(Shader.Find(shader)); renderer.material = particleMaterial; PrepareMaterial(particleMaterial); particleMaterial.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 1.0f)); particleMaterial.SetColor("_EmissionColor", new Color(0.8f, 0.8f, 0.8f, 1.0f)); ParticleSystem.EmissionModule em = ps.emission; em.enabled = false; ParticleSystem.ShapeModule sh = ps.shape; sh.enabled = false; ParticleSystem.VelocityOverLifetimeModule vol = ps.velocityOverLifetime; vol.enabled = false; ParticleSystem.LimitVelocityOverLifetimeModule lvol = ps.limitVelocityOverLifetime; lvol.enabled = false; ParticleSystem.InheritVelocityModule ivm = ps.inheritVelocity; ivm.enabled = false; ParticleSystem.ForceOverLifetimeModule fol = ps.forceOverLifetime; fol.enabled = false; ParticleSystem.ColorOverLifetimeModule col = ps.colorOverLifetime; col.enabled = false; ParticleSystem.ColorBySpeedModule cbs = ps.colorBySpeed; cbs.enabled = false; ParticleSystem.SizeOverLifetimeModule sol = ps.sizeOverLifetime; sol.enabled = false; ParticleSystem.SizeBySpeedModule sbs = ps.sizeBySpeed; sbs.enabled = false; ParticleSystem.RotationOverLifetimeModule rol = ps.rotationOverLifetime; rol.enabled = false; ParticleSystem.RotationBySpeedModule rbs = ps.rotationBySpeed; rbs.enabled = false; ParticleSystem.ExternalForcesModule extf = ps.externalForces; extf.enabled = false; ParticleSystem.NoiseModule noise = ps.noise; noise.enabled = false; ParticleSystem.CollisionModule collision = ps.collision; collision.enabled = false; ParticleSystem.TriggerModule triggers = ps.trigger; triggers.enabled = false; ParticleSystem.SubEmittersModule subem = ps.subEmitters; subem.enabled = false; ParticleSystem.TextureSheetAnimationModule tsa = ps.textureSheetAnimation; tsa.enabled = false; ParticleSystem.LightsModule lights = ps.lights; lights.enabled = false; ParticleSystem.CustomDataModule cd = ps.customData; cd.enabled = false; }
// Start is called before the first frame update void Start() { Debug.Log("Branches: " + header.numBranches); particleSystem = gameObject.AddComponent <ParticleSystem>(); particleRenderer = GetComponent <ParticleSystemRenderer>(); // Get and activate all the required modules mainModule = particleSystem.main; emissionModule = particleSystem.emission; emissionModule.enabled = true; shapeModule = particleSystem.shape; shapeModule.enabled = true; colorModule = particleSystem.colorOverLifetime; colorModule.enabled = true; sizeModule = particleSystem.sizeOverLifetime; sizeModule.enabled = true; texAnimModule = particleSystem.textureSheetAnimation; texAnimModule.enabled = true; velocityModule = particleSystem.velocityOverLifetime; velocityModule.enabled = true; collisionModule = particleSystem.collision; collisionModule.enabled = true; rotationModule = particleSystem.rotationOverLifetime; rotationModule.enabled = true; limitVelocityModule = particleSystem.limitVelocityOverLifetime; limitVelocityModule.enabled = true; // Set main parameters mainModule.gravityModifier = emitterParameters.gravity; mainModule.startSize = emitterParameters.sizeStart; mainModule.startLifetime = emitterParameters.lifeExp; // Set collision parameters collisionModule.bounce = emitterParameters.bounceCoefficient; // Set emission parameters emissionModule.rateOverTime = new ParticleSystem.MinMaxCurve(emitterParameters.birthRate); // Set size parameters // TODO: Use x, y values of size? // TODO: Use size mid sizeModule.size = new ParticleSystem.MinMaxCurve( emitterParameters.sizeStart / SIZE_FACTOR, emitterParameters.sizeEnd / SIZE_FACTOR ); sizeModule.x = new ParticleSystem.MinMaxCurve( emitterParameters.sizeStartX / SIZE_FACTOR, emitterParameters.sizeEnd / SIZE_FACTOR ); sizeModule.y = new ParticleSystem.MinMaxCurve( emitterParameters.sizeStartY > 0 ? emitterParameters.sizeStartY / SIZE_FACTOR : emitterParameters.sizeStartX / SIZE_FACTOR, emitterParameters.sizeEnd / SIZE_FACTOR ); // Set color parameters // TODO: Support colorMid too //colorModule.color = new ParticleSystem.MinMaxGradient( // new Color( // emitterParameters.colorStart.r, // emitterParameters.colorStart.g, // emitterParameters.colorStart.b, // emitterParameters.alphaStart // ), // new Color( // emitterParameters.colorEnd.r, // emitterParameters.colorEnd.g, // emitterParameters.colorEnd.b, // emitterParameters.alphaEnd // ) //); // Set texture sheet parameters texAnimModule.animation = ParticleSystemAnimationType.WholeSheet; //texAnimModule.cycleCount = 1; texAnimModule.fps = emitterParameters.fps; texAnimModule.numTilesX = 4; texAnimModule.numTilesY = 4; texAnimModule.startFrame = emitterParameters.frameStart; texAnimModule.timeMode = ParticleSystemAnimationTimeMode.FPS; // Velocity parameters velocityModule.speedModifier = emitterParameters.velocity; // Velocity limit parameters limitVelocityModule.drag = emitterParameters.drag; // Rotation over lifetime rotationModule.separateAxes = false; rotationModule.x = emitterParameters.particleRotation; // Particle system render options particleRenderer.minParticleSize = 0f; particleRenderer.maxParticleSize = 1f; particleRenderer.alignment = ParticleSystemRenderSpace.Facing; // Source: https://forum.unity.com/threads/change-standard-shader-render-mode-in-runtime.318815/ mat.SetInt("_Mode", 2); mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); mat.SetInt("_ZWrite", 0); mat.DisableKeyword("_ALPHATEST_ON"); mat.DisableKeyword("_ALPHABLEND_ON"); mat.EnableKeyword("_ALPHAPREMULTIPLY_ON"); mat.renderQueue = 3000; mat.SetFloat("_SoftParticlesEnabled", 1f); mat.SetFloat("_SoftParticlesNearFadeDistance", 5f); mat.SetFloat("_SoftParticlesFarFadeDistance", 1f); mat.SetFloat("_CameraFadingEnabled", 1f); mat.SetFloat("_CameraFarFadeDistance", 5f); mat.SetFloat("_CameraNearFadeDistance", 1f); mat.SetFloat("_FlipbookMode", 1f); particleRenderer.material = mat; switch (header.blend) { case "Normal": break; case "Punch-Through": Debug.Log("Punch-Through not yet supported"); break; case "Lighten": Debug.Log("Lighten not yet supported"); break; default: Debug.Log(header.blend + " blend type not yet supported"); break; } switch (header.render) { case "Normal": // Particles are billboards particleRenderer.renderMode = ParticleSystemRenderMode.VerticalBillboard; particleRenderer.alignment = ParticleSystemRenderSpace.Facing; break; case "Linked": // Particle "touch and are stretched where necessary to do so" Debug.LogWarning("Linked not yet supported"); break; case "Billboard to Local Z": // Particle faces the way they came out regardless of camera movement Debug.LogWarning("Billboard to Local Z not yet supported"); break; case "Billboard to World Z": // Particles face upwards particleRenderer.renderMode = ParticleSystemRenderMode.HorizontalBillboard; break; case "Aligned to World Z": Debug.LogWarning("Aligned to World Z not yet supported"); break; case "Aligned to Particle": // Particles are aligned at the angle they leave the emitter // Uses the deadspace parameter Debug.LogWarning("Aligned to Particle not yet supported"); break; case "Motion Blur": // Stretches the particles along the path of travel severely, // and overlaps them as well particleRenderer.renderMode = ParticleSystemRenderMode.Stretch; break; default: Debug.LogWarning("Did not recognize particle render mode " + header.render); break; } switch (header.update) { case "Fountain": shapeModule.angle = emitterParameters.spread; break; case "Single": break; case "Explosion": particleSystem.Stop(); break; case "Lightning": break; default: Debug.LogWarning("Emitter style " + header.style + " not found"); break; } }