331 lines
13 KiB
C#
331 lines
13 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using TMPro;
|
||
|
||
public class PlanetSelector : MonoBehaviour
|
||
{
|
||
[SerializeField] private Material skyboxMaterial;
|
||
[SerializeField] private TextMeshProUGUI planetNameText;
|
||
[SerializeField] private Button leftButton;
|
||
[SerializeField] private Button rightButton;
|
||
[SerializeField] private Light sunLight;
|
||
[SerializeField] private ParticleSystem atmosphereParticles;
|
||
[SerializeField] private ParticleSystem starsParticles;
|
||
|
||
private int _currentIndex = 0;
|
||
private Coroutine _transitionCoroutine;
|
||
private PlanetData[] _planets;
|
||
|
||
public struct PlanetData
|
||
{
|
||
public string name;
|
||
public float gravity;
|
||
public float atmosphereDensity;
|
||
public Color skyTint;
|
||
public Color groundColor;
|
||
public float atmosphereThickness;
|
||
public float sunSize;
|
||
public float exposure;
|
||
public Color sunLightColor;
|
||
public float sunLightIntensity;
|
||
public bool hasFog;
|
||
public float fogDensity;
|
||
public Color fogColor;
|
||
public Color atmosParticleColor;
|
||
public float atmosParticleRate;
|
||
public Color starsColor;
|
||
public float starsRate;
|
||
public float starsSize;
|
||
}
|
||
|
||
private static Color H(string hex)
|
||
{
|
||
ColorUtility.TryParseHtmlString(hex, out Color c);
|
||
return c;
|
||
}
|
||
|
||
private void Awake()
|
||
{
|
||
_planets = new PlanetData[]
|
||
{
|
||
new PlanetData {
|
||
name = "헌佾<ED978C>",
|
||
gravity = 9.8f, atmosphereDensity = 1.0f,
|
||
skyTint = H("#3A7BD5"),
|
||
groundColor = H("#1A3A0A"),
|
||
atmosphereThickness = 1.0f, sunSize = 0.04f, exposure = 1.3f,
|
||
sunLightColor = H("#FFF8DC"),
|
||
sunLightIntensity = 1.2f,
|
||
hasFog = true, fogDensity = 0.0008f,
|
||
fogColor = H("#B0CCEE"),
|
||
atmosParticleColor = new Color(0.70f, 0.85f, 1.0f, 0.45f),
|
||
atmosParticleRate = 80f,
|
||
starsColor = new Color(0.95f, 0.97f, 1.0f, 0.55f),
|
||
starsRate = 60f, starsSize = 0.035f
|
||
},
|
||
new PlanetData {
|
||
name = "璥猝",
|
||
gravity = 3.7f, atmosphereDensity = 0.01f,
|
||
skyTint = H("#C99A72"),
|
||
groundColor = H("#6B3A1A"),
|
||
atmosphereThickness = 0.12f, sunSize = 0.028f, exposure = 0.90f,
|
||
sunLightColor = H("#FFD4A0"),
|
||
sunLightIntensity = 0.95f,
|
||
hasFog = true, fogDensity = 0.003f,
|
||
fogColor = H("#D4A87A"),
|
||
atmosParticleColor = new Color(0.78f, 0.55f, 0.32f, 0.65f),
|
||
atmosParticleRate = 120f,
|
||
starsColor = new Color(1.0f, 0.90f, 0.75f, 0.40f),
|
||
starsRate = 30f, starsSize = 0.025f
|
||
},
|
||
new PlanetData {
|
||
name = "犬<>琢",
|
||
gravity = 1.6f, atmosphereDensity = 0f,
|
||
skyTint = H("#000008"),
|
||
groundColor = H("#323030"),
|
||
atmosphereThickness = 0f, sunSize = 0.042f, exposure = 1.7f,
|
||
sunLightColor = H("#FFFFFF"),
|
||
sunLightIntensity = 1.9f,
|
||
hasFog = false, fogDensity = 0f, fogColor = Color.black,
|
||
atmosParticleColor = new Color(0f, 0f, 0f, 0f),
|
||
atmosParticleRate = 0f,
|
||
starsColor = new Color(1.0f, 1.0f, 1.0f, 1.0f),
|
||
starsRate = 580f, starsSize = 0.065f
|
||
},
|
||
new PlanetData {
|
||
name = "쭤張調",
|
||
gravity = 8.87f, atmosphereDensity = 90f,
|
||
skyTint = H("#D4922A"),
|
||
groundColor = H("#6B3A08"),
|
||
atmosphereThickness = 3.2f, sunSize = 0.09f, exposure = 1.0f,
|
||
sunLightColor = H("#FF9B20"),
|
||
sunLightIntensity = 1.1f,
|
||
hasFog = true, fogDensity = 0.008f,
|
||
fogColor = H("#C8842A"),
|
||
atmosParticleColor = new Color(0.90f, 0.65f, 0.20f, 0.75f),
|
||
atmosParticleRate = 200f,
|
||
starsColor = new Color(1.0f, 0.85f, 0.50f, 0.05f),
|
||
starsRate = 2f, starsSize = 0.015f
|
||
},
|
||
new PlanetData {
|
||
name = "蛇놋儼",
|
||
gravity = 24.8f, atmosphereDensity = 50f,
|
||
skyTint = H("#5A7A9E"),
|
||
groundColor = H("#7A5535"),
|
||
atmosphereThickness = 2.5f, sunSize = 0.016f, exposure = 0.80f,
|
||
sunLightColor = H("#E8C080"),
|
||
sunLightIntensity = 0.85f,
|
||
hasFog = true, fogDensity = 0.005f,
|
||
fogColor = H("#8A7050"),
|
||
atmosParticleColor = new Color(0.75f, 0.60f, 0.35f, 0.60f),
|
||
atmosParticleRate = 180f,
|
||
starsColor = new Color(0.90f, 0.88f, 0.75f, 0.15f),
|
||
starsRate = 10f, starsSize = 0.016f
|
||
},
|
||
new PlanetData {
|
||
name = "邏膣存",
|
||
gravity = 10.4f, atmosphereDensity = 20f,
|
||
skyTint = H("#DFC87A"),
|
||
groundColor = H("#A08540"),
|
||
atmosphereThickness = 1.8f, sunSize = 0.014f, exposure = 0.85f,
|
||
sunLightColor = H("#FFF0C0"),
|
||
sunLightIntensity = 0.90f,
|
||
hasFog = true, fogDensity = 0.002f,
|
||
fogColor = H("#D4BC70"),
|
||
atmosParticleColor = new Color(0.90f, 0.80f, 0.50f, 0.50f),
|
||
atmosParticleRate = 100f,
|
||
starsColor = new Color(1.0f, 0.97f, 0.82f, 0.20f),
|
||
starsRate = 15f, starsSize = 0.020f
|
||
},
|
||
new PlanetData {
|
||
name = "竟簇債녜",
|
||
gravity = 3.7f, atmosphereDensity = 0f,
|
||
skyTint = H("#050404"),
|
||
groundColor = H("#4A4038"),
|
||
atmosphereThickness = 0f, sunSize = 0.12f, exposure = 2.4f,
|
||
sunLightColor = H("#FFFCF0"),
|
||
sunLightIntensity = 2.4f,
|
||
hasFog = false, fogDensity = 0f, fogColor = Color.black,
|
||
atmosParticleColor = new Color(0f, 0f, 0f, 0f),
|
||
atmosParticleRate = 0f,
|
||
starsColor = new Color(1.0f, 1.0f, 0.97f, 0.92f),
|
||
starsRate = 500f, starsSize = 0.058f
|
||
},
|
||
new PlanetData {
|
||
name = "到陝",
|
||
gravity = 8.7f, atmosphereDensity = 5f,
|
||
skyTint = H("#72E0DC"),
|
||
groundColor = H("#2A9090"),
|
||
atmosphereThickness = 1.2f, sunSize = 0.010f, exposure = 1.0f,
|
||
sunLightColor = H("#A0F0F8"),
|
||
sunLightIntensity = 0.95f,
|
||
hasFog = true, fogDensity = 0.0015f,
|
||
fogColor = H("#60D0D0"),
|
||
atmosParticleColor = new Color(0.42f, 0.88f, 0.86f, 0.55f),
|
||
atmosParticleRate = 90f,
|
||
starsColor = new Color(0.70f, 0.95f, 1.0f, 0.50f),
|
||
starsRate = 100f, starsSize = 0.038f
|
||
},
|
||
new PlanetData {
|
||
name = "袞綎艙",
|
||
gravity = 11.2f, atmosphereDensity = 8f,
|
||
skyTint = H("#1535C8"),
|
||
groundColor = H("#080F50"),
|
||
atmosphereThickness = 1.5f, sunSize = 0.007f, exposure = 0.80f,
|
||
sunLightColor = H("#6080FF"),
|
||
sunLightIntensity = 0.75f,
|
||
hasFog = true, fogDensity = 0.003f,
|
||
fogColor = H("#1828A0"),
|
||
atmosParticleColor = new Color(0.18f, 0.28f, 1.0f, 0.60f),
|
||
atmosParticleRate = 130f,
|
||
starsColor = new Color(0.70f, 0.80f, 1.0f, 0.48f),
|
||
starsRate = 75f, starsSize = 0.036f
|
||
},
|
||
new PlanetData {
|
||
name = "拳寀佺",
|
||
gravity = 0.62f, atmosphereDensity = 0.001f,
|
||
skyTint = H("#0A0318"),
|
||
groundColor = H("#504870"),
|
||
atmosphereThickness = 0.03f, sunSize = 0.005f, exposure = 0.50f,
|
||
sunLightColor = H("#A090E0"),
|
||
sunLightIntensity = 0.45f,
|
||
hasFog = false, fogDensity = 0f, fogColor = Color.black,
|
||
atmosParticleColor = new Color(0.50f, 0.40f, 0.70f, 0.08f),
|
||
atmosParticleRate = 0f,
|
||
starsColor = new Color(0.88f, 0.82f, 1.0f, 0.92f),
|
||
starsRate = 650f, starsSize = 0.072f
|
||
}
|
||
};
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
if (leftButton != null) leftButton.onClick.AddListener(PrevPlanet);
|
||
if (rightButton != null) rightButton.onClick.AddListener(NextPlanet);
|
||
|
||
if (starsParticles != null)
|
||
{
|
||
var shape = starsParticles.shape;
|
||
shape.shapeType = ParticleSystemShapeType.Hemisphere;
|
||
shape.radius = 80f;
|
||
}
|
||
|
||
ApplyPlanet(0);
|
||
}
|
||
|
||
private void ApplyPlanet(int index)
|
||
{
|
||
if (_transitionCoroutine != null)
|
||
StopCoroutine(_transitionCoroutine);
|
||
_transitionCoroutine = StartCoroutine(TransitionToPlanet(_planets[index]));
|
||
|
||
if (planetNameText != null)
|
||
planetNameText.text = _planets[index].name;
|
||
|
||
if (leftButton != null) leftButton.interactable = index > 0;
|
||
if (rightButton != null) rightButton.interactable = index < _planets.Length - 1;
|
||
}
|
||
|
||
private IEnumerator TransitionToPlanet(PlanetData p)
|
||
{
|
||
float t = 0f;
|
||
float duration = 1.8f;
|
||
|
||
Color startSkyTint = skyboxMaterial.GetColor("_SkyTint");
|
||
Color startGroundColor = skyboxMaterial.GetColor("_GroundColor");
|
||
float startAtmosphere = skyboxMaterial.GetFloat("_AtmosphereThickness");
|
||
float startSunSize = skyboxMaterial.GetFloat("_SunSize");
|
||
float startExposure = skyboxMaterial.GetFloat("_Exposure");
|
||
Color startFogColor = RenderSettings.fogColor;
|
||
float startFogDensity = RenderSettings.fogDensity;
|
||
Color startLightColor = sunLight != null ? sunLight.color : Color.white;
|
||
float startLightIntensity = sunLight != null ? sunLight.intensity : 1f;
|
||
|
||
while (t < 1f)
|
||
{
|
||
t += Time.deltaTime / duration;
|
||
float s = Mathf.SmoothStep(0f, 1f, t);
|
||
|
||
if (skyboxMaterial != null)
|
||
{
|
||
skyboxMaterial.SetColor("_SkyTint", Color.Lerp(startSkyTint, p.skyTint, s));
|
||
skyboxMaterial.SetColor("_GroundColor", Color.Lerp(startGroundColor, p.groundColor, s));
|
||
skyboxMaterial.SetFloat("_AtmosphereThickness", Mathf.Lerp(startAtmosphere, p.atmosphereThickness, s));
|
||
skyboxMaterial.SetFloat("_SunSize", Mathf.Lerp(startSunSize, p.sunSize, s));
|
||
skyboxMaterial.SetFloat("_Exposure", Mathf.Lerp(startExposure, p.exposure, s));
|
||
}
|
||
|
||
RenderSettings.fog = p.hasFog;
|
||
if (p.hasFog)
|
||
{
|
||
RenderSettings.fogMode = FogMode.Exponential;
|
||
RenderSettings.fogColor = Color.Lerp(startFogColor, p.fogColor, s);
|
||
RenderSettings.fogDensity = Mathf.Lerp(startFogDensity, p.fogDensity, s);
|
||
}
|
||
|
||
if (sunLight != null)
|
||
{
|
||
sunLight.color = Color.Lerp(startLightColor, p.sunLightColor, s);
|
||
sunLight.intensity = Mathf.Lerp(startLightIntensity, p.sunLightIntensity, s);
|
||
}
|
||
|
||
DynamicGI.UpdateEnvironment();
|
||
yield return null;
|
||
}
|
||
|
||
if (atmosphereParticles != null)
|
||
{
|
||
var main = atmosphereParticles.main;
|
||
main.startColor = p.atmosParticleColor;
|
||
var emission = atmosphereParticles.emission;
|
||
emission.rateOverTime = p.atmosParticleRate;
|
||
if (p.atmosParticleRate > 0f && !atmosphereParticles.isPlaying)
|
||
atmosphereParticles.Play();
|
||
else if (p.atmosParticleRate == 0f)
|
||
atmosphereParticles.Stop();
|
||
}
|
||
|
||
if (starsParticles != null)
|
||
{
|
||
var main = starsParticles.main;
|
||
main.startColor = p.starsColor;
|
||
main.startSize = new ParticleSystem.MinMaxCurve(p.starsSize * 0.5f, p.starsSize);
|
||
var emission = starsParticles.emission;
|
||
emission.rateOverTime = p.starsRate;
|
||
if (p.starsRate > 0f && !starsParticles.isPlaying)
|
||
starsParticles.Play();
|
||
else if (p.starsRate == 0f)
|
||
starsParticles.Stop();
|
||
}
|
||
}
|
||
|
||
private void NextPlanet()
|
||
{
|
||
if (_currentIndex < _planets.Length - 1)
|
||
{
|
||
_currentIndex++;
|
||
ApplyPlanet(_currentIndex);
|
||
}
|
||
}
|
||
|
||
private void PrevPlanet()
|
||
{
|
||
if (_currentIndex > 0)
|
||
{
|
||
_currentIndex--;
|
||
ApplyPlanet(_currentIndex);
|
||
}
|
||
}
|
||
|
||
public void RestoreCurrentPlanet()
|
||
{
|
||
if (_transitionCoroutine != null)
|
||
StopCoroutine(_transitionCoroutine);
|
||
_transitionCoroutine = StartCoroutine(TransitionToPlanet(_planets[_currentIndex]));
|
||
}
|
||
|
||
public PlanetData GetCurrentPlanet() => _planets[_currentIndex];
|
||
}
|