PolyverseSkies.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using Boxophobic.StyledGUI;
  4. [DisallowMultipleComponent]
  5. [ExecuteInEditMode]
  6. public class PolyverseSkies : StyledMonoBehaviour
  7. {
  8. [StyledBanner(0.968f, 0.572f, 0.890f, "Polyverse Skies", "", "https://docs.google.com/document/d/1z7A_xKNa2mXhvTRJqyu-ZQsAtbV32tEZQbO1OmPS_-s/edit?usp=sharing")]
  9. public bool styledBanner;
  10. [StyledCategory("Scene", 5, 10)]
  11. public bool categoryScene;
  12. public GameObject sunDirection;
  13. public GameObject moonDirection;
  14. [StyledCategory("Time Of Day")]
  15. public bool categoryTime;
  16. [StyledMessage("Info", "The Time Of Day feature will interpolate between two Polyverse Skies materials. Please note that not all material properties such as textures and keywords will not be interpolated! Toggle Update Lighting to enable Unity's realtime environment lighting!", 0, 10)]
  17. public bool categoryTimeMessage = true;
  18. public Material skyboxDay;
  19. public Material skyboxNight;
  20. [Range(0, 1)]
  21. public float timeOfDay = 0;
  22. [Space(10)]
  23. public bool updateLighting = false;
  24. [StyledSpace(5)]
  25. public bool styledSpace0;
  26. void Update ()
  27. {
  28. if (sunDirection != null)
  29. {
  30. Shader.SetGlobalVector ("GlobalSunDirection", -sunDirection.transform.forward);
  31. }
  32. else
  33. {
  34. Shader.SetGlobalVector ("GlobalSunDirection", Vector3.zero);
  35. }
  36. if (moonDirection != null)
  37. {
  38. Shader.SetGlobalVector ("GlobalMoonDirection", -moonDirection.transform.forward);
  39. }
  40. else
  41. {
  42. Shader.SetGlobalVector ("GlobalMoonDirection", Vector3.zero);
  43. }
  44. if (skyboxDay != null && skyboxNight != null)
  45. {
  46. Material skyboxMaterial = new Material(skyboxDay);
  47. skyboxMaterial.Lerp(skyboxDay, skyboxNight, timeOfDay);
  48. RenderSettings.skybox = skyboxMaterial;
  49. }
  50. if (updateLighting)
  51. {
  52. DynamicGI.UpdateEnvironment();
  53. }
  54. }
  55. }