Files
ScienceLab.TypesOfMotion/Assets/Scripts/PlanetInfoDisplay.cs
2026-02-18 00:08:49 +02:00

132 lines
4.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class PlanetInfoDisplay : MonoBehaviour
{
[SerializeField] private PlanetType planetType;
[SerializeField] private PlanetSpin planetSpin;
[SerializeField] private TextMeshProUGUI infoText;
[SerializeField] private float startDistanceUnity;
private Dictionary<PlanetType, float> _realDistances = new Dictionary<PlanetType, float>()
{
{ PlanetType.Mercury, 57.9f },
{ PlanetType.Venus, 108.2f },
{ PlanetType.Earth, 149.6f },
{ PlanetType.Mars, 227.9f },
{ PlanetType.Jupiter, 778.5f },
{ PlanetType.Saturn, 1432f },
{ PlanetType.Uranus, 2867f },
{ PlanetType.Neptune, 4515f },
{ PlanetType.Pluto, 5906f }
};
private Dictionary<PlanetType, float> _realRotationSpeeds = new Dictionary<PlanetType, float>()
{
{ PlanetType.Mercury, 10.83f },
{ PlanetType.Venus, 6.52f },
{ PlanetType.Earth, 1674f },
{ PlanetType.Mars, 868f },
{ PlanetType.Jupiter, 45583f },
{ PlanetType.Saturn, 36840f },
{ PlanetType.Uranus, 14794f },
{ PlanetType.Neptune, 9719f },
{ PlanetType.Pluto, 813f }
};
private Dictionary<PlanetType, float> _baseRotationSpeeds = new Dictionary<PlanetType, float>()
{
{ PlanetType.Mercury, 0.26f },
{ PlanetType.Venus, -0.025f },
{ PlanetType.Earth, 15f },
{ PlanetType.Mars, 14.6f },
{ PlanetType.Jupiter, 36.4f },
{ PlanetType.Saturn, 33.6f },
{ PlanetType.Uranus, -20.9f },
{ PlanetType.Neptune, 22.4f },
{ PlanetType.Pluto, -2.35f }
};
private Dictionary<PlanetType, float> _orbitalSpeeds = new Dictionary<PlanetType, float>()
{
{ PlanetType.Mercury, 47.4f },
{ PlanetType.Venus, 35.0f },
{ PlanetType.Earth, 29.8f },
{ PlanetType.Mars, 24.1f },
{ PlanetType.Jupiter, 13.1f },
{ PlanetType.Saturn, 9.7f },
{ PlanetType.Uranus, 6.8f },
{ PlanetType.Neptune, 5.4f },
{ PlanetType.Pluto, 4.7f }
};
private Dictionary<PlanetType, Vector2> _temperatures = new Dictionary<PlanetType, Vector2>()
{
{ PlanetType.Mercury, new Vector2(-180f, 430f) },
{ PlanetType.Venus, new Vector2(437f, 497f) },
{ PlanetType.Earth, new Vector2(-88f, 58f) },
{ PlanetType.Mars, new Vector2(-125f, 20f) },
{ PlanetType.Jupiter, new Vector2(-145f, -108f) },
{ PlanetType.Saturn, new Vector2(-178f, -130f) },
{ PlanetType.Uranus, new Vector2(-224f, -197f) },
{ PlanetType.Neptune, new Vector2(-218f, -200f) },
{ PlanetType.Pluto, new Vector2(-240f, -218f) }
};
private Dictionary<PlanetType, string> _planetTypes = new Dictionary<PlanetType, string>()
{
{ PlanetType.Mercury, "Êàì'ÿíèñòà" },
{ PlanetType.Venus, "Êàì'ÿíèñòà" },
{ PlanetType.Earth, "Êàì'ÿíèñòà" },
{ PlanetType.Mars, "Êàì'ÿíèñòà" },
{ PlanetType.Jupiter, "Ãàçîâèé ã³ãàíò" },
{ PlanetType.Saturn, "Ãàçîâèé ã³ãàíò" },
{ PlanetType.Uranus, "Êðèæàíèé ã³ãàíò" },
{ PlanetType.Neptune, "Êðèæàíèé ã³ãàíò" },
{ PlanetType.Pluto, "Êàðëèêîâà" }
};
void Update()
{
if (infoText == null) return;
UpdateInfo();
}
void UpdateInfo()
{
float currentX = Mathf.Abs(transform.position.x);
float distanceKm = 0f;
if (startDistanceUnity > 0.001f)
{
float ratio = currentX / startDistanceUnity;
distanceKm = ratio * _realDistances[planetType];
}
float currentRotationSpeed = 0f;
if (planetSpin != null)
{
float baseSpeed = Mathf.Abs(_baseRotationSpeeds[planetType]);
float currentSpeed = Mathf.Abs(planetSpin.RotationSpeed);
if (baseSpeed > 0.0001f)
{
float speedRatio = currentSpeed / baseSpeed;
currentRotationSpeed = _realRotationSpeeds[planetType] * speedRatio;
}
}
float orbitalSpeed = _orbitalSpeeds[planetType];
Vector2 temp = _temperatures[planetType];
string type = _planetTypes[planetType];
infoText.text =
"Òèï ïëàíåòè: " + type + "\n" +
"³äñòàíü â³ä Ñîíöÿ: " + distanceKm.ToString("F1") + " ìëí êì\n" +
"Øâèäê³ñòü îáåðòàííÿ íàâêîëî ñâ îñ³: " + currentRotationSpeed.ToString("F0") + " êì/ãîä\n" +
"Øâèäê³ñòü ðóõó ïî îðá³ò³ íàâêîëî Ñîíöÿ: " + orbitalSpeed.ToString("F1") + " êì/ñ\n" +
"Òåìïåðàòóðà ïîâåðõí³: â³ä "+"\n" + temp.x.ToString("F0") + "°C äî " + temp.y.ToString("F0") + "°C";
}
}