Files
grass-cutters/Assets/Scripts/Core/Fx.cs
NiemandKG 36e4bb2a10 Round 6 fixes: held tools, headlamp glare, ladder openings, level horizon, roof hulls, rain hits, idle motion, belt packs, meadow variety
- Held tools sit lower and further right; the hammer faces forward and strikes about the camera's right
- Headlamp leaves held items, treats and vending machines alone (rendering layer NoLamp); other lights keep lighting them
- Hay grounded on the floor in world space (it floated)
- Deck fence opens at each ladder, rail colliders split around it; ladders moved to 2 m off the edge middle, clear of the intakes; climbing goes over a rail only if one is in the way
- Crew stand to the soil's up (Planet.Level): flat round the base, the ball's up past it, so the horizon stays level on a small planet
- Convex roof hulls for the crew cabin, garage, pitched roof and windmill tower; cabin box lowered to the eaves
- Rain and acid rain hits differ by surface: soil, grass, wood, metal
- Idle motion: dishes pan, sways sway, sensors turn, eyes blink, windmill turns in the breeze, reels and parked rotors tick over
- Belt: take tools off at the supply wall; hold E at a vending machine for a pack of 3 on the belt, LMB has one
- New meadow pieces: boulders, slab stones, crystals, mushrooms, stump, bulb plants
- -demofix checks for all of the above; loc rows in all 11 tables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 22:52:05 +06:00

539 lines
29 KiB
C#

