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.
 
 
 
 
 

106 lines
3.7 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(
new Color32(31, 0, 0, 255),
new Color32(55, 0, 0, 255));
shape.scale = new Vector3(6f, 6f, 6f);
break;
}
case ParticleTrail.Tracer:
case ParticleTrail.Tracer2:
{
break;
}
case ParticleTrail.SlightBlood:
{
break;
}
case ParticleTrail.VoreBall:
{
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 },
};
}
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),
};
}