initial commit
This commit is contained in:
150
Assets/Scripts/JupiterAtmosphereSystem.cs
Normal file
150
Assets/Scripts/JupiterAtmosphereSystem.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteAlways]
|
||||
public class JupiterAtmosphereSystem : MonoBehaviour
|
||||
{
|
||||
public float jupiterRadiusUnits = 7.1492f;
|
||||
public float heightMultiplier = 8f;
|
||||
|
||||
[Header("Òåêñòóðè äëÿ òðîïîñôåðè ³ ñòðàòîñôåðè")]
|
||||
public Texture2D jupiterTexture1;
|
||||
public Texture2D jupiterTexture2;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (!Application.isPlaying && transform.childCount == 0)
|
||||
BuildLayers();
|
||||
}
|
||||
|
||||
[ContextMenu("Ïåðåáóäóâàòè øàðè")]
|
||||
public void BuildLayers()
|
||||
{
|
||||
for (int i = transform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
Transform child = transform.GetChild(i);
|
||||
if (child.name.StartsWith("Layer_"))
|
||||
{
|
||||
if (Application.isPlaying) Destroy(child.gameObject);
|
||||
else DestroyImmediate(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
CreateTextureLayer("Layer_Troposphere", 300f,
|
||||
new Color(0.7f, 0.4f, 0.15f),
|
||||
new Color(0.5f, 0.25f, 0.08f),
|
||||
2.0f, 0.6f, 0.02f, -0.01f);
|
||||
|
||||
CreateTextureLayer("Layer_Stratosphere", 600f,
|
||||
new Color(0.85f, 0.7f, 0.4f),
|
||||
new Color(0.6f, 0.5f, 0.2f),
|
||||
1.5f, 0.4f, 0.015f, -0.008f);
|
||||
|
||||
CreateSimpleLayer("Layer_Thermosphere", 900f,
|
||||
new Color(0.4f, 0.3f, 0.8f),
|
||||
new Color(0.2f, 0.1f, 0.5f),
|
||||
1.0f, 0.2f);
|
||||
|
||||
CreateSimpleLayer("Layer_Exosphere", 1200f,
|
||||
new Color(0.6f, 0.5f, 0.9f),
|
||||
new Color(0.3f, 0.2f, 0.6f),
|
||||
0.6f, 0.1f);
|
||||
}
|
||||
|
||||
void CreateTextureLayer(string layerName, float heightKm,
|
||||
Color rimColor, Color coreColor,
|
||||
float rimIntensity, float coreIntensity,
|
||||
float scrollSpeed1, float scrollSpeed2)
|
||||
{
|
||||
float radiusUnits = jupiterRadiusUnits + (heightKm / 1000f) * heightMultiplier;
|
||||
|
||||
GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
obj.name = layerName;
|
||||
obj.transform.parent = this.transform;
|
||||
obj.transform.localPosition = Vector3.zero;
|
||||
obj.transform.localScale = Vector3.one * radiusUnits * 2f;
|
||||
|
||||
if (Application.isPlaying) Destroy(obj.GetComponent<Collider>());
|
||||
else DestroyImmediate(obj.GetComponent<Collider>());
|
||||
|
||||
Material mat = new Material(Shader.Find("Custom/JupiterAtmosphereLayer"));
|
||||
mat.SetColor("_RimColor", rimColor);
|
||||
mat.SetColor("_CoreColor", coreColor);
|
||||
mat.SetFloat("_RimPower", 2.0f);
|
||||
mat.SetFloat("_RimIntensity", rimIntensity);
|
||||
mat.SetFloat("_CoreIntensity", coreIntensity);
|
||||
mat.SetFloat("_ScrollSpeed1", scrollSpeed1);
|
||||
mat.SetFloat("_ScrollSpeed2", scrollSpeed2);
|
||||
mat.SetFloat("_PulseSpeed", 0.3f);
|
||||
mat.SetFloat("_PulseStrength", 0.1f);
|
||||
mat.SetFloat("_TextureBlend", 0.5f);
|
||||
mat.SetFloat("_TextureInfluence", 0.5f);
|
||||
|
||||
if (jupiterTexture1 != null) mat.SetTexture("_MainTex", jupiterTexture1);
|
||||
if (jupiterTexture2 != null) mat.SetTexture("_SecondTex", jupiterTexture2);
|
||||
|
||||
obj.GetComponent<Renderer>().material = mat;
|
||||
}
|
||||
|
||||
void CreateSimpleLayer(string layerName, float heightKm,
|
||||
Color rimColor, Color coreColor,
|
||||
float rimIntensity, float coreIntensity)
|
||||
{
|
||||
float radiusUnits = jupiterRadiusUnits + (heightKm / 1000f) * heightMultiplier;
|
||||
|
||||
GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
obj.name = layerName;
|
||||
obj.transform.parent = this.transform;
|
||||
obj.transform.localPosition = Vector3.zero;
|
||||
obj.transform.localScale = Vector3.one * radiusUnits * 2f;
|
||||
|
||||
if (Application.isPlaying) Destroy(obj.GetComponent<Collider>());
|
||||
else DestroyImmediate(obj.GetComponent<Collider>());
|
||||
|
||||
Material mat = new Material(Shader.Find("Custom/AtmosphereLayer"));
|
||||
mat.SetColor("_RimColor", rimColor);
|
||||
mat.SetColor("_CoreColor", coreColor);
|
||||
mat.SetFloat("_RimPower", 2.0f);
|
||||
mat.SetFloat("_RimIntensity", rimIntensity);
|
||||
mat.SetFloat("_CoreIntensity", coreIntensity);
|
||||
mat.SetFloat("_PulseSpeed", 0.3f);
|
||||
mat.SetFloat("_PulseStrength", 0.1f);
|
||||
|
||||
obj.GetComponent<Renderer>().material = mat;
|
||||
}
|
||||
|
||||
public void SetLayerIntensity(string layerName, float level)
|
||||
{
|
||||
Transform layer = transform.Find(layerName);
|
||||
if (layer == null) return;
|
||||
Renderer r = layer.GetComponent<Renderer>();
|
||||
if (r == null) return;
|
||||
|
||||
float rimBase = 0f;
|
||||
float coreBase = 0f;
|
||||
|
||||
switch (layerName)
|
||||
{
|
||||
case "Layer_Troposphere": rimBase = 2.0f; coreBase = 0.6f; break;
|
||||
case "Layer_Stratosphere": rimBase = 1.5f; coreBase = 0.4f; break;
|
||||
case "Layer_Thermosphere": rimBase = 1.0f; coreBase = 0.2f; break;
|
||||
case "Layer_Exosphere": rimBase = 0.6f; coreBase = 0.1f; break;
|
||||
}
|
||||
|
||||
r.material.SetFloat("_RimIntensity", Mathf.Lerp(0f, rimBase, level));
|
||||
r.material.SetFloat("_CoreIntensity", Mathf.Lerp(0f, coreBase, level));
|
||||
}
|
||||
|
||||
public void SetLayerActive(string layerName, bool active)
|
||||
{
|
||||
Transform layer = transform.Find(layerName);
|
||||
if (layer != null) layer.gameObject.SetActive(active);
|
||||
}
|
||||
|
||||
public void SetIntensity(float level)
|
||||
{
|
||||
SetLayerIntensity("Layer_Troposphere", level);
|
||||
SetLayerIntensity("Layer_Stratosphere", level);
|
||||
SetLayerIntensity("Layer_Thermosphere", level);
|
||||
SetLayerIntensity("Layer_Exosphere", level);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user