| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityStandardAssets.ImageEffects;
- public class DayToNight : MonoBehaviour
- {
- [SerializeField] Material daySkyboxMaterial;
- [SerializeField] Material nightSkyboxMaterial;
- [SerializeField] Camera[] cameras;
- void Awake()
- {
- if (GameMgr.gameType == 5) {
- EnterNight();
- } else {
- EnterDay();
- }
- }
- public void EnterDay()
- {
- RenderSettings.fogStartDistance = 25;
- RenderSettings.fogColor = new Color(124f/255, 177f/255, 221f/255);
- RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;
- RenderSettings.ambientSkyColor = Color.white;
- RenderSettings.skybox = daySkyboxMaterial;
- foreach (Transform item in transform) item.gameObject.SetActive(false);
- transform.Find("DayElements").gameObject.SetActive(true);
- SetFogCamera(false);
- }
- public void EnterNight()
- {
- RenderSettings.fogStartDistance = 5;
- RenderSettings.fogColor = new Color(37f/255, 52f/255, 63f/255);
- RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;
- RenderSettings.ambientSkyColor = new Color(160f/255, 90f/255, 90f/255);
- RenderSettings.skybox = nightSkyboxMaterial;
- foreach (Transform item in transform) item.gameObject.SetActive(false);
- transform.Find("NightElements").gameObject.SetActive(true);
- SetFogCamera(true);
- }
- public void SetFogCamera(bool setValue)
- {
- Component[] components = {
- cameras[0].GetComponent<VignetteAndChromaticAberration>(),
- cameras[0].GetComponent<ScreenSpaceAmbientObscurance>(),
- cameras[0].GetComponent<GlobalFog>()
- };
- foreach (var comp in components) {
- for (int i = 1; i < cameras.Length; i++) {
- Camera camera = cameras[i];
- CopyComponent(comp, camera.gameObject);
- }
- }
- foreach (var item in cameras)
- {
- item.GetComponent<VignetteAndChromaticAberration>().enabled = setValue;
- item.GetComponent<ScreenSpaceAmbientObscurance>().enabled = setValue;
- item.GetComponent<GlobalFog>().enabled = setValue;
- }
- }
- void CopyComponent(Component comp, GameObject dest)
- {
- System.Type type = comp.GetType();
- Component copy = dest.GetComponent(type);
- if (copy == null) {
- copy = dest.AddComponent(type);
- }
- System.Reflection.FieldInfo[] fields = type.GetFields();
- foreach (System.Reflection.FieldInfo field in fields)
- {
- field.SetValue(copy, field.GetValue(comp));
- }
- }
- }
|