Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Kopernicus.MaterialWrapper;
- using System;
- using UnityEngine;
- namespace RandomRecolorPlugin
- {
- namespace Components
- {
- public class RandomRecolor : MonoBehaviour
- {
- public Color randomColor = new Color(1.5f, 1.5f, 1.5f, 1);
- void Start()
- {
- CelestialBody body = GetComponent<CelestialBody>();
- randomColor = new Color(2,0.1f,0.1f,1);
- Debug.Log("RRLOG: planet = " + body.name);
- Debug.Log("RRLOG: randomColor = " + randomColor);
- // ScaledVersion Texture Color
- body.scaledBody.GetComponent<Renderer>().material.color =
- new Color
- (
- body.scaledBody.GetComponent<Renderer>().material.color.r * randomColor.r,
- body.scaledBody.GetComponent<Renderer>().material.color.g * randomColor.g,
- body.scaledBody.GetComponent<Renderer>().material.color.b * randomColor.b,
- body.scaledBody.GetComponent<Renderer>().material.color.a
- );
- // Atmosphere ambientColor
- body.atmosphericAmbientColor =
- new Color
- (
- body.atmosphericAmbientColor.r * randomColor.r,
- body.atmosphericAmbientColor.g * randomColor.g,
- body.atmosphericAmbientColor.b * randomColor.b,
- body.atmosphericAmbientColor.a
- );
- // Atmosphere lightColor
- body.scaledBody.GetComponentsInChildren<AtmosphereFromGround> (true) [0].waveLength =
- new Color
- (
- body.scaledBody.GetComponentsInChildren<AtmosphereFromGround>(true)[0].waveLength.r * (float)Math.Pow(randomColor.r, -0.25d),
- body.scaledBody.GetComponentsInChildren<AtmosphereFromGround>(true)[0].waveLength.g * (float)Math.Pow(randomColor.g, -0.25d),
- body.scaledBody.GetComponentsInChildren<AtmosphereFromGround>(true)[0].waveLength.b * (float)Math.Pow(randomColor.b, -0.25d),
- body.scaledBody.GetComponentsInChildren<AtmosphereFromGround>(true)[0].waveLength.a
- );
- Renderer r = body.scaledBody.GetComponent<Renderer>();
- ScaledPlanetRimAerial material = new ScaledPlanetRimAerial(r.material);
- r.material = material;
- Texture2D ramp = new Texture2D(512, 1);
- ramp = material.rimColorRamp;
- for (int i = 0; i < ramp.width; i++)
- {
- ramp.SetPixel
- (
- i, 1, // x,y coordinates
- new Color
- (
- ramp.GetPixel(i, 0).r * (float)randomColor.r,
- ramp.GetPixel(i, 0).g * (float)randomColor.g,
- ramp.GetPixel(i, 0).b * (float)randomColor.b,
- ramp.GetPixel(i, 0).a
- )
- );
- }
- material.rimColorRamp = ramp;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement