private void InitEnvironmentEffects() { Config = Loader.Instance?.SimConfig; sunGO = Instantiate(sunGO, new Vector3(0f, 50f, 0f), Quaternion.Euler(90f, 0f, 0f)); sun = sunGO.GetComponent <Light>(); var dt = DateTime.Now; ResetTime(new DateTime(dt.Year, dt.Month, dt.Day, 12, 0, 0)); Reset(); PostPrecessingVolume = Instantiate(PostProcessingVolumePrefab); ActiveProfile = PostPrecessingVolume.profile; ActiveProfile.TryGet(out volumetricFog); clouds = Instantiate(CloudPrefab, new Vector3(0f, 0f, 0f), Quaternion.identity); cloudRenderer = clouds.GetComponentInChildren <Renderer>(); //ActiveProfile.TryGet(out activeOverrides.proceduralSky); //ActiveProfile.TryGet(out activeOverrides.tonemapping); //ActiveProfile.TryGet(out activeOverrides.exposure); //ActiveProfile.TryGet(out activeOverrides.whiteBalance); //ActiveProfile.TryGet(out activeOverrides.colorAdjustments); //ActiveProfile.TryGet(out activeOverrides.IndirectLightingController); //DayProfile.TryGet(out dayOverrides.proceduralSky); //DayProfile.TryGet(out dayOverrides.tonemapping); //DayProfile.TryGet(out dayOverrides.exposure); //DayProfile.TryGet(out dayOverrides.whiteBalance); //DayProfile.TryGet(out dayOverrides.colorAdjustments); //DayProfile.TryGet(out dayOverrides.IndirectLightingController); //NightProfile.TryGet(out nightOverrides.proceduralSky); //NightProfile.TryGet(out nightOverrides.tonemapping); //NightProfile.TryGet(out nightOverrides.exposure); //NightProfile.TryGet(out nightOverrides.whiteBalance); //NightProfile.TryGet(out nightOverrides.colorAdjustments); //NightProfile.TryGet(out nightOverrides.IndirectLightingController); //SetRiseProfile.TryGet(out setRiseOverrides.proceduralSky); //SetRiseProfile.TryGet(out setRiseOverrides.tonemapping); //SetRiseProfile.TryGet(out setRiseOverrides.exposure); //SetRiseProfile.TryGet(out setRiseOverrides.whiteBalance); //SetRiseProfile.TryGet(out setRiseOverrides.colorAdjustments); //SetRiseProfile.TryGet(out setRiseOverrides.IndirectLightingController); rainVolumes.AddRange(FindObjectsOfType <RainVolume>()); foreach (var volume in rainVolumes) { rainPfxs.Add(volume.Init(rainPfx, RandomGenerator.Next())); } // TODO mem issue //RainEffect = Instantiate(RainEffectPrefab, Vector3.zero, Quaternion.identity); //ActiveRainVfxs.AddRange(RainEffect.GetComponentsInChildren<VisualEffect>()); //RaycastHit hit; //var seed = Convert.ToUInt32(RandomGenerator.Next()); //for (int i = 0; i < ActiveRainVfxs.Count; i++) //{ // ActiveRainVfxs[i].SetFloat("_RainfallAmount", 0f); // ActiveRainVfxs[i].startSeed = seed; // var fxBounds = ActiveRainVfxs[i].GetVector3("_RainfallFXBounds"); // var wp = ActiveRainVfxs[i].transform.position; // Vector3[] boundsToCheck = // { // new Vector3(wp.x + fxBounds.x/2f, fxBounds.y, wp.z + fxBounds.z/2f), // new Vector3(wp.x + fxBounds.x/2f, fxBounds.y, wp.z - fxBounds.z/2f), // new Vector3(wp.x - fxBounds.x/2f, fxBounds.y, wp.z - fxBounds.z/2f), // new Vector3(wp.x - fxBounds.x/2f, fxBounds.y, wp.z + fxBounds.z/2f) // }; // bool isHit = false; // foreach (var pt in boundsToCheck) // { // if (Physics.Raycast(pt, ActiveRainVfxs[i].transform.TransformDirection(Vector3.down), out hit, Mathf.Infinity)) // { // isHit = true; // continue; // } // } // if (!isHit) // { // ActiveRainVfxs[i].Stop(); // ActiveRainVfxs[i].enabled = false; // } //} wetObjects.AddRange(GameObject.FindGameObjectsWithTag("Road")); wetObjects.AddRange(GameObject.FindGameObjectsWithTag("Sidewalk")); var renderers = new List <Renderer>(); var materials = new List <Material>(); foreach (var obj in wetObjects) { obj.GetComponentsInChildren(renderers); renderers.ForEach(r => { r.GetSharedMaterials(materials); materials.ForEach(m => { if (r.GetComponent <ParticleSystem>() != null || r.GetComponent <ReflectionProbe>() != null) { return; } if (m == null) { Debug.Log($"Object {r.gameObject.name} has null material", r.gameObject); return; } else { wetMaterials.Add(m); } }); }); } SetWet(); timeOfDayLights.AddRange(FindObjectsOfType <TimeOfDayLight>()); timeOfDayLights.ForEach(x => x.Init(currentTimeOfDayState)); Array.ForEach(FindObjectsOfType <TimeOfDayBuilding>(), x => x.Init(currentTimeOfDayState)); TimeOfDayCycle(); }
private void InitEnvironmentEffects() { Config = Loader.Instance?.SimConfig; Sun = Instantiate(SunGO, new Vector3(0f, 50f, 0f), Quaternion.Euler(90f, 0f, 0f)).GetComponent <Light>(); SunHD = Sun.gameObject.GetComponent <HDAdditionalLightData>(); Moon = Instantiate(MoonGO, new Vector3(0f, 50f, 0f), Quaternion.Euler(90f, 0f, 0f)).GetComponent <Light>(); MoonHD = Moon.gameObject.GetComponent <HDAdditionalLightData>(); // AD Stack needs -90 degree map rotation so celestial bodies need rotated var CelestialBodyHolder = new GameObject("CelestialBodyHolder"); CelestialBodyHolder.transform.SetPositionAndRotation(Vector3.zero, Quaternion.Euler(0f, -90f, 0f)); Sun.transform.SetParent(CelestialBodyHolder.transform); Moon.transform.SetParent(CelestialBodyHolder.transform); Reset(); PostPrecessingVolume = Instantiate(PostProcessingVolumePrefab); ActiveProfile = PostPrecessingVolume.profile; ActiveProfile.TryGet(out VolumetricFog); ActiveProfile.TryGet(out PBS); CloudRenderer = Instantiate(CloudPrefab, new Vector3(0f, 0f, 0f), Quaternion.identity).GetComponentInChildren <Renderer>(); VFXRain = Instantiate(VFXRainPrefab); var origin = MapOrigin.Find(); var trans = VFXRain.transform; var pos = trans.position; pos.y += origin.transform.position.y; trans.position = pos; var agents = SimulatorManager.Instance.AgentManager.ActiveAgents; foreach (var agent in agents) { VFXRain.RegisterTrackedEntity(agent.AgentGO.transform); } WetObjects.AddRange(GameObject.FindGameObjectsWithTag("Road")); WetObjects.AddRange(GameObject.FindGameObjectsWithTag("Sidewalk")); var renderers = new List <Renderer>(); var materials = new List <Material>(); foreach (var obj in WetObjects) { obj.GetComponentsInChildren(renderers); renderers.ForEach(r => { r.GetMaterials(materials); materials.ForEach(m => { if (r.GetComponent <ParticleSystem>() != null || r.GetComponent <ReflectionProbe>() != null) { return; } if (m == null) { Debug.Log($"Object {r.gameObject.name} has null material", r.gameObject); return; } else { WetMaterials.Add(m); } }); }); } UpdateWet(); DamageObjects.AddRange(GameObject.FindGameObjectsWithTag("Road")); renderers.Clear(); materials.Clear(); foreach (var obj in DamageObjects) { obj.GetComponentsInChildren(renderers); renderers.ForEach(r => { r.GetMaterials(materials); materials.ForEach(m => { if (r.GetComponent <ParticleSystem>() != null || r.GetComponent <ReflectionProbe>() != null) { return; } if (m == null) { Debug.Log($"Object {r.gameObject.name} has null material", r.gameObject); return; } else { DamageMaterials.Add(m); } }); }); } UpdateDamage(); TimeOfDayLights.AddRange(FindObjectsOfType <TimeOfDayLight>()); TimeOfDayLights.ForEach(x => x.Init(CurrentTimeOfDayState)); Array.ForEach(FindObjectsOfType <TimeOfDayBuilding>(), x => x.Init(CurrentTimeOfDayState)); TimeOfDayCycle(); }
private void InitEnvironmentEffects() { sunGO = Instantiate(sunGO, new Vector3(0f, 50f, 0f), Quaternion.Euler(90f, 0f, 0f)); sun = sunGO.GetComponent <Light>(); var dt = DateTime.Now; ResetTime(new DateTime(dt.Year, dt.Month, dt.Day, 12, 0, 0)); Reset(); PostPrecessingVolume = Instantiate(PostProcessingVolumePrefab); ActiveProfile = PostPrecessingVolume.profile; ActiveProfile.TryGet(out activeOverrides.proceduralSky); ActiveProfile.TryGet(out activeOverrides.tonemapping); ActiveProfile.TryGet(out activeOverrides.exposure); ActiveProfile.TryGet(out activeOverrides.whiteBalance); ActiveProfile.TryGet(out activeOverrides.colorAdjustments); ActiveProfile.TryGet(out activeOverrides.IndirectLightingController); DayProfile.TryGet(out dayOverrides.proceduralSky); DayProfile.TryGet(out dayOverrides.tonemapping); DayProfile.TryGet(out dayOverrides.exposure); DayProfile.TryGet(out dayOverrides.whiteBalance); DayProfile.TryGet(out dayOverrides.colorAdjustments); DayProfile.TryGet(out dayOverrides.IndirectLightingController); NightProfile.TryGet(out nightOverrides.proceduralSky); NightProfile.TryGet(out nightOverrides.tonemapping); NightProfile.TryGet(out nightOverrides.exposure); NightProfile.TryGet(out nightOverrides.whiteBalance); NightProfile.TryGet(out nightOverrides.colorAdjustments); NightProfile.TryGet(out nightOverrides.IndirectLightingController); SetRiseProfile.TryGet(out setRiseOverrides.proceduralSky); SetRiseProfile.TryGet(out setRiseOverrides.tonemapping); SetRiseProfile.TryGet(out setRiseOverrides.exposure); SetRiseProfile.TryGet(out setRiseOverrides.whiteBalance); SetRiseProfile.TryGet(out setRiseOverrides.colorAdjustments); SetRiseProfile.TryGet(out setRiseOverrides.IndirectLightingController); ActiveProfile.TryGet(out volumetricFog); clouds = Instantiate(CloudPrefab, new Vector3(0f, 100f, 0f), Quaternion.identity); cloudRenderer = clouds.GetComponentInChildren <Renderer>(); rainVolumes.AddRange(FindObjectsOfType <RainVolume>()); foreach (var volume in rainVolumes) { rainPfxs.Add(volume.Init(rainPfx, RandomGenerator.Next())); } wetObjects.AddRange(GameObject.FindGameObjectsWithTag("Road")); wetObjects.AddRange(GameObject.FindGameObjectsWithTag("Sidewalk")); var renderers = new List <Renderer>(); var materials = new List <Material>(); foreach (var obj in wetObjects) { obj.GetComponentsInChildren(renderers); renderers.ForEach(r => { if (r.GetComponent <ParticleSystem>() != null || r.GetComponent <ReflectionProbe>() != null) { return; } r.GetSharedMaterials(materials); materials.ForEach(m => { if (m == null) { Debug.LogError($"Object {r.gameObject.name} has null material", r.gameObject); } else { wetMaterials.Add(m); } }); }); } SetWet(); timeOfDayLights.AddRange(FindObjectsOfType <TimeOfDayLight>()); timeOfDayLights.ForEach(x => x.Init(currentTimeOfDayState)); Array.ForEach(FindObjectsOfType <TimeOfDayBuilding>(), x => x.Init(currentTimeOfDayState)); TimeOfDayCycle(); }
private void InitEnvironmentEffects() { Reset(); PostPrecessingVolume = Instantiate(PostProcessingVolumePrefab); ActiveProfile = PostPrecessingVolume.profile; sunGO = Instantiate(sunGO, new Vector3(0f, 50f, 0f), Quaternion.Euler(90f, 0f, 0f)); sun = sunGO.GetComponent <Light>(); ActiveProfile.TryGet(out activeOverrides.proceduralSky); ActiveProfile.TryGet(out activeOverrides.tonemapping); ActiveProfile.TryGet(out activeOverrides.exposure); ActiveProfile.TryGet(out activeOverrides.whiteBalance); ActiveProfile.TryGet(out activeOverrides.colorAdjustments); ActiveProfile.TryGet(out activeOverrides.IndirectLightingController); DayProfile.TryGet(out dayOverrides.proceduralSky); DayProfile.TryGet(out dayOverrides.tonemapping); DayProfile.TryGet(out dayOverrides.exposure); DayProfile.TryGet(out dayOverrides.whiteBalance); DayProfile.TryGet(out dayOverrides.colorAdjustments); DayProfile.TryGet(out dayOverrides.IndirectLightingController); NightProfile.TryGet(out nightOverrides.proceduralSky); NightProfile.TryGet(out nightOverrides.tonemapping); NightProfile.TryGet(out nightOverrides.exposure); NightProfile.TryGet(out nightOverrides.whiteBalance); NightProfile.TryGet(out nightOverrides.colorAdjustments); NightProfile.TryGet(out nightOverrides.IndirectLightingController); SetRiseProfile.TryGet(out setRiseOverrides.proceduralSky); SetRiseProfile.TryGet(out setRiseOverrides.tonemapping); SetRiseProfile.TryGet(out setRiseOverrides.exposure); SetRiseProfile.TryGet(out setRiseOverrides.whiteBalance); SetRiseProfile.TryGet(out setRiseOverrides.colorAdjustments); SetRiseProfile.TryGet(out setRiseOverrides.IndirectLightingController); ActiveProfile.TryGet(out volumetricFog); clouds = Instantiate(CloudPrefab, new Vector3(0f, 100f, 0f), Quaternion.identity); cloudRenderer = clouds.GetComponentInChildren <Renderer>(); rainVolumes.AddRange(FindObjectsOfType <RainVolume>()); foreach (var volume in rainVolumes) { rainPfxs.Add(volume.Init(rainPfx, RandomGenerator.Next())); } wetObjects.AddRange(GameObject.FindGameObjectsWithTag("Road")); wetObjects.AddRange(GameObject.FindGameObjectsWithTag("Sidewalk")); foreach (var obj in wetObjects) { var renderers = obj.GetComponentsInChildren <Renderer>(); foreach (var r in renderers) { if (r != null) { wetRenderers.Add(r); } } } SetWet(); timeOfDayLights.AddRange(FindObjectsOfType <TimeOfDayLight>()); timeOfDayLights.ForEach(x => x.Init(currentTimeOfDayState)); Array.ForEach(FindObjectsOfType <TimeOfDayBuilding>(), x => x.Init(currentTimeOfDayState)); TimeOfDayCycle(); }