initial commit
This commit is contained in:
67
Assets/Scripts/MercuryAtmosphereSystem.cs
Normal file
67
Assets/Scripts/MercuryAtmosphereSystem.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using UnityEngine;
|
||||
|
||||
[ExecuteAlways]
|
||||
public class MercuryAtmosphereSystem : MonoBehaviour
|
||||
{
|
||||
public float mercuryRadiusUnits = 2.4395f;
|
||||
public float heightMultiplier = 8f;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
CreateLayer();
|
||||
}
|
||||
|
||||
void CreateLayer()
|
||||
{
|
||||
float radiusUnits = mercuryRadiusUnits + (2000f / 1000f) * heightMultiplier;
|
||||
|
||||
GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
obj.name = "Layer_Exosphere";
|
||||
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", new Color(1f, 0.75f, 0.2f));
|
||||
mat.SetColor("_CoreColor", new Color(0.8f, 0.4f, 0.0f));
|
||||
mat.SetFloat("_RimPower", 1.8f);
|
||||
mat.SetFloat("_RimIntensity", 4f);
|
||||
mat.SetFloat("_CoreIntensity", 0.8f);
|
||||
mat.SetFloat("_PulseSpeed", 0.5f);
|
||||
mat.SetFloat("_PulseStrength", 0.3f);
|
||||
|
||||
obj.GetComponent<Renderer>().material = mat;
|
||||
}
|
||||
|
||||
public void SetIntensity(float level)
|
||||
{
|
||||
Transform layer = transform.Find("Layer_Exosphere");
|
||||
if (layer == null) return;
|
||||
|
||||
Renderer r = layer.GetComponent<Renderer>();
|
||||
if (r == null) return;
|
||||
|
||||
r.material.SetFloat("_RimIntensity", Mathf.Lerp(0f, 4f, level));
|
||||
r.material.SetFloat("_CoreIntensity", Mathf.Lerp(0f, 0.8f, level));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user