public static void UpdateAuroraLight(AuroraElectrolizer electrolizer) { float aurora_int = AmbientLightUtils.GetPrivateFieldFloat(electrolizer, "m_AuroraLightFade"); float static_int = AmbientLightUtils.GetPrivateFieldFloat(electrolizer, "m_StaticIntensity"); for (int i = 0; i < electrolizer.m_LocalLights.Length; i++) { float cur_intensity = electrolizer.m_LocalLights[i].intensity; if (AmbientLightsOptions.disable_aurora_flicker) { cur_intensity = aurora_int * static_int; } if (AmbientLightControl.config != null) { float int_multiplier = AmbientLightsOptions.aurora_intensity * AmbientLightControl.config.options.aurora_intensity_multiplier; int_multiplier = Math.Max(int_multiplier, 1f); cur_intensity *= int_multiplier; } electrolizer.m_LocalLights[i].intensity = cur_intensity; AmbientLightUtils.SetPrivateFieldFloat(electrolizer, "m_CurIntensity", cur_intensity); } }
static AmbientLightControl() { Debug.Log("[ambient-lights] Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version); mods_folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); mod_data_folder = Path.Combine(mods_folder, "ambient-lights"); AmbientLightUtils.RegisterCommands(); }
public void FinishTransition() { if (!AmbientLightControl.light_override) { SetLightIntensity(target_set.intensity); SetLightRange(target_set.range); SetLightColor(AmbientLightUtils.ParseColor32(target_set.color)); if (AmbientLightsOptions.verbose) { DebugLightSet(); } } }
public void UpdateLightTransition(float step) { float t_intensity = Mathf.Lerp(start_set.intensity, target_set.intensity, step); float t_range = Mathf.Lerp(start_set.range, target_set.range, step); Color32 t_color = Color32.Lerp(AmbientLightUtils.ParseColor32(start_set.color), AmbientLightUtils.ParseColor32(target_set.color), step); if (!AmbientLightControl.light_override) { SetLightIntensity(t_intensity); SetLightRange(t_range); SetLightColor(t_color); //DebugLightSet(); } }
public static void SetupLights() { Debug.Log("[ambient-lights] Setting up " + config.emitters.Count + " light sources for scene."); foreach (AmbientConfigEmitter emitter in config.emitters) { Vector3 new_pos = AmbientLightUtils.StringToVector3(emitter.position); AmbientLight new_light = new AmbientLight(new_pos, emitter.orientation, emitter.size, emitter.cover); light_list.Add(new_light); } light_setup_done = true; MaybeUpdateLightsToPeriod(true); }
public static string GetCurrentPeriod() { string period_name = "default"; int now_time = AmbientLightUtils.GetCurrentTimeFormatted(); //TODO: Change to use tld functions to get period name foreach (KeyValuePair <string, AmbientPeriodItem> prd in AmbientLightControl.periods_data) { if (now_time >= prd.Value.start_hour && now_time < prd.Value.end_hour) { period_name = prd.Key; } } return(period_name); }
public static void MaybeUpdateLightsToPeriod(bool force_update = false) { if (light_setup_done && scene_time_init && scene_weather_init) { int now_time = AmbientLightUtils.GetCurrentTimeFormatted(); string period_name = TimeWeather.GetCurrentPeriod(); string weather_name = TimeWeather.GetCurrentWeather(); AuroraLightsControl.UpdateAuroraLightsRanges(); if (period_name != current_period || weather_name != current_weather || force_update) { AmbientConfigPeriod period = TimeWeather.GetPeriodSet(period_name); AmbientConfigWeather weatherSet = TimeWeather.GetWeatherSet(period, weather_name); period_transition.start = now_time; if (period_name == current_period && weather_name != current_weather) { period_transition.duration = 15; period_transition.end = now_time + 15; } else { period_transition.duration = TimeWeather.GetPeriodChangeDuration(period_name); period_transition.end = now_time + TimeWeather.GetPeriodChangeDuration(period_name); } period_transition.complete = force_update; current_weather = weather_name; current_period = period_name; if (AmbientLightsOptions.verbose) { Debug.Log("[ambient-lights] * Light period change:"); Debug.Log("[ambient-lights] Period: " + current_period); Debug.Log("[ambient-lights] Weather: " + current_weather); } foreach (var light in light_list) { AmbientConfigPeriodSet set = TimeWeather.GetLightSet(weatherSet, light.light_set); if (set != null) { light.SetLightParams(set, force_update); } } } else if (now_time > period_transition.start && now_time <= period_transition.end && !period_transition.complete) { float time_passed = now_time - period_transition.start; float transition_pos = time_passed / period_transition.duration; //Debug.Log("[ambient-lights] Transition position: " + transition_pos.ToString()); foreach (var light in light_list) { light.UpdateLightTransition(transition_pos); } } else if (now_time > period_transition.end && !period_transition.complete) { //Debug.Log("[ambient-lights] End of transition."); period_transition.complete = true; } } }
public static void RegisterCommands() { uConsole.RegisterCommand("light_int", new uConsole.DebugCommand(() => { float intensity = uConsole.GetFloat(); AmbientLightControl.light_override = true; AmbientLightControl.SetLightsIntensity(intensity); })); uConsole.RegisterCommand("lightset_int", new uConsole.DebugCommand(() => { string set = uConsole.GetString(); float intensity = uConsole.GetFloat(); AmbientLightControl.light_override = true; AmbientLightControl.SetLightsIntensity(intensity, set); })); uConsole.RegisterCommand("light_range", new uConsole.DebugCommand(() => { float range = uConsole.GetFloat(); AmbientLightControl.light_override = true; AmbientLightControl.SetLightsRange(range); })); uConsole.RegisterCommand("lightset_range", new uConsole.DebugCommand(() => { string set = uConsole.GetString(); float range = uConsole.GetFloat(); AmbientLightControl.light_override = true; AmbientLightControl.SetLightsRange(range, set); })); uConsole.RegisterCommand("light_color", new uConsole.DebugCommand(() => { string colorR = uConsole.GetString(); string colorG = uConsole.GetString(); string colorB = uConsole.GetString(); Color32 color = AmbientLightUtils.ParseColor32(colorR + "," + colorG + "," + colorB); AmbientLightControl.light_override = true; AmbientLightControl.SetLightsColor(color); })); uConsole.RegisterCommand("lightset_color", new uConsole.DebugCommand(() => { string set = uConsole.GetString(); string colorR = uConsole.GetString(); string colorG = uConsole.GetString(); string colorB = uConsole.GetString(); Color32 color = AmbientLightUtils.ParseColor32(colorR + "," + colorG + "," + colorB); AmbientLightControl.light_override = true; AmbientLightControl.SetLightsColor(color, set); })); uConsole.RegisterCommand("light_shadow", new uConsole.DebugCommand(() => { string shadow = uConsole.GetString(); AmbientLightControl.light_override = true; AmbientLightControl.SetLightsShadow(shadow); })); uConsole.RegisterCommand("lightset_shadow", new uConsole.DebugCommand(() => { string set = uConsole.GetString(); string shadow = uConsole.GetString(); AmbientLightControl.light_override = true; AmbientLightControl.SetLightsShadow(shadow, set); })); uConsole.RegisterCommand("light_on", new uConsole.DebugCommand(() => { AmbientLightControl.light_override = false; AmbientLightControl.MaybeUpdateLightsToPeriod(true); })); uConsole.RegisterCommand("light_off", new uConsole.DebugCommand(() => { AmbientLightControl.light_override = true; AmbientLightControl.SetLightsIntensity(0f); })); uConsole.RegisterCommand("debug_config", new uConsole.DebugCommand(() => { Debug.Log(Utils.SerializeObject(AmbientLightControl.config)); Debug.Log(Utils.SerializeObject(AmbientLightControl.global_periods_config)); })); uConsole.RegisterCommand("p", new uConsole.DebugCommand(() => { GetPoint(); })); uConsole.RegisterCommand("lobj", new uConsole.DebugCommand(() => { string obj_name = uConsole.GetString(); GetObjectsWithName(obj_name); })); }
public void SetLightParams(AmbientConfigPeriodSet set, bool instant_apply = false) { start_set = target_set; target_set = new AmbientConfigPeriodSet { intensity = set.intensity * AmbientLightControl.GetIntensityModifier(), range = set.range * AmbientLightControl.GetRangeModifier(), color = set.color, shadows = set.shadows }; if (start_set == null) { start_set = target_set; instant_apply = true; } if (set.intensity != 0) { light_source.enabled = true; } else { light_source.enabled = false; } if (AmbientLightControl.config.options.override_shadows != "") { set.shadows = AmbientLightControl.config.options.override_shadows; } if (!AmbientLightsOptions.enable_shadows) { light_source.shadows = LightShadows.None; } else { if (set.shadows.ToLower() == "hard") { //Hard shadows don't work well //light_source.shadows = LightShadows.Hard; light_source.shadows = LightShadows.Soft; } else if (set.shadows.ToLower() == "soft") { light_source.shadows = LightShadows.Soft; } else { light_source.shadows = LightShadows.None; } } if (instant_apply && !AmbientLightControl.light_override) { SetLightIntensity(target_set.intensity); SetLightRange(target_set.range); SetLightColor(AmbientLightUtils.ParseColor32(target_set.color)); if (AmbientLightsOptions.verbose) { DebugLightSet(); } } }