HomeSunLight.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Experimental.Rendering;
  5. using UnityEngine.Rendering;
  6. public class HomeSunLight : MonoBehaviour
  7. {
  8. // Start is called before the first frame update
  9. public float rotationSpeed = 30f;
  10. public Transform rotateObj;
  11. public Transform targetObj;
  12. public Light rotateLight;
  13. public GameObject targetCamera;
  14. public Material daySkybox;
  15. public Material nightSkybox;
  16. void Start()
  17. {
  18. GameObject homeLight = GameObject.Find("Home Light");
  19. int hour = System.DateTime.Now.Hour;
  20. //hour = 7;
  21. float rotateAngle = (12 - hour) * 13;
  22. //print(rotateAngle);
  23. if ( hour >=22 || hour < 5) // Éîҹʱ¼ä
  24. {
  25. rotateLight.intensity = 0.1f;
  26. //targetCamera.GetComponent<Camera>().backgroundColor = new Color(22, 42, 113, 239);
  27. UnityEngine.RenderSettings.skybox = nightSkybox;
  28. UnityEngine.RenderSettings.ambientIntensity = 0.2f;
  29. UnityEngine.RenderSettings.reflectionIntensity = 0.2f;
  30. homeLight.GetComponent<Light>().intensity = 0.3f;
  31. }
  32. else if (hour < 6 || hour >= 18)
  33. {
  34. // night time
  35. rotateLight.intensity = 0.1f;
  36. //targetCamera.GetComponent<Camera>().backgroundColor = new Color(22, 42, 113, 239);
  37. UnityEngine.RenderSettings.skybox = nightSkybox;
  38. UnityEngine.RenderSettings.ambientIntensity = 0.2f;
  39. UnityEngine.RenderSettings.reflectionIntensity = 0.2f;
  40. homeLight.GetComponent<Light>().intensity = 1f;
  41. }
  42. else
  43. {
  44. Debug.Log("day time");
  45. // day time
  46. rotateLight.intensity = 0.7f;
  47. //targetCamera.GetComponent<Camera>().clearFlags = CameraClearFlags.SolidColor;
  48. //targetCamera.GetComponent<Camera>().backgroundColor = new Color(139, 202, 255, 203);
  49. UnityEngine.RenderSettings.skybox = daySkybox;
  50. UnityEngine.RenderSettings.ambientIntensity = 0.9f;
  51. UnityEngine.RenderSettings.reflectionIntensity = 1f;
  52. homeLight.GetComponent<Light>().intensity = 1f;
  53. rotateObj.RotateAround(targetObj.transform.position, Vector3.forward, rotateAngle);
  54. }
  55. DynamicGI.UpdateEnvironment();
  56. }
  57. // Update is called once per frame
  58. void Update()
  59. {
  60. }
  61. }