Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. using Kopernicus.MaterialWrapper;
  2. using System;
  3. using UnityEngine;
  4.  
  5.  
  6. namespace RandomRecolorPlugin
  7. {
  8. namespace Components
  9. {
  10. public class RandomRecolor : MonoBehaviour
  11. {
  12. public Color randomColor = new Color(1.5f, 1.5f, 1.5f, 1);
  13.  
  14. void Start()
  15. {
  16. CelestialBody body = GetComponent<CelestialBody>();
  17. randomColor = new Color(2,0.1f,0.1f,1);
  18. Debug.Log("RRLOG: planet = " + body.name);
  19. Debug.Log("RRLOG: randomColor = " + randomColor);
  20.  
  21. // ScaledVersion Texture Color
  22. body.scaledBody.GetComponent<Renderer>().material.color =
  23. new Color
  24. (
  25. body.scaledBody.GetComponent<Renderer>().material.color.r * randomColor.r,
  26. body.scaledBody.GetComponent<Renderer>().material.color.g * randomColor.g,
  27. body.scaledBody.GetComponent<Renderer>().material.color.b * randomColor.b,
  28. body.scaledBody.GetComponent<Renderer>().material.color.a
  29. );
  30.  
  31. // Atmosphere ambientColor
  32. body.atmosphericAmbientColor =
  33. new Color
  34. (
  35. body.atmosphericAmbientColor.r * randomColor.r,
  36. body.atmosphericAmbientColor.g * randomColor.g,
  37. body.atmosphericAmbientColor.b * randomColor.b,
  38. body.atmosphericAmbientColor.a
  39. );
  40.  
  41. // Atmosphere lightColor
  42. body.scaledBody.GetComponentsInChildren<AtmosphereFromGround> (true) [0].waveLength =
  43. new Color
  44. (
  45. body.scaledBody.GetComponentsInChildren<AtmosphereFromGround>(true)[0].waveLength.r * (float)Math.Pow(randomColor.r, -0.25d),
  46. body.scaledBody.GetComponentsInChildren<AtmosphereFromGround>(true)[0].waveLength.g * (float)Math.Pow(randomColor.g, -0.25d),
  47. body.scaledBody.GetComponentsInChildren<AtmosphereFromGround>(true)[0].waveLength.b * (float)Math.Pow(randomColor.b, -0.25d),
  48. body.scaledBody.GetComponentsInChildren<AtmosphereFromGround>(true)[0].waveLength.a
  49. );
  50.  
  51. Renderer r = body.scaledBody.GetComponent<Renderer>();
  52. ScaledPlanetRimAerial material = new ScaledPlanetRimAerial(r.material);
  53. r.material = material;
  54. Texture2D ramp = new Texture2D(512, 1);
  55. ramp = material.rimColorRamp;
  56. for (int i = 0; i < ramp.width; i++)
  57. {
  58. ramp.SetPixel
  59. (
  60. i, 1, // x,y coordinates
  61. new Color
  62. (
  63. ramp.GetPixel(i, 0).r * (float)randomColor.r,
  64. ramp.GetPixel(i, 0).g * (float)randomColor.g,
  65. ramp.GetPixel(i, 0).b * (float)randomColor.b,
  66. ramp.GetPixel(i, 0).a
  67. )
  68. );
  69. }
  70. material.rimColorRamp = ramp;
  71. }
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement