public Condition() { expanded = true; parameter = ePARAMETER.None; trigger = eTRIGGER.Constant; tunings = new Condition.Tuning[XParticleLevel.QUALITY_COUNT]; for (var i = 0; i < XParticleLevel.QUALITY_COUNT; ++i) { tunings[i] = new Condition.Tuning(); } }
void Update() { if (_particleSystem == null) { return; } #if UNITY_EDITOR if (!Application.isPlaying) { _quality = XParticlePreview.Quality; this.GetComponent <Renderer>().enabled = (_quality != eQUALITY.Off) && IsQualitysEnabled[(int)_quality]; } else { _quality = GetQuality(); this.GetComponent <Renderer>().enabled = (_quality != eQUALITY.Off) && IsQualitysEnabled[(int)_quality]; } #endif bool allConstant = true; foreach (Condition condition in Conditions) { Condition.Tuning tuning = condition.tunings[(int)_quality]; if (condition.trigger == eTRIGGER.Constant || tuning.tuningType == eTUNING.Constant) { if (condition.parameter == ePARAMETER.StartingColor) { SetParameter(condition.parameter, tuning.constantColor); } else { SetParameter(condition.parameter, tuning.constant); } continue; } allConstant = false; // if height var triggerValue = 0.0f; switch (condition.trigger) { case (eTRIGGER.Height): triggerValue = this.transform.position.y; break; default: break; } float interpolateKey = 0.0f; //if curve switch (tuning.tuningType) { case (eTUNING.Curve): AnimationCurve curve = tuning.curve; interpolateKey = curve.Evaluate((triggerValue - tuning.minX) / (tuning.maxX - tuning.minX)); break; default: break; } switch (condition.parameter) { case (ePARAMETER.StartingColor): Color interpolatedColor = Color.Lerp(tuning.minColor, tuning.maxColor, interpolateKey); SetParameter(condition.parameter, interpolatedColor); break; default: float interpolatedFloat = interpolateKey * (tuning.maxY - tuning.minY) + tuning.minY; SetParameter(condition.parameter, interpolatedFloat); break; } } if (allConstant && Application.isPlaying) { this.enabled = false; } }
void Update() { if (_particleSystem == null) { return; } #if UNITY_EDITOR if (!Application.isPlaying) { quality = ParticlePalPreview.Quality; this.GetComponent <Renderer>().enabled = isEnabled[(int)quality]; } #endif UpdateVelocity(); bool allConstant = true; foreach (Condition condition in conditions) { Condition.Tuning tuning = condition.tunings[(int)quality]; if (condition.trigger == ParticleManager.TRIGGER.Constant || tuning.type == ParticleManager.TUNING.Constant) { //constant value for all qualities or this particular quality, early out if (condition.parameter == ParticleManager.PARAMETER.StartingColor) { SetParameter(condition.parameter, tuning.constantColor); } else { SetParameter(condition.parameter, tuning.constant); } continue; } allConstant = false; //find the trigger value to use in the tuning phase var triggerVal = 0.0f; switch (condition.trigger) { case (ParticleManager.TRIGGER.Height): triggerVal = this.transform.position.y; break; case (ParticleManager.TRIGGER.Velocity): triggerVal = velocity; break; default: #if UNITY_EDITOR EB.Debug.LogError("ParticlePal trigger {0} is not recognized", condition.trigger.ToString()); #endif break; } //find the interpolated key based of tuning type float interpolateKey = 0.0f; switch (tuning.type) { case (ParticleManager.TUNING.Linear): interpolateKey = Mathf.Clamp01((triggerVal - tuning.minX) / (tuning.maxX - tuning.minX)); break; case (ParticleManager.TUNING.Curve): AnimationCurve curve = tuning.curve; interpolateKey = curve.Evaluate((triggerVal - tuning.minX) / (tuning.maxX - tuning.minX)); break; default: #if UNITY_EDITOR EB.Debug.LogError("ParticlePal tuning {0} is not recognized", condition.tunings[(int)quality].ToString()); #endif break; } //interpolate the float or color switch (condition.parameter) { case (ParticleManager.PARAMETER.StartingColor): Color interpolatedColor = Color.Lerp(tuning.minColor, tuning.maxColor, interpolateKey); SetParameter(condition.parameter, interpolatedColor); break; default: float iterpolatedFloat = interpolateKey * (tuning.maxY - tuning.minY) + tuning.minY; SetParameter(condition.parameter, iterpolatedFloat); break; } } if (allConstant && Application.isPlaying) { //in game, disable the particle pal script, as we have completed an update and set all the constants this.enabled = false; } }