Files
2026-05-29 18:21:53 +03:00

158 lines
4.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SaturnDeath : MonoBehaviour
{
[Header("Òåêñòóðè òðîïîñôåðè (BaseMap)")]
public Texture2D tropo100;
public Texture2D tropo70;
public Texture2D tropo50;
public Texture2D tropo30;
public Texture2D tropo0;
public Texture2D deadTexture;
[Header("Òåêñòóðè òðîïîñôåðè (BaseMap2)")]
public Texture2D tropo100B;
public Texture2D tropo70B;
public Texture2D tropo50B;
public Texture2D tropo30B;
public Texture2D tropo0B;
public Texture2D deadTextureB;
[Header("Òåêñòóðè ê³ëåöü")]
public Texture2D rings100;
public Texture2D rings70;
public Texture2D rings50;
public Texture2D rings30;
public Texture2D rings0;
[Header("ʳëüöÿ")]
public Renderer ringsRenderer;
[Range(0f, 1f)]
public float troposphereLevel = 1f;
public float stratosphereLevel = 1f;
public float thermosphereLevel = 1f;
public float exosphereLevel = 1f;
private Renderer _planetRenderer;
private Material _planetMat;
private Material _ringsMat;
private Texture2D _originalTexture;
private Texture2D _originalTexture2;
private Texture2D _originalRingsTexture;
void Start()
{
_planetRenderer = GetComponent<Renderer>();
if (_planetRenderer == null)
_planetRenderer = GetComponentInChildren<Renderer>();
if (_planetRenderer != null)
{
_planetMat = _planetRenderer.material;
_originalTexture = (Texture2D)_planetMat.GetTexture("_BaseMap");
_originalTexture2 = (Texture2D)_planetMat.GetTexture("_BaseMap2");
}
if (ringsRenderer != null)
{
_ringsMat = ringsRenderer.material;
_originalRingsTexture = (Texture2D)_ringsMat.GetTexture("_BaseMap");
}
}
public void ResetTexture()
{
troposphereLevel = 1f;
stratosphereLevel = 1f;
thermosphereLevel = 1f;
exosphereLevel = 1f;
if (_planetMat != null)
{
if (_originalTexture != null)
_planetMat.SetTexture("_BaseMap", _originalTexture);
if (_originalTexture2 != null)
_planetMat.SetTexture("_BaseMap2", _originalTexture2);
}
if (_ringsMat != null && _originalRingsTexture != null)
_ringsMat.SetTexture("_BaseMap", _originalRingsTexture);
}
void Update()
{
if (_planetMat == null) return;
UpdatePlanetTexture();
UpdateRingsTexture();
}
void UpdatePlanetTexture()
{
float worst = Mathf.Min(troposphereLevel, stratosphereLevel, thermosphereLevel, exosphereLevel);
if (worst >= 1f)
{
if (_originalTexture != null)
_planetMat.SetTexture("_BaseMap", _originalTexture);
if (_originalTexture2 != null)
_planetMat.SetTexture("_BaseMap2", _originalTexture2);
return;
}
Texture2D tex = worst <= 0f ? deadTexture : GetPlanetTexture(worst);
Texture2D tex2 = worst <= 0f ? deadTextureB : GetPlanetTexture2(worst);
if (tex != null)
_planetMat.SetTexture("_BaseMap", tex);
if (tex2 != null)
_planetMat.SetTexture("_BaseMap2", tex2);
}
void UpdateRingsTexture()
{
if (_ringsMat == null) return;
float worst = Mathf.Min(troposphereLevel, stratosphereLevel, thermosphereLevel, exosphereLevel);
if (worst >= 1f)
{
if (_originalRingsTexture != null)
_ringsMat.SetTexture("_BaseMap", _originalRingsTexture);
return;
}
Texture2D tex = worst <= 0f ? rings0 : GetRingsTexture(worst);
if (tex != null)
_ringsMat.SetTexture("_BaseMap", tex);
}
Texture2D GetPlanetTexture(float level)
{
if (level >= 0.7f) return tropo100;
else if (level >= 0.5f) return tropo70;
else if (level >= 0.3f) return tropo50;
else if (level > 0f) return tropo30;
else return tropo0;
}
Texture2D GetPlanetTexture2(float level)
{
if (level >= 0.7f) return tropo100B;
else if (level >= 0.5f) return tropo70B;
else if (level >= 0.3f) return tropo50B;
else if (level > 0f) return tropo30B;
else return tropo0B;
}
Texture2D GetRingsTexture(float level)
{
if (level >= 0.7f) return rings100;
else if (level >= 0.5f) return rings70;
else if (level >= 0.3f) return rings50;
else if (level > 0f) return rings30;
else return rings0;
}
}