You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

135 lines
5.5 KiB

using System.Collections;
using UnityEngine;
public class ParticleTrailController : MonoBehaviour
{
private Vector3 endPosition;
public void Initialize(ParticleSystem effect, ParticleTrail type, Vector3 end, int interval)
{
endPosition = end;
var main = effect.main;
var shape = effect.shape;
var emission = effect.emission;
emission.rateOverDistance = 1.0f / interval;
switch (type)
{
case ParticleTrail.Rocket:
{
main.startLifetime = new ParticleSystem.MinMaxCurve(0.6f, 1.2f);
shape.scale = new Vector3(6f, 6f, 6f);
var colorOverLifetime = effect.colorOverLifetime;
colorOverLifetime.enabled = true;
colorOverLifetime.color = SetupGradients(RocketColorKeys, SmokeColorKeys);
break;
}
case ParticleTrail.Smoke:
{
main.startLifetime = new ParticleSystem.MinMaxCurve(0.2f, 0.8f);
shape.scale = new Vector3(6f, 6f, 6f);
var colorOverLifetime = effect.colorOverLifetime;
colorOverLifetime.enabled = true;
colorOverLifetime.color = SetupGradients(SmokeColorKeys, SmokeColorKeys2);
break;
}
case ParticleTrail.Blood:
{
main.gravityModifierMultiplier = 0.05f;
main.startColor = new ParticleSystem.MinMaxGradient(BloodColorMin, BloodColorMax);
shape.scale = new Vector3(6f, 6f, 6f);
break;
}
case ParticleTrail.Tracer:
case ParticleTrail.Tracer2:
{
main.startLifetime = 0.5f;
main.startColor = type == ParticleTrail.Tracer
? new ParticleSystem.MinMaxGradient(TracerColorMin, TracerColorMax)
: new ParticleSystem.MinMaxGradient(Tracer2ColorMin, Tracer2ColorMax);
var velocityOverLifetime = effect.velocityOverLifetime;
velocityOverLifetime.enabled = true;
velocityOverLifetime.radial = new ParticleSystem.MinMaxCurve(-30, 30);
break;
}
case ParticleTrail.SlightBlood:
{
main.gravityModifierMultiplier = 0.05f;
main.startColor = new ParticleSystem.MinMaxGradient(BloodColorMin, BloodColorMax);
shape.scale = new Vector3(6f, 6f, 6f);
emission.rateOverDistance = 1.0f / (interval + 3);
break;
}
case ParticleTrail.VoreBall:
{
main.startLifetime = 0.3f;
main.startColor = new ParticleSystem.MinMaxGradient(VoreColorMin, VoreColorMax);
shape.scale = new Vector3(16f, 16f, 16f);
break;
}
}
}
IEnumerator Start()
{
// Instantly move the particle emitter to its end position, to force it to emit all particles at once
yield return null;
transform.position = endPosition;
}
private static ParticleSystem.MinMaxGradient SetupGradients(GradientColorKey[] minKeys, GradientColorKey[] maxKeys)
{
return new ParticleSystem.MinMaxGradient
{
mode = ParticleSystemGradientMode.TwoGradients,
gradientMin = new Gradient { mode = GradientMode.Fixed, colorKeys = minKeys },
gradientMax = new Gradient { mode = GradientMode.Fixed, colorKeys = maxKeys },
};
}
// TODO: these colors ought to be initialized from the Quake palette instead of being hard-coded.
// That will allow them to work with custom palettes from total conversions.
private static readonly GradientColorKey[] RocketColorKeys =
{
new GradientColorKey(new Color32(223, 171, 39, 255), 0.167f),
new GradientColorKey(new Color32(191, 119, 47, 255), 0.333f),
new GradientColorKey(new Color32(91, 91, 91, 255), 0.5f),
new GradientColorKey(new Color32(75, 75, 75, 255), 0.667f),
new GradientColorKey(new Color32(63, 63, 63, 255), 0.833f),
new GradientColorKey(new Color32(47, 47, 47, 255), 1.0f),
};
private static readonly GradientColorKey[] SmokeColorKeys =
{
new GradientColorKey(new Color32(91, 91, 91, 255), 0.25f),
new GradientColorKey(new Color32(75, 75, 75, 255), 0.5f),
new GradientColorKey(new Color32(63, 63, 63, 255), 0.75f),
new GradientColorKey(new Color32(47, 47, 47, 255), 1.0f),
};
private static readonly GradientColorKey[] SmokeColorKeys2 =
{
new GradientColorKey(new Color32(63, 63, 63, 255), 0.5f),
new GradientColorKey(new Color32(47, 47, 47, 255), 1.0f),
};
private static readonly Color BloodColorMin = new Color32(31, 0, 0, 255);
private static readonly Color BloodColorMax = new Color32(55, 0, 0, 255);
private static readonly Color TracerColorMin = new Color32(27, 27, 0, 255);
private static readonly Color TracerColorMax = new Color32(83, 83, 11, 255);
private static readonly Color Tracer2ColorMin = new Color32(147, 31, 7, 255);
private static readonly Color Tracer2ColorMax = new Color32(239, 191, 119, 255);
private static readonly Color VoreColorMin = new Color32(95, 51, 63, 255);
private static readonly Color VoreColorMax = new Color32(59, 31, 35, 255);
}