using System.Collections; using System.Collections.Generic; using UnityEngine; public class JupiterExosphereEffects : MonoBehaviour { [Header("Налаштування")] public Material tailMaterial; public Material radiationMaterial; public float planetRadius = 72f; [Range(0f, 1f)] public float exosphereLevel = 1f; public float previousLevel = 1f; private ParticleSystem tailSystem; private ParticleSystem radiationBeltSystem; private ParticleSystem solarCaptureSystem; private bool deathTriggered = false; void Awake() { enabled = false; } public void InitState() { if (tailSystem != null) Destroy(tailSystem.gameObject); if (radiationBeltSystem != null) Destroy(radiationBeltSystem.gameObject); if (solarCaptureSystem != null) Destroy(solarCaptureSystem.gameObject); tailSystem = null; radiationBeltSystem = null; solarCaptureSystem = null; deathTriggered = false; exosphereLevel = 1f; previousLevel = 1f; CreateTail(); CreateRadiationBelt(); CreateSolarCapture(); } void CreateTail() { GameObject obj = new GameObject("JupiterTail"); obj.transform.parent = null; obj.transform.position = transform.position; tailSystem = obj.AddComponent(); var main = tailSystem.main; main.loop = true; main.playOnAwake = true; main.maxParticles = 5000; main.startLifetime = new ParticleSystem.MinMaxCurve(5f, 12f); main.startSpeed = new ParticleSystem.MinMaxCurve(3f, 8f); main.startSize = new ParticleSystem.MinMaxCurve(0.1f, 0.4f); main.startColor = new ParticleSystem.MinMaxGradient( new Color(0.5f, 0.7f, 1f, 0.3f), new Color(0.3f, 0.5f, 1f, 0.15f) ); main.simulationSpace = ParticleSystemSimulationSpace.World; main.gravityModifier = 0f; var emission = tailSystem.emission; emission.rateOverTime = 0f; var shape = tailSystem.shape; shape.enabled = true; shape.shapeType = ParticleSystemShapeType.Sphere; shape.radius = planetRadius * 0.9f; shape.radiusThickness = 1f; var vel = tailSystem.velocityOverLifetime; vel.enabled = true; vel.space = ParticleSystemSimulationSpace.World; vel.x = new ParticleSystem.MinMaxCurve(5f); vel.y = new ParticleSystem.MinMaxCurve(0f); vel.z = new ParticleSystem.MinMaxCurve(0f); vel.orbitalX = new ParticleSystem.MinMaxCurve(0f); vel.orbitalY = new ParticleSystem.MinMaxCurve(0f); vel.orbitalZ = new ParticleSystem.MinMaxCurve(0f); var colorOverLifetime = tailSystem.colorOverLifetime; colorOverLifetime.enabled = true; Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(new Color(0.5f, 0.7f, 1f), 0f), new GradientColorKey(new Color(0.3f, 0.5f, 1f), 0.5f), new GradientColorKey(new Color(0.2f, 0.3f, 0.8f), 1f) }, new GradientAlphaKey[] { new GradientAlphaKey(0.3f, 0f), new GradientAlphaKey(0.15f, 0.5f), new GradientAlphaKey(0f, 1f) } ); colorOverLifetime.color = new ParticleSystem.MinMaxGradient(gradient); var renderer = tailSystem.GetComponent(); renderer.renderMode = ParticleSystemRenderMode.Stretch; renderer.velocityScale = 0.2f; renderer.lengthScale = 3f; renderer.sortingFudge = 3f; if (tailMaterial != null) renderer.material = tailMaterial; tailSystem.Play(); } void CreateRadiationBelt() { GameObject obj = new GameObject("JupiterRadiationBelt"); obj.transform.parent = null; obj.transform.position = transform.position; obj.transform.rotation = Quaternion.Euler(90f, 0f, 0f); radiationBeltSystem = obj.AddComponent(); var main = radiationBeltSystem.main; main.loop = true; main.playOnAwake = true; main.maxParticles = 5000; main.startLifetime = new ParticleSystem.MinMaxCurve(6f, 12f); main.startSpeed = new ParticleSystem.MinMaxCurve(0f, 0f); main.startSize = new ParticleSystem.MinMaxCurve(0.2f, 0.6f); main.startColor = new ParticleSystem.MinMaxGradient( new Color(0.8f, 0.4f, 1f, 0.4f), new Color(0.6f, 0.2f, 0.8f, 0.2f) ); main.simulationSpace = ParticleSystemSimulationSpace.World; main.gravityModifier = 0f; var emission = radiationBeltSystem.emission; emission.rateOverTime = 200f; var shape = radiationBeltSystem.shape; shape.enabled = true; shape.shapeType = ParticleSystemShapeType.Donut; shape.radius = planetRadius * 2.5f; shape.donutRadius = 3f; shape.radiusThickness = 1f; shape.arc = 360f; var vel = radiationBeltSystem.velocityOverLifetime; vel.enabled = true; vel.space = ParticleSystemSimulationSpace.World; vel.orbitalX = new ParticleSystem.MinMaxCurve(0f); vel.orbitalY = new ParticleSystem.MinMaxCurve(4f); vel.orbitalZ = new ParticleSystem.MinMaxCurve(0f); vel.x = new ParticleSystem.MinMaxCurve(0f); vel.y = new ParticleSystem.MinMaxCurve(0f); vel.z = new ParticleSystem.MinMaxCurve(0f); var colorOverLifetime = radiationBeltSystem.colorOverLifetime; colorOverLifetime.enabled = true; Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(new Color(0.8f, 0.4f, 1f), 0f), new GradientColorKey(new Color(0.6f, 0.2f, 0.8f), 0.5f), new GradientColorKey(new Color(0.4f, 0.1f, 0.6f), 1f) }, new GradientAlphaKey[] { new GradientAlphaKey(0f, 0f), new GradientAlphaKey(0.4f, 0.1f), new GradientAlphaKey(0.2f, 0.8f), new GradientAlphaKey(0f, 1f) } ); colorOverLifetime.color = new ParticleSystem.MinMaxGradient(gradient); var renderer = radiationBeltSystem.GetComponent(); renderer.renderMode = ParticleSystemRenderMode.Billboard; renderer.sortingFudge = 2f; if (radiationMaterial != null) renderer.material = radiationMaterial; radiationBeltSystem.Play(); } void CreateSolarCapture() { GameObject obj = new GameObject("JupiterSolarCapture"); obj.transform.parent = null; obj.transform.position = transform.position; solarCaptureSystem = obj.AddComponent(); var main = solarCaptureSystem.main; main.loop = true; main.playOnAwake = true; main.maxParticles = 3000; main.startLifetime = new ParticleSystem.MinMaxCurve(4f, 8f); main.startSpeed = new ParticleSystem.MinMaxCurve(0f, 0f); main.startSize = new ParticleSystem.MinMaxCurve(0.15f, 0.4f); main.startColor = new ParticleSystem.MinMaxGradient( new Color(1f, 0.8f, 0.3f, 0.3f), new Color(0.8f, 0.6f, 0.2f, 0.15f) ); main.simulationSpace = ParticleSystemSimulationSpace.World; main.gravityModifier = 0f; var emission = solarCaptureSystem.emission; emission.rateOverTime = 150f; var shape = solarCaptureSystem.shape; shape.enabled = true; shape.shapeType = ParticleSystemShapeType.Sphere; shape.radius = planetRadius * 3f; shape.radiusThickness = 0.3f; var vel = solarCaptureSystem.velocityOverLifetime; vel.enabled = true; vel.space = ParticleSystemSimulationSpace.World; vel.orbitalX = new ParticleSystem.MinMaxCurve(0f); vel.orbitalY = new ParticleSystem.MinMaxCurve(2f); vel.orbitalZ = new ParticleSystem.MinMaxCurve(0f); vel.x = new ParticleSystem.MinMaxCurve(0f); vel.y = new ParticleSystem.MinMaxCurve(0f); vel.z = new ParticleSystem.MinMaxCurve(0f); var colorOverLifetime = solarCaptureSystem.colorOverLifetime; colorOverLifetime.enabled = true; Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(new Color(1f, 0.8f, 0.3f), 0f), new GradientColorKey(new Color(0.8f, 0.6f, 0.2f), 0.5f), new GradientColorKey(new Color(0.6f, 0.4f, 0.1f), 1f) }, new GradientAlphaKey[] { new GradientAlphaKey(0f, 0f), new GradientAlphaKey(0.3f, 0.1f), new GradientAlphaKey(0.15f, 0.8f), new GradientAlphaKey(0f, 1f) } ); colorOverLifetime.color = new ParticleSystem.MinMaxGradient(gradient); var renderer = solarCaptureSystem.GetComponent(); renderer.renderMode = ParticleSystemRenderMode.Billboard; renderer.sortingFudge = 1f; if (radiationMaterial != null) renderer.material = radiationMaterial; solarCaptureSystem.Play(); } void UpdateTail() { if (tailSystem == null) return; var e = tailSystem.emission; if (exosphereLevel >= 1f) { e.rateOverTime = 0f; return; } float t = Mathf.InverseLerp(1f, 0f, exosphereLevel); e.rateOverTime = Mathf.Lerp(0f, 500f, t); var main = tailSystem.main; float speedMin = Mathf.Lerp(3f, 15f, t); float speedMax = Mathf.Lerp(8f, 30f, t); main.startSpeed = new ParticleSystem.MinMaxCurve(speedMin, speedMax); } void UpdateRadiationBelt() { if (radiationBeltSystem == null) return; var e = radiationBeltSystem.emission; float t = Mathf.InverseLerp(1f, 0f, exosphereLevel); e.rateOverTime = Mathf.Lerp(200f, 0f, t); } void UpdateSolarCapture() { if (solarCaptureSystem == null) return; var e = solarCaptureSystem.emission; float t = Mathf.InverseLerp(1f, 0f, exosphereLevel); e.rateOverTime = Mathf.Lerp(150f, 0f, t); } IEnumerator DeathBurst() { if (tailSystem != null) { var e = tailSystem.emission; e.rateOverTime = 3000f; var m = tailSystem.main; m.startSpeed = new ParticleSystem.MinMaxCurve(20f, 50f); } if (radiationBeltSystem != null) { var e = radiationBeltSystem.emission; e.rateOverTime = 0f; } yield return new WaitForSeconds(2f); if (tailSystem != null) { var e = tailSystem.emission; e.rateOverTime = 0f; var m = tailSystem.main; m.startSpeed = new ParticleSystem.MinMaxCurve(3f, 8f); } } void Update() { if (!Application.isPlaying) return; if (exosphereLevel >= 1f && previousLevel < 1f) { InitState(); deathTriggered = false; } previousLevel = exosphereLevel; if (exosphereLevel <= 0f && !deathTriggered) { deathTriggered = true; StartCoroutine(DeathBurst()); return; } if (deathTriggered) return; UpdateTail(); UpdateRadiationBelt(); UpdateSolarCapture(); } public void CleanUp() { if (tailSystem != null) Destroy(tailSystem.gameObject); if (radiationBeltSystem != null) Destroy(radiationBeltSystem.gameObject); if (solarCaptureSystem != null) Destroy(solarCaptureSystem.gameObject); tailSystem = null; radiationBeltSystem = null; solarCaptureSystem = null; deathTriggered = false; enabled = false; } }