using UnityEngine;
namespace GrassCutter
{
/// <summary>All particle juice in one place. Systems are built in code and emitted manually.</summary>
public class Fx : MonoBehaviour
{
static Fx _i;
internal static Fx I
{
get
{
if (_i == null)
{
var go = new GameObject("[Fx]");
DontDestroyOnLoad(go);
_i = go.AddComponent<Fx>();
_i.Build();
}
return _i;
}
}
ParticleSystem _drops, _spray, _foam, _puff, _steam, _frost, _sparkle, _confetti, _dust, _ring, _smoke, _wake, _motes;
ParticleSystem _bubbles, _smokeRing, _breath;
int _frame, _burstsThisFrame;
float _moteDue;
Material _flameMat, _softMat;
static readonly Color[] ConfettiColors =
{
new Color(0.69f, 0.25f, 0.17f), new Color(0.3f, 0.6f, 0.2f), new Color(0.94f, 0.89f, 0.76f),
new Color(0.9f, 0.72f, 0.24f), new Color(0.55f, 0.78f, 0.25f), new Color(0.55f, 0.37f, 0.2f),
};
static readonly Color[] ClipColors =
{
new Color(0.36f, 0.62f, 0.16f), new Color(0.5f, 0.74f, 0.22f), new Color(0.27f, 0.5f, 0.12f),
new Color(0.66f, 0.78f, 0.3f), new Color(0.42f, 0.56f, 0.18f), new Color(0.3f, 0.58f, 0.2f),
};
/// <summary>A random grass-clipping green.</summary>
public static Color Clip() => ClipColors[Random.Range(0, ClipColors.Length)];
static readonly Color FoamTint = new Color(0.72f, 0.66f, 0.48f, 0.45f);
static readonly Color Haze = new Color(0.78f, 0.82f, 0.6f, 0.3f);
void Build()
{
var bank = AssetBank.I;
var soft = bank.Mat("FX_Soft");
_softMat = soft;
var drop = bank.Mat("FX_Drop") ?? bank.Mat("FX_Shard") ?? soft;
var spark = bank.Mat("FX_Sparkle") ?? soft;
_flameMat = bank.Mat("FX_Flame") ?? spark;
// grass clippings: flat fluttering leaf shards
var leaf = bank.Mat("FX_Leaf") ?? drop;
_drops = Make("drops", leaf, 1.1f, 0.05f, 6.5f, true);
SetSizeCurve(_drops, 1f, 0.75f);
var dlim = _drops.limitVelocityOverLifetime;
dlim.enabled = true; dlim.limit = 16f; dlim.dampen = 0.05f;
var drot = _drops.rotationOverLifetime;
drot.z = new ParticleSystem.MinMaxCurve(-9f, 9f);
_spray = Make("spray", soft, 0.8f, 0.3f, 2.5f, true);
SetSizeCurve(_spray, 0.5f, 1.7f);
SetFade(_spray, 0.75f);
_foam = Make("foam", bank.Mat("FX_Foam") ?? soft, 2.2f, 0.6f, 0f, true);
_foam.GetComponent<ParticleSystemRenderer>().renderMode = ParticleSystemRenderMode.HorizontalBillboard;
SetSizeCurve(_foam, 0.6f, 1.6f);
SetFade(_foam, 0.8f);
_puff = Make("puff", soft, 0.25f, 0.06f, 0f, false);
SetSizeCurve(_puff, 0.3f, 1.4f);
SetFade(_puff, 0.5f);
_ring = Make("ring", bank.Mat("FX_Ring") ?? soft, 0.6f, 0.5f, 0f, false);
_ring.GetComponent<ParticleSystemRenderer>().renderMode = ParticleSystemRenderMode.HorizontalBillboard;
SetSizeCurve(_ring, 0.15f, 1.6f);
SetFade(_ring, 0.85f);
_steam = Make("steam", soft, 2.6f, 0.8f, -0.25f, true);
SetSizeCurve(_steam, 0.4f, 2.6f);
SetFade(_steam, 0.55f);
var sn = _steam.noise; sn.enabled = true; sn.strength = 0.6f; sn.frequency = 0.35f;
_frost = Make("frost", spark, 1.4f, 0.06f, -0.15f, true);
SetSizeCurve(_frost, 1f, 0f);
var fn = _frost.noise; fn.enabled = true; fn.strength = 0.5f; fn.frequency = 0.8f;
_sparkle = Make("sparkle", spark, 0.7f, 0.05f, -0.3f, false);
SetSizeCurve(_sparkle, 1f, 0f);
_dust = Make("dust", soft, 0.6f, 0.25f, -0.05f, false);
SetSizeCurve(_dust, 0.4f, 1.6f);
SetFade(_dust, 0.35f);
_smoke = Make("smoke", soft, 4.5f, 2f, -0.1f, true);
SetSizeCurve(_smoke, 0.5f, 3.2f);
SetFade(_smoke, 0.7f);
var smn = _smoke.noise; smn.enabled = true; smn.strength = 1.2f; smn.frequency = 0.2f;
_wake = Make("wake", bank.Mat("FX_Foam") ?? soft, 3f, 0.9f, 0f, true);
_wake.GetComponent<ParticleSystemRenderer>().renderMode = ParticleSystemRenderMode.HorizontalBillboard;
SetSizeCurve(_wake, 0.6f, 2.4f);
SetFade(_wake, 0.7f);
// treats: beer bubbles that wobble up, smoke breath that hangs and curls, and rings blown off a cigar
_bubbles = Make("bubbles", bank.Mat("FX_Ring") ?? spark, 1.6f, 0.05f, -0.6f, false);
SetSizeCurve(_bubbles, 0.6f, 1.2f);
SetFade(_bubbles, 0.9f);
var bn = _bubbles.noise; bn.enabled = true; bn.strength = 0.4f; bn.frequency = 1.4f;
_breath = Make("breath", soft, 3.2f, 0.4f, -0.08f, true);
SetSizeCurve(_breath, 0.35f, 2.8f);
SetFade(_breath, 0.55f);
var brn = _breath.noise; brn.enabled = true; brn.strength = 0.35f; brn.frequency = 0.5f;
var brl = _breath.limitVelocityOverLifetime; brl.enabled = true; brl.limit = 0.4f; brl.dampen = 0.08f;
_smokeRing = Make("smokering", bank.Mat("FX_Ring") ?? soft, 2.4f, 0.2f, -0.05f, false);
_smokeRing.GetComponent<ParticleSystemRenderer>().renderMode = ParticleSystemRenderMode.Billboard;
SetSizeCurve(_smokeRing, 0.5f, 2.2f);
SetFade(_smokeRing, 0.7f);
var srl = _smokeRing.limitVelocityOverLifetime; srl.enabled = true; srl.limit = 0.3f; srl.dampen = 0.05f;
_confetti = Make("confetti", bank.Mat("FX_Confetti") ?? soft, 3.5f, 0.06f, 1.4f, true);
_motes = Make("motes", soft, 5f, 0.05f, 0f, false);
var wander = _motes.noise;
wander.enabled = true; wander.strength = 0.35f; wander.frequency = 0.25f; wander.scrollSpeed = 0.2f;
var glow = _motes.colorOverLifetime;
glow.enabled = true;
var fade = new Gradient();
fade.SetKeys(new[] { new GradientColorKey(Color.white, 0f), new GradientColorKey(Color.white, 1f) },
new[] { new GradientAlphaKey(0f, 0f), new GradientAlphaKey(1f, 0.2f), new GradientAlphaKey(1f, 0.7f), new GradientAlphaKey(0f, 1f) });
glow.color = fade;
var noise = _confetti.noise;
noise.enabled = true; noise.strength = 1.2f; noise.frequency = 0.6f;
var vel = _confetti.limitVelocityOverLifetime;
vel.enabled = true; vel.limit = 6f; vel.dampen = 0.08f;
}
/// <summary>Keeps the air around a spot alive: pollen on the breeze by day, fireflies low over the grass after dark.</summary>
public static void Motes(Vector3 eye, float dark)
{
var i = I;
i._moteDue += Time.deltaTime * Mathf.Lerp(16f, 5f, dark);
for (; i._moteDue >= 1f; i._moteDue -= 1f)
{
var at = Planet.Surface(eye + Random.insideUnitSphere * 16f);
var up = Planet.Up(at);
bool fly = dark > 0.5f;
at += up * (fly ? Random.Range(0.5f, 1.5f) : Random.Range(0.3f, 4f));
var drift = Vector3.ProjectOnPlane(new Vector3(0.87f, 0.11f, 0.48f), up) * (fly ? 0.1f : 0.45f) + Random.insideUnitSphere * 0.2f;
Emit(i._motes, at, drift, fly ? Random.Range(0.1f, 0.16f) : Random.Range(0.03f, 0.06f), fly ? new Color(1.6f, 2.2f, 0.5f, 1f) : new Color(1f, 0.97f, 0.76f, 0.55f), Random.Range(4f, 7f));
}
}
internal ParticleSystem Make(string n, Material mat, float life, float size, float gravity, bool rotate)
{
var go = new GameObject(n);
go.transform.SetParent(transform, false);
var ps = go.AddComponent<ParticleSystem>();
ps.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
var main = ps.main;
main.playOnAwake = false;
main.loop = false;
main.startLifetime = life;
main.startSize = size;
main.startSpeed = 0f;
main.gravityModifier = gravity / 9.81f;
main.simulationSpace = ParticleSystemSimulationSpace.World;
main.maxParticles = 5000;
main.scalingMode = ParticleSystemScalingMode.Hierarchy;
if (rotate)
{
main.startRotation3D = false;
main.startRotation = new ParticleSystem.MinMaxCurve(0f, Mathf.PI * 2f);
var rol = ps.rotationOverLifetime;
rol.enabled = true;
rol.z = new ParticleSystem.MinMaxCurve(-1.5f, 1.5f);
}
var em = ps.emission; em.enabled = false;
var sh = ps.shape; sh.enabled = false;
var r = go.GetComponent<ParticleSystemRenderer>();
r.sharedMaterial = mat;
r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
r.receiveShadows = false;
ps.Play();
return ps;
}
internal static void SetSizeCurve(ParticleSystem ps, float a, float b)
{
var s = ps.sizeOverLifetime;
s.enabled = true;
s.size = new ParticleSystem.MinMaxCurve(1f, AnimationCurve.EaseInOut(0f, a, 1f, b));
}
internal static void SetFade(ParticleSystem ps, float startAlpha)
{
var c = ps.colorOverLifetime;
c.enabled = true;
var g = new Gradient();
g.SetKeys(new[] { new GradientColorKey(Color.white, 0f), new GradientColorKey(Color.white, 1f) },
new[] { new GradientAlphaKey(startAlpha, 0f), new GradientAlphaKey(startAlpha, 0.25f), new GradientAlphaKey(0f, 1f) });
c.color = g;
}
internal static void Emit(ParticleSystem ps, Vector3 pos, Vector3 vel, float size, Color color, float life = -1f)
{
var ep = new ParticleSystem.EmitParams
{
position = pos,
velocity = vel,
startSize = size,
startColor = color,
applyShapeToPosition = false,
};
if (life > 0f) ep.startLifetime = life;
ps.Emit(ep, 1);
}
static Vector3 Hemi(Vector3 n, float spread)
{
var r = Random.onUnitSphere;
if (Vector3.Dot(r, n) < 0f) r = -r;
return Vector3.Slerp(n, r, spread).normalized;
}
bool Budget(int cost)
{
if (_frame != Time.frameCount) { _frame = Time.frameCount; _burstsThisFrame = 0; }
_burstsThisFrame += cost;
return _burstsThisFrame <= 80;
}
// ───────────────────────── grass ─────────────────────────
/// <summary>Something thumps into the meadow: a burst of clippings, a dust puff, a flattened ring.</summary>
public static void Splash(Vector3 pos, float power)
{
var i = I;
if (!i.Budget(2)) return;
power = Mathf.Max(0.1f, power);
int n = Mathf.RoundToInt(10 + 30 * Mathf.Min(power, 2.5f));
for (int k = 0; k < n; k++)
{
var d = Random.insideUnitCircle.normalized;
var v = Planet.Frame * new Vector3(d.x * Random.Range(0.6f, 2.2f), Random.Range(2.5f, 6.5f), d.y * Random.Range(0.6f, 2.2f)) * Mathf.Sqrt(power);
Emit(i._drops, pos + Planet.Frame * new Vector3(d.x, 0f, d.y) * 0.25f * power, v * 0.8f, Random.Range(0.05f, 0.11f) * (0.7f + power * 0.3f), Clip());
}
for (int k = 0; k < 3 + power * 4; k++)
Emit(i._spray, pos + Random.insideUnitSphere * 0.3f * power, Planet.LocalUp * Random.Range(0.8f, 2.4f) * power + Random.insideUnitSphere * 0.6f,
Random.Range(0.4f, 0.9f) * power, Haze);
Emit(i._ring, pos + Planet.LocalUp * 0.04f, Vector3.zero, 1.6f * power + 0.4f, FoamTint, 0.9f);
Emit(i._foam, pos + Planet.LocalUp * 0.05f, Vector3.zero, 1.2f * power + 0.3f, FoamTint);
}
/// <summary>A few clippings flung in a direction (mower chutes, jetpack, full bags).</summary>
public static void Droplets(Vector3 pos, Vector3 dir, int count)
{
var i = I;
if (!i.Budget(1)) return;
for (int k = 0; k < count; k++)
Emit(i._drops, pos + Random.insideUnitSphere * 0.15f, (dir.normalized + Random.insideUnitSphere * 0.6f) * Random.Range(1.5f, 3.5f),
Random.Range(0.045f, 0.09f), Clip(), 0.9f);
}
/// <summary>A stream of clippings ripped out of the meadow toward a nozzle (mowing tools, drones, edge mowers).</summary>
public static void Stream(Vector3 from, Vector3 to, float power)
{
var i = I;
if (!i.Budget(1)) return;
var d = to - from;
float len = d.magnitude;
if (len < 0.05f) return;
var dir = d / len;
int n = Mathf.Clamp(Mathf.RoundToInt(3 + power * 6), 2, 14);
float speed = Mathf.Max(6f, len * 3.2f);
float life = len / speed;
for (int k = 0; k < n; k++)
{
var side = Vector3.Cross(dir, Random.onUnitSphere).normalized * Random.Range(0f, 0.35f) * (0.5f + power);
var p = from + side;
Emit(i._drops, p, (to - p).normalized * speed + Random.insideUnitSphere * 0.6f, Random.Range(0.05f, 0.1f) * (0.7f + power * 0.4f), Clip(), life);
}
if (Random.value < 0.6f)
Emit(i._spray, from + Planet.LocalUp * 0.1f, dir * speed * 0.6f + Random.insideUnitSphere * 0.5f, Random.Range(0.2f, 0.45f) * (0.6f + power), Haze, life * 1.4f);
if (Random.value < 0.25f)
Emit(i._foam, from + Planet.LocalUp * 0.04f + Random.insideUnitSphere.Flat() * 0.6f, Vector3.zero, Random.Range(0.4f, 0.9f) * (0.6f + power), FoamTint, 1.2f);
}
/// <summary>A spray of mulch out of a nozzle (dumping, mulch blast).</summary>
public static void Jet(Vector3 nozzle, Vector3 dir, float power)
{
var i = I;
if (!i.Budget(1)) return;
for (int k = 0; k < 4; k++)
{
var d = Vector3.Slerp(dir, Random.onUnitSphere, 0.06f).normalized;
Emit(i._drops, nozzle + d * 0.05f, d * Random.Range(9f, 14f) * power, Random.Range(0.05f, 0.1f), Clip(), 0.9f);
}
if (Random.value < 0.5f) Emit(i._spray, nozzle, dir * 6f * power, Random.Range(0.12f, 0.25f), Haze, 0.4f);
}
/// <summary>Vehicle trail: a dust wake + clippings thrown out of the sides.</summary>
public static void Wake(Vector3 pos, Vector3 back, float speed01)
{
var i = I;
if (!i.Budget(1) || speed01 < 0.05f) return;
Emit(i._wake, pos + Random.insideUnitSphere.Flat() * 0.3f, back * 0.5f, Random.Range(0.8f, 1.4f) * (0.6f + speed01), new Color(FoamTint.r, FoamTint.g, FoamTint.b, 0.3f + speed01 * 0.3f));
var side = Vector3.Cross(Planet.LocalUp, back).normalized;
if (Random.value < speed01)
for (int s = -1; s <= 1; s += 2)
Emit(i._drops, pos + side * s * 0.5f, (side * s * 1.8f + Planet.LocalUp * 2.4f) * (0.6f + speed01), Random.Range(0.05f, 0.09f), Clip(), 0.8f);
}
public enum Surface { Ground, Grass, Wood, Metal }
/// <summary>
/// A raindrop landing, as the thing it lands on takes it. Soil throws up a brown fleck and a dull ring; grass shakes off
/// a spray of beads; wood beads up; metal rings out with a hard bright bounce. Acid adds its own: a fizz of steam on
/// metal, a thin brown smoke off wood, scorched flecks and a yellow puff off grass, a yellow froth on soil.
/// </summary>
public static void RainHit(Vector3 pos, Vector3 up, Surface on, Color tint, float acid)
{
var i = I;
if (!i || !i.Budget(1)) return;
var drop = new Color(tint.r, tint.g, tint.b, 0.55f);
switch (on)
{
case Surface.Ground:
Emit(i._ring, pos + up * 0.03f, Vector3.zero, Random.Range(0.12f, 0.22f), new Color(0.42f, 0.33f, 0.22f, 0.5f), 0.6f);
for (int k = 0; k < 2; k++)
Emit(i._drops, pos + up * 0.03f, up * Random.Range(1.2f, 2f) + Random.insideUnitSphere * 0.9f, Random.Range(0.025f, 0.04f), new Color(0.36f, 0.27f, 0.17f, 1f), 0.35f);
if (acid > 0.5f) Emit(i._puff, pos + up * 0.04f, up * 0.25f, Random.Range(0.1f, 0.18f), new Color(0.85f, 0.9f, 0.35f, 0.5f), 0.9f);
break;
case Surface.Grass:
for (int k = 0; k < 3; k++)
Emit(i._drops, pos + up * 0.25f + Random.insideUnitSphere * 0.1f, up * Random.Range(0.8f, 1.6f) + Random.insideUnitSphere * 1.2f, Random.Range(0.02f, 0.035f),
acid > 0.5f ? new Color(0.55f, 0.5f, 0.15f, 1f) : new Color(0.7f, 0.9f, 0.75f, 0.9f), 0.4f);
if (acid > 0.5f && Random.value < 0.4f) Emit(i._puff, pos + up * 0.3f, up * 0.35f, Random.Range(0.12f, 0.2f), new Color(0.8f, 0.85f, 0.4f, 0.4f), 1.1f);
break;
case Surface.Wood:
Emit(i._puff, pos + up * 0.02f, up * 0.3f, Random.Range(0.06f, 0.1f), drop, 0.4f);
for (int k = 0; k < 2; k++)
Emit(i._drops, pos + up * 0.02f, up * Random.Range(0.8f, 1.4f) + Random.insideUnitSphere * 0.6f, Random.Range(0.02f, 0.03f), drop, 0.3f);
if (acid > 0.5f && Random.value < 0.5f) Emit(i._puff, pos + up * 0.05f, up * Random.Range(0.4f, 0.7f), Random.Range(0.15f, 0.25f), new Color(0.35f, 0.3f, 0.2f, 0.45f), 1.4f);
break;
case Surface.Metal:
for (int k = 0; k < 4; k++)
Emit(i._drops, pos + up * 0.02f, up * Random.Range(2.2f, 3.4f) + Random.insideUnitSphere * 1.6f, Random.Range(0.018f, 0.028f), new Color(0.9f, 0.95f, 1f, 1f), 0.3f);
Emit(i._sparkle, pos + up * 0.03f, up * 0.4f, Random.Range(0.06f, 0.1f), new Color(1f, 1f, 1f, 0.8f), 0.25f);
if (acid > 0.5f)
{
Emit(i._steam, pos + up * 0.05f, up * Random.Range(0.6f, 1f), Random.Range(0.12f, 0.2f), new Color(0.88f, 1f, 0.6f, 0.45f), 0.5f);
if (Random.value < 0.25f) Emit(i._sparkle, pos + up * 0.05f, up * 1.2f + Random.insideUnitSphere, 0.05f, new Color(0.8f, 1f, 0.3f, 1f), 0.3f);
}
break;
}
}
/// <summary>Vaporizer / hot vent: big soft white billows.</summary>
public static void Steam(Vector3 pos, float amount)
{
var i = I;
if (!i.Budget(1)) return;
int n = Mathf.Clamp(Mathf.RoundToInt(2 + amount * 6), 1, 24);
for (int k = 0; k < n; k++)
Emit(i._steam, pos + Random.insideUnitSphere * 0.25f * amount, Planet.LocalUp * Random.Range(1.2f, 2.6f) + Random.insideUnitSphere * 0.5f,
Random.Range(0.5f, 1f) * (0.6f + amount * 0.4f), new Color(1f, 1f, 1f, 0.6f));
}
/// <summary>Cryo Press: icy glitter and cold mist.</summary>
public static void Frost(Vector3 pos, float amount)
{
var i = I;
if (!i.Budget(1)) return;
int n = Mathf.Clamp(Mathf.RoundToInt(6 + amount * 24), 2, 40);
for (int k = 0; k < n; k++)
Emit(i._frost, pos + Random.insideUnitSphere * 0.5f, Random.insideUnitSphere * 1.4f + Planet.LocalUp * 0.3f, Random.Range(0.04f, 0.1f),
Color.Lerp(new Color(0.55f, 0.78f, 0.25f), new Color(0.9f, 0.82f, 0.45f), Random.value));
for (int k = 0; k < 2 + amount * 4; k++)
Emit(i._steam, pos + Random.insideUnitSphere * 0.4f, -Planet.LocalUp * 0.4f + Random.insideUnitSphere * 0.5f, Random.Range(0.6f, 1.2f), new Color(0.85f, 0.95f, 1f, 0.45f), 1.8f);
}
/// <summary>Rocket lift-off: shock ring, steam blast hugging the deck, debris of spray.</summary>
public static void LaunchBlast(Vector3 pos)
{
var i = I;
Emit(i._ring, pos + Planet.LocalUp * 0.05f, Vector3.zero, 14f, new Color(1f, 0.9f, 0.7f, 0.9f), 0.7f);
Emit(i._ring, pos + Planet.LocalUp * 0.08f, Vector3.zero, 8f, new Color(1f, 0.7f, 0.35f, 0.9f), 0.45f);
for (int k = 0; k < 40; k++)
{
var d = Random.insideUnitCircle.normalized;
Emit(i._smoke, pos + Planet.Frame * new Vector3(d.x, 0.2f, d.y) * 1.5f, Planet.Frame * new Vector3(d.x, 0.08f, d.y) * Random.Range(6f, 14f), Random.Range(1.5f, 3f), new Color(1f, 0.98f, 0.95f, 0.85f));
}
for (int k = 0; k < 60; k++)
Emit(i._drops, pos + Random.insideUnitSphere, Hemi(Planet.LocalUp, 0.9f) * Random.Range(4f, 12f), Random.Range(0.05f, 0.1f), Clip());
for (int k = 0; k < 24; k++)
Emit(i._sparkle, pos + Planet.LocalUp * 0.5f, Random.onUnitSphere * Random.Range(3f, 8f), Random.Range(0.08f, 0.16f), new Color(1f, 0.75f, 0.35f));
}
/// <summary>A puff of grey diesel smoke out of a stack; power over 1 is a black cough.</summary>
public static void Exhaust(Vector3 pos, Vector3 up, float power)
{
var i = I;
if (!i.Budget(1)) return;
int n = power > 1f ? 5 : 1;
float dark = power > 1f ? 0.18f : 0.42f;
for (int k = 0; k < n; k++)
Emit(i._smoke, pos + Random.insideUnitSphere * 0.05f, up * Random.Range(1.2f, 2.2f) * Mathf.Min(power, 1.5f) + Random.insideUnitSphere * 0.25f,
Random.Range(0.18f, 0.32f) * (0.7f + power * 0.4f), new Color(dark, dark, dark * 1.05f, power > 1f ? 0.55f : 0.32f), Random.Range(1.1f, 1.8f));
}
/// <summary>Dust and a few clippings thrown up behind a wheel.</summary>
public static void Kick(Vector3 ground, Vector3 back, float speed01)
{
var i = I;
if (!i.Budget(1)) return;
var up = Planet.Up(ground);
Emit(i._dust, ground + up * 0.1f + Random.insideUnitSphere * 0.15f, (back * 1.2f + up * 0.8f) * (0.5f + speed01) + Random.insideUnitSphere * 0.3f,
Random.Range(0.35f, 0.7f) * (0.6f + speed01), new Color(0.76f, 0.68f, 0.5f, 0.28f + speed01 * 0.22f), Random.Range(0.6f, 1.1f));
if (Random.value < 0.5f + speed01 * 0.5f)
Emit(i._drops, ground + up * 0.1f, (back * 1.5f + up * 2.2f) * (0.5f + speed01) + Random.insideUnitSphere * 0.6f, Random.Range(0.04f, 0.08f), Clip(), 0.8f);
}
public static void Smoke(Vector3 pos, float size)
{
var i = I;
if (!i.Budget(1)) return;
Emit(i._smoke, pos + Random.insideUnitSphere * 0.3f, Random.insideUnitSphere * 1.2f + -Planet.LocalUp * 1.5f, size * Random.Range(0.8f, 1.3f), new Color(1f, 0.97f, 0.93f, 0.7f));
}
// ───────────────────────── treats ─────────────────────────
/// <summary>A breath of cigar smoke: a soft cloud that drifts out the way you face, slows, and curls up.</summary>
public static void Exhale(Vector3 mouth, Vector3 dir, float amount)
{
var i = I;
int n = Mathf.Clamp(Mathf.RoundToInt(4 + amount * 14), 2, 24);
for (int k = 0; k < n; k++)
Emit(i._breath, mouth + Random.insideUnitSphere * 0.05f, (dir * Random.Range(0.6f, 1.6f) + Random.insideUnitSphere * 0.25f) * (0.5f + amount * 0.6f),
Random.Range(0.12f, 0.3f) * (0.6f + amount * 0.5f), new Color(0.93f, 0.92f, 0.88f, Random.Range(0.35f, 0.6f)), Random.Range(2.2f, 3.4f));
}
/// <summary>A smoke ring, blown off the lips and drifting away as it opens.</summary>
public static void SmokeRing(Vector3 mouth, Vector3 dir)
{
Emit(I._smokeRing, mouth, dir * Random.Range(0.9f, 1.3f), Random.Range(0.12f, 0.18f), new Color(0.95f, 0.94f, 0.9f, 0.75f));
}
/// <summary>Beer bubbles wobbling up and popping.</summary>
public static void Bubbles(Vector3 pos, int count)
{
var i = I;
for (int k = 0; k < count; k++)
Emit(i._bubbles, pos + Random.insideUnitSphere * 0.15f, Planet.LocalUp * Random.Range(0.3f, 0.9f) + Random.insideUnitSphere * 0.2f,
Random.Range(0.025f, 0.06f), new Color(1f, 0.9f, 0.55f, 0.9f), Random.Range(0.8f, 1.6f));
}
/// <summary>A can cracked open: a fizz of foam and spray up out of the top.</summary>
public static void Fizz(Vector3 pos, Vector3 up)
{
var i = I;
for (int k = 0; k < 14; k++)
Emit(i._puff, pos, (up * Random.Range(0.6f, 1.4f) + Random.insideUnitSphere * 0.5f), Random.Range(0.02f, 0.05f), new Color(1f, 0.97f, 0.88f, 0.8f), 0.35f);
Bubbles(pos, 8);
}
/// <summary>The ember catches: a few orange sparks.</summary>
public static void Embers(Vector3 pos, int count)
{
var i = I;
for (int k = 0; k < count; k++)
Emit(i._sparkle, pos + Random.insideUnitSphere * 0.01f, Random.onUnitSphere * Random.Range(0.3f, 1.2f) + Planet.LocalUp * 0.4f, Random.Range(0.012f, 0.03f),
Color.Lerp(new Color(1f, 0.45f, 0.1f), new Color(1f, 0.85f, 0.4f), Random.value), Random.Range(0.3f, 0.7f));
}
// ───────────────────────── generic ─────────────────────────
public static void Confetti(Vector3 pos, int amount = 120, float power = 6f)
{
var i = I;
for (int k = 0; k < amount; k++)
Emit(i._confetti, pos + Random.insideUnitSphere * 0.3f, Hemi(Planet.LocalUp, 0.55f) * Random.Range(power * 0.5f, power),
Random.Range(0.05f, 0.09f), ConfettiColors[Random.Range(0, ConfettiColors.Length)]);
}
public static void Slam(Vector3 pos, Vector3 normal, float radius)
{
var i = I;
Emit(i._ring, pos + normal * 0.01f, Vector3.zero, radius * 2.4f, new Color(1f, 1f, 1f, 0.8f), 0.35f);
for (int k = 0; k < 8; k++)
Emit(i._dust, pos + Random.insideUnitSphere * radius * 0.5f, (Random.insideUnitSphere + normal) * 0.7f, Random.Range(0.15f, 0.3f),
new Color(1f, 1f, 1f, 0.5f));
}
public static void Dust(Vector3 pos, float size = 0.3f, int count = 6)
{
var i = I;
for (int k = 0; k < count; k++)
{
var d = Random.insideUnitCircle.normalized;
Emit(i._dust, pos + Planet.Frame * new Vector3(d.x, 0.05f, d.y) * 0.2f, Planet.Frame * new Vector3(d.x, 0.15f, d.y) * Random.Range(0.6f, 1.3f), size * Random.Range(0.7f, 1.3f),
new Color(0.82f, 0.74f, 0.58f, 0.5f));
}
}
public static void Sparkles(Vector3 pos, int count, Color c)
{
var i = I;
for (int k = 0; k < count; k++)
Emit(i._sparkle, pos + Random.insideUnitSphere * 0.2f, Random.onUnitSphere * Random.Range(0.5f, 2f) + Planet.LocalUp, Random.Range(0.04f, 0.09f), c);
}
/// <summary>Suction nozzle intake: spray specks spiralling into the nozzle.</summary>
public static void Suck(Vector3 nozzle, Vector3 dir)
{
var i = I;
if (!i.Budget(1)) return;
for (int k = 0; k < 2; k++)
{
var from = nozzle + Vector3.Slerp(dir, Random.onUnitSphere, 0.35f).normalized * Random.Range(0.6f, 1.4f);
Emit(i._puff, from, (nozzle - from) * 4f, Random.Range(0.04f, 0.09f), new Color(0.85f, 0.95f, 1f, 0.45f), 0.25f);
}
}
public static void Build(Vector3 pos, Vector2 size)
{
var i = I;
int n = Mathf.RoundToInt(8 + size.x * size.y * 4);
for (int k = 0; k < n; k++)
{
var p = pos + new Vector3(Random.Range(-0.5f, 0.5f) * size.x, 0.05f, Random.Range(-0.5f, 0.5f) * size.y);
Emit(i._dust, p, new Vector3(Random.Range(-0.6f, 0.6f), 0.4f, Random.Range(-0.6f, 0.6f)), Random.Range(0.2f, 0.4f), new Color(1f, 1f, 1f, 0.6f));
}
for (int k = 0; k < 8; k++)
Emit(i._sparkle, pos + Planet.LocalUp * 0.5f + Random.insideUnitSphere * 0.4f, Random.onUnitSphere * 1.5f + Planet.LocalUp, Random.Range(0.04f, 0.08f), new Color(1f, 0.75f, 0.35f));
}
/// <summary>Make sure the singleton (and its systems) exist before gameplay starts emitting.</summary>
public static void Warmup() { _ = I; }
}
static class VecExt
{
public static Vector3 Flat(this Vector3 v) => Vector3.ProjectOnPlane(v, Planet.LocalUp);
}
}