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
4.8 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 = SetupGradient(BloodColorKeys);
shape.scale = new Vector3(6f, 6f, 6f);
break;
}
case ParticleTrail.Tracer:
case ParticleTrail.Tracer2:
{
// Split trails, e.g. Scrag projectile
break;
}
case ParticleTrail.SlightBlood:
{
main.gravityModifierMultiplier = 0.05f;
main.startColor = SetupGradient(BloodColorKeys);
shape.scale = new Vector3(6f, 6f, 6f);
emission.rateOverDistance = 1.0f / (interval + 3);
break;
}
case ParticleTrail.VoreBall:
{
main.startLifetime = 0.3f;
main.startColor = SetupGradient(VoreColorKeys);
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 SetupGradient(GradientColorKey[] colorKeys)
{
return new ParticleSystem.MinMaxGradient(new Gradient
{
mode = GradientMode.Blend,
colorKeys = colorKeys,
});
}
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 },
};
}
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 GradientColorKey[] BloodColorKeys =
{
new GradientColorKey(new Color32(31, 0, 0, 255), 0.5f),
new GradientColorKey(new Color32(55, 0, 0, 255), 1.0f),
};
private static readonly GradientColorKey[] VoreColorKeys =
{
new GradientColorKey(new Color32(95, 51, 63, 255), 0.5f),
new GradientColorKey(new Color32(59, 31, 35, 255), 1.0f),
};
}