using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; public class ReflectionProbesUpdater : MonoBehaviour { [SerializeField] List _reflectionProbesToUpdate; //[SerializeField] List _allReflectionsProbes; public static ReflectionProbesUpdater Instance { get; private set; } [SerializeField] ReflectionProbe _reflectionProbeNormal; public static ReflectionProbe ReflectionProbeNormal { get { return Instance._reflectionProbeNormal; } } [SerializeField] ReflectionProbe _reflectionProbeExterior; public static ReflectionProbe ReflectionProbeExterior { get { return Instance._reflectionProbeExterior; } } [SerializeField] ReflectionProbe _reflectionNone; public static ReflectionProbe ReflectionNone { get { return Instance._reflectionNone; } } [SerializeField] ReflectionProbe _reflectionStainless; public static ReflectionProbe ReflectionStainless { get { return Instance._reflectionStainless; } } [SerializeField] GameObject _onOff; public static GameObject OnOff { get { return Instance._onOff; } } [SerializeField] GameObject _directionalLight; public static GameObject DirectionalLight { get { return Instance._directionalLight; } } private void Awake() { if(Instance == null) { Instance = this; } else { Destroy(this.gameObject); } } void SetProbeToRefreshMode(ReflectionProbeRefreshMode refreshMode) { foreach (var probe in _reflectionProbesToUpdate) { // set the probe to update via script refresh mode probe.mode = ReflectionProbeMode.Realtime; probe.refreshMode = refreshMode; probe.timeSlicingMode = ReflectionProbeTimeSlicingMode.AllFacesAtOnce; } } public static void UpdateProbesStatic() { Instance.UpdateProbes(); } public void UpdateProbes() { if(!_G.HD)return; //Debug.Log("Updating probes"); // forces the probes to update foreach (var probe in _reflectionProbesToUpdate) { if (!probe.isActiveAndEnabled) { continue; } //Debug.Log("Updating " + probe); probe.RenderProbe(); } } public static void OnHdTurnedOn() { StaticCoroutine.Start(Instance.UpdateProbesOnAwakeOnce()); } public IEnumerator UpdateProbesOnAwakeOnce() { SetProbeToRefreshMode(ReflectionProbeRefreshMode.EveryFrame); yield return new WaitForSeconds(0.1f); SetProbeToRefreshMode(ReflectionProbeRefreshMode.ViaScripting); } //public void ResizeReflectionProbes() //{ // Vector3 roomSize = GetRoomSize(); // foreach (var probe in _allReflectionsProbes) // { // probe.size = roomSize; // } //} //public Vector3 GetRoomSize() //{ // float minX = float.PositiveInfinity; // float maxX = float.NegativeInfinity; // float minZ = float.PositiveInfinity; // float maxZ = float.NegativeInfinity; // float y = _G.HEIGHT; // for(int i = 0; i < _G.WALL.Length; i++) // { // Vector3 pos = _G.WALL[i].transform.position; // minX = Mathf.Min(minX, pos.x); // maxX = Mathf.Max(maxX, pos.x); // minZ = Mathf.Min(minZ, pos.z); // maxZ = Mathf.Max(maxZ, pos.z); // } // return new Vector3(Mathf.Abs(maxX - minX)+ 10, y, Mathf.Abs(maxZ - minZ)) + Vector3.one * 10f; //} }