using System; using System.Collections.Generic; using UnityEngine; namespace Artngame.GIPROXY { public class LightCollisionsPDM : MonoBehaviour { public bool check_secondary_collisions; public bool meet_half_way; public bool Disable_on_tag; public List Disable_Tags = new List(); public bool Disable_on_layer; public List Disable_Layers = new List(); public bool Set_light_mask; public LayerMask Bounce_light_mask; public bool Cut_below_height; public float Cut_height; public bool Preview; public bool SecondBounce; private int Cycle_ID; private int Cycle_ID1; public bool Not_important_2ond; public bool use_light_sampling; public float sampling_dist = 15f; public bool use_grid; public int max_positions = 10; private List ray_dest_positions = new List(); private List sphere_dest_positions = new List(); private bool got_random_offsets; public float extend_X = 1f; public float extend_Y = 1f; private bool randomize; private Vector2[] rand_offsets; public bool go_random; public int hor_directions = 5; public int ver_directions = 5; public float PointLight_Radius = 10f; public float PointLight_Radius_2ond = 10f; public float Update_Color_Dist = 1f; public bool Follow_Hero; public Transform HERO; public bool Tag_based_player; public string Player_tag = "Player"; private Vector3 Hero_Dist; public Vector3 Hero_offset = new Vector3(0f, 0f, 0f); private bool Hero_has_been_set; private Transform LightTransform; private float current_time; [HideInInspector] public List Lights_level; [HideInInspector] public List Lights_source; [HideInInspector] public List Lights; [HideInInspector] public List Lights_destination_color; public float Divide_init_intensity = 5f; public float Bounce_Intensity = 5f; public float Bounce_Range = 230f; public float Degrade_speed = 0.6f; public float Appear_speed = 2f; public float min_dist_to_last_light = 10f; public float min_dist_to_source = 10f; public float min_density_dist = 1f; public bool Enable_follow; public float Follow_dist = 10f; public float Follow_speed = 10f; public Color Bounce_color; private Vector3 Start_light_pos; public bool Jitter_directional; public float bound_up_down = 50f; public float HDR_drop_speed = 1f; public bool get_hit_color; public bool get_texture_color; public bool mix_colors; public bool dynamic_update_color; public float Color_change_speed = 0.5f; public bool Soften_color_change; public bool Use_light_color; public bool Debug_on; public bool Debug_2ond; public bool add_only_when_seen; private Transform CameraTransform; public bool close_to_camera; public float min_dist_to_camera = 10f; public float max_hit_light_dist = 10f; public bool Give_Offset; public float placement_offset = 5f; public bool Origin_at_Projector; public Transform Projector_OBJ; public GameObject LightPool; public float Update_every = 0.1f; public bool Use_Height_cut_off; public float Cut_off_height = 15f; public float floor_if_no_hero; public bool Jove_Lights; public bool Grab_Skylight; public bool Rotate_grid; public float Sky_influence = 0.05f; public GameObject Sky; public bool offset_on_normal; private void Start() { if (Tag_based_player) { if (HERO == null) { HERO = GameObject.FindGameObjectWithTag(Player_tag).transform; } } else if (HERO == null) { HERO = Camera.main.transform; } LightTransform = GetComponent().transform; Bounce_color = GetComponent().color; Start_light_pos = LightTransform.position; CameraTransform = Camera.main.transform; current_time = Time.fixedTime; } private void Update() { if (!LightPool.activeInHierarchy) { LightPool.SetActive(value: true); } if (Cut_below_height && Projector_OBJ.position.y < Cut_height) { if (LightPool.activeInHierarchy) { LightPool.SetActive(value: false); } } else { if (!(Time.fixedTime - current_time > Update_every)) { return; } current_time = Time.fixedTime; float num = Color_change_speed; if ((GetComponent().type == LightType.Point) | Soften_color_change) { num = Color_change_speed * Time.deltaTime; } Vector3 vector = new Vector3(0f, 0f, 0f); if (Follow_Hero) { if (Tag_based_player) { if (HERO == null) { HERO = GameObject.FindGameObjectWithTag(Player_tag).transform; } } else if (HERO == null) { HERO = Camera.main.transform; } if ((HERO != null) & !Hero_has_been_set) { Vector3 position = LightTransform.position; Vector3 forward = LightTransform.forward; RaycastHit hitInfo = default(RaycastHit); if (Physics.Raycast(position, forward, out hitInfo, float.PositiveInfinity)) { Hero_Dist = hitInfo.point - HERO.position; Hero_has_been_set = true; } } if (HERO != null) { Vector3 position2 = LightTransform.position; Vector3 forward2 = LightTransform.forward; RaycastHit hitInfo2 = default(RaycastHit); if (Physics.Raycast(position2, forward2, out hitInfo2, float.PositiveInfinity)) { Hero_Dist = hitInfo2.point - HERO.position; } vector = -Hero_Dist + Hero_offset; } } Vector3 vector2 = LightTransform.position + vector; Vector3 forward3 = LightTransform.forward; if (Origin_at_Projector) { if (Projector_OBJ != null) { vector2 = Projector_OBJ.position + vector; forward3 = Projector_OBJ.forward; } else { Debug.Log("Please insert the projector gameobject to the script"); } } if ((GetComponent().type == LightType.Directional) & Jitter_directional) { vector2 = ((!(vector2.y > Start_light_pos.y)) ? new Vector3(vector2.x, vector2.y + bound_up_down * Time.deltaTime, vector2.z) : new Vector3(vector2.x, vector2.y - bound_up_down / 10f * Time.deltaTime, vector2.z)); } for (int num2 = Lights.Count - 1; num2 >= 0; num2--) { if (Lights[num2] == null) { if (SecondBounce) { for (int i = 0; i < Lights.Count; i++) { if ((Lights_source[i] == Lights[num2]) & (Lights_level[i] > 1)) { Lights[i].GetComponent().intensity = 0f; UnityEngine.Object.Destroy(Lights[i].gameObject); Lights.RemoveAt(i); Lights_destination_color.RemoveAt(i); Lights_level.RemoveAt(i); Lights_source.RemoveAt(i); } } } Lights.RemoveAt(num2); Lights_destination_color.RemoveAt(num2); Lights_level.RemoveAt(num2); Lights_source.RemoveAt(num2); } else if (Lights[num2].GetComponent().intensity == 0f) { if (SecondBounce) { for (int j = 0; j < Lights.Count; j++) { if ((Lights_source[j] == Lights[num2]) & (Lights_level[j] > 1)) { Lights[j].GetComponent().intensity = 0f; UnityEngine.Object.Destroy(Lights[j].gameObject); Lights.RemoveAt(j); Lights_destination_color.RemoveAt(j); Lights_level.RemoveAt(j); Lights_source.RemoveAt(j); } } } UnityEngine.Object.Destroy(Lights[num2].gameObject); Lights.RemoveAt(num2); Lights_destination_color.RemoveAt(num2); Lights_level.RemoveAt(num2); Lights_source.RemoveAt(num2); } } if (!use_grid) { for (int num3 = Lights.Count - 1; num3 >= 0; num3--) { if (Debug_on) { Debug.DrawLine(Lights[num3].position, new Vector3(Lights[num3].position.x, Lights[num3].position.y + 15f, Lights[num3].position.z)); } if (use_light_sampling && Lights_destination_color[num3] != Lights[num3].GetComponent().color) { Lights[num3].GetComponent().color = Color.Lerp(Lights[num3].GetComponent().color, Lights_destination_color[num3], num); } if (Vector3.Distance(Lights[num3].position, Lights[Lights.Count - 1].position) > min_dist_to_last_light) { if (Lights[num3].GetComponent().intensity > 0f) { if ((GetComponent().type != LightType.Point) & (Lights_level[num3] < 2)) { Lights[num3].GetComponent().intensity -= Degrade_speed * Time.deltaTime; if (SecondBounce) { for (int k = 0; k < Lights.Count; k++) { if ((Lights_source[k] == Lights[num3]) & (Lights_level[k] > 1)) { Lights[k].GetComponent().intensity -= 100f * Degrade_speed * Time.deltaTime; } } } } } else { if (SecondBounce) { for (int l = 0; l < Lights.Count; l++) { if ((Lights_source[l] == Lights[num3]) & (Lights_level[l] > 1)) { Lights[l].GetComponent().intensity = 0f; UnityEngine.Object.Destroy(Lights[l].gameObject); Lights.RemoveAt(l); Lights_destination_color.RemoveAt(l); Lights_level.RemoveAt(l); Lights_source.RemoveAt(l); } } } UnityEngine.Object.Destroy(Lights[num3].gameObject); Lights.RemoveAt(num3); Lights_destination_color.RemoveAt(num3); Lights_level.RemoveAt(num3); Lights_source.RemoveAt(num3); } } else if (Vector3.Distance(Lights[num3].position, vector2) > min_dist_to_source) { if (Lights[num3].GetComponent().intensity > 0f) { if ((Lights[num3].GetComponent().type == LightType.Point) & (Lights_level[num3] < 2)) { Lights[num3].GetComponent().intensity -= Degrade_speed * Time.deltaTime; if (SecondBounce) { for (int m = 0; m < Lights.Count; m++) { if ((Lights_source[m] == Lights[num3]) & (Lights_level[m] > 1)) { Lights[m].GetComponent().intensity -= 100f * Degrade_speed * Time.deltaTime; } } } } } else { if (SecondBounce) { for (int n = 0; n < Lights.Count; n++) { if ((Lights_source[n] == Lights[num3]) & (Lights_level[n] > 1)) { Lights[n].GetComponent().intensity = 0f; UnityEngine.Object.Destroy(Lights[n].gameObject); Lights.RemoveAt(n); Lights_destination_color.RemoveAt(n); Lights_level.RemoveAt(n); Lights_source.RemoveAt(n); } } } UnityEngine.Object.Destroy(Lights[num3].gameObject); Lights.RemoveAt(num3); Lights_destination_color.RemoveAt(num3); Lights_level.RemoveAt(num3); Lights_source.RemoveAt(num3); } } else { if ((Lights[num3].GetComponent().intensity < Bounce_Intensity) & (Lights_level[num3] < 2)) { Lights[num3].GetComponent().intensity += Appear_speed * Time.deltaTime; } else if ((HDR_drop_speed > 0f) & (Lights[num3].GetComponent().intensity > Bounce_Intensity + 1f) & (Lights_level[num3] < 2)) { Lights[num3].GetComponent().intensity -= HDR_drop_speed * Time.deltaTime; } if ((Lights[num3].GetComponent().intensity < Bounce_Intensity / (float)Lights_level[num3]) & (Lights_level[num3] >= 2)) { Lights[num3].GetComponent().intensity += Appear_speed * Time.deltaTime; } else if ((HDR_drop_speed > 0f) & (Lights[num3].GetComponent().intensity > Bounce_Intensity / 2f + 1f) & (Lights_level[num3] >= 2)) { Lights[num3].GetComponent().intensity -= HDR_drop_speed * Time.deltaTime; } } } if (Cycle_ID1 > Lights.Count - 1) { Cycle_ID1 = 0; } for (int num4 = Lights.Count - 1; num4 >= 0; num4--) { Cycle_ID1++; if (Cycle_ID1 > Lights.Count - 1) { Cycle_ID1 = 0; } RaycastHit hitInfo3 = default(RaycastHit); if (Physics.Raycast(vector2, forward3, out hitInfo3, float.PositiveInfinity)) { Vector3 vector3 = new Vector3(0f, 0f, 0f); if (Vector3.Distance(b: (!Give_Offset) ? hitInfo3.point : ((!offset_on_normal) ? (hitInfo3.point + (vector2 - hitInfo3.point).normalized * placement_offset) : (hitInfo3.point + hitInfo3.normal.normalized * placement_offset)), a: Lights[num4].position) > max_hit_light_dist) { if (Lights[num4].GetComponent().intensity > 0f) { if ((GetComponent().type != LightType.Point) & (Lights_level[num4] < 2)) { Lights[num4].GetComponent().intensity -= Degrade_speed * 10f * Time.deltaTime; if (SecondBounce) { for (int num5 = 0; num5 < Lights.Count; num5++) { if ((Lights_source[num5] == Lights[num4]) & (Lights_level[num5] > 1)) { Lights[num5].GetComponent().intensity -= 100f * Degrade_speed * Time.deltaTime; } } } } } else { if (SecondBounce) { for (int num6 = 0; num6 < Lights.Count; num6++) { if ((Lights_source[num6] == Lights[num4]) & (Lights_level[num6] > 1)) { Lights[num6].GetComponent().intensity = 0f; UnityEngine.Object.Destroy(Lights[num6].gameObject); Lights.RemoveAt(num6); Lights_destination_color.RemoveAt(num6); Lights_level.RemoveAt(num6); Lights_source.RemoveAt(num6); } } } UnityEngine.Object.Destroy(Lights[num4].gameObject); Lights.RemoveAt(num4); Lights_destination_color.RemoveAt(num4); Lights_level.RemoveAt(num4); Lights_source.RemoveAt(num4); } } } } } else { for (int num7 = Lights.Count - 1; num7 >= 0; num7--) { if (Debug_on) { Debug.DrawLine(Lights[num7].position, new Vector3(Lights[num7].position.x, Lights[num7].position.y + 15f, Lights[num7].position.z)); } if (Vector3.Distance(Lights[num7].position, vector2) > min_dist_to_source) { if (Lights[num7].GetComponent().intensity > 0f) { if ((GetComponent().type == LightType.Point) & (Lights_level[num7] < 2)) { Lights[num7].GetComponent().intensity -= Degrade_speed * 10f * Time.deltaTime; if (SecondBounce) { for (int num8 = 0; num8 < Lights.Count; num8++) { if ((Lights_source[num8] == Lights[num7]) & (Lights_level[num8] > 1)) { Lights[num8].GetComponent().intensity -= 100f * Degrade_speed * Time.deltaTime; } } } } } else if (GetComponent().type == LightType.Point) { if (SecondBounce) { for (int num9 = 0; num9 < Lights.Count; num9++) { if ((Lights_source[num9] == Lights[num7]) & (Lights_level[num9] > 1)) { Lights[num9].GetComponent().intensity = 0f; UnityEngine.Object.Destroy(Lights[num9].gameObject); Lights.RemoveAt(num9); Lights_destination_color.RemoveAt(num9); Lights_level.RemoveAt(num9); Lights_source.RemoveAt(num9); } } } UnityEngine.Object.Destroy(Lights[num7].gameObject); Lights.RemoveAt(num7); Lights_destination_color.RemoveAt(num7); Lights_level.RemoveAt(num7); Lights_source.RemoveAt(num7); } } else { if ((Lights[num7].GetComponent().intensity < Bounce_Intensity) & (Lights_level[num7] < 2)) { Lights[num7].GetComponent().intensity += Appear_speed * Time.deltaTime; } else if ((HDR_drop_speed > 0f) & (Lights[num7].GetComponent().intensity > Bounce_Intensity + 1f) & (Lights_level[num7] < 2)) { Lights[num7].GetComponent().intensity -= HDR_drop_speed * Time.deltaTime; } if ((Lights[num7].GetComponent().intensity < Bounce_Intensity / (float)Lights_level[num7]) & (Lights_level[num7] >= 2)) { Lights[num7].GetComponent().intensity += Appear_speed * Time.deltaTime; } else if ((HDR_drop_speed > 0f) & (Lights[num7].GetComponent().intensity > Bounce_Intensity / 2f + 1f) & (Lights_level[num7] >= 2)) { Lights[num7].GetComponent().intensity -= HDR_drop_speed * Time.deltaTime; } } } if (Cycle_ID1 > Lights.Count - 1) { Cycle_ID1 = 0; } for (int num10 = Lights.Count - 1; num10 >= 0; num10--) { Cycle_ID1++; if (Cycle_ID1 > Lights.Count - 1) { Cycle_ID1 = 0; } if (GetComponent().type == LightType.Point) { Vector3 vector4 = Lights[num10].position - vector2; Vector3 origin = vector2; RaycastHit hitInfo4 = default(RaycastHit); if (Physics.Raycast(origin, vector4, out hitInfo4, float.PositiveInfinity)) { Vector3 vector5 = new Vector3(0f, 0f, 0f); if (Vector3.Distance(b: (!Give_Offset) ? hitInfo4.point : ((!offset_on_normal) ? (hitInfo4.point + (vector2 - hitInfo4.point).normalized * placement_offset) : (hitInfo4.point + hitInfo4.normal.normalized * placement_offset)), a: hitInfo4.point) < Update_Color_Dist) { Lights[num10].gameObject.GetComponent().color = Get_color(Lights[num10].gameObject, hitInfo4, num); } } if (Grab_Skylight) { RaycastHit hitInfo5 = default(RaycastHit); if (Physics.Raycast(origin, -vector4, out hitInfo5, float.PositiveInfinity)) { bool flag = true; if (Sky != null && Sky.name != hitInfo5.collider.gameObject.name) { flag = false; } if (flag) { Lights[num10].gameObject.GetComponent().color = Get_color(Lights[num10].gameObject, hitInfo5, num * Sky_influence); } _ = Debug_on; } } } bool flag2 = true; for (int num11 = 0; num11 < ray_dest_positions.Count; num11++) { Vector3 direction = forward3; Vector3 origin2 = vector2 + ray_dest_positions[num11]; RaycastHit hitInfo6 = default(RaycastHit); if (Physics.Raycast(origin2, direction, out hitInfo6, float.PositiveInfinity)) { Vector3 vector6 = new Vector3(0f, 0f, 0f); if (Vector3.Distance(b: (!Give_Offset) ? hitInfo6.point : ((!offset_on_normal) ? (hitInfo6.point + (vector2 - hitInfo6.point).normalized * placement_offset) : (hitInfo6.point + hitInfo6.normal.normalized * placement_offset)), a: Lights[num10].position) < max_hit_light_dist) { flag2 = false; } } } if (flag2) { if (Lights[num10].GetComponent().intensity > 0f) { if ((GetComponent().type != LightType.Point) & (Lights_level[num10] < 2)) { Lights[num10].GetComponent().intensity -= Degrade_speed * 10f * Time.deltaTime; if (SecondBounce) { for (int num12 = 0; num12 < Lights.Count; num12++) { if ((Lights_source[num12] == Lights[num10]) & (Lights_level[num12] > 1)) { Lights[num12].GetComponent().intensity -= 100f * Degrade_speed * Time.deltaTime; } } } } } else { if (SecondBounce) { for (int num13 = 0; num13 < Lights.Count; num13++) { if ((Lights_source[num13] == Lights[num10]) & (Lights_level[num13] > 1)) { Lights[num13].GetComponent().intensity = 0f; UnityEngine.Object.Destroy(Lights[num13].gameObject); Lights.RemoveAt(num13); Lights_destination_color.RemoveAt(num13); Lights_level.RemoveAt(num13); Lights_source.RemoveAt(num13); } } } UnityEngine.Object.Destroy(Lights[num10].gameObject); Lights.RemoveAt(num10); Lights_destination_color.RemoveAt(num10); Lights_level.RemoveAt(num10); Lights_source.RemoveAt(num10); } } } } if (use_grid & !got_random_offsets) { ray_dest_positions.Clear(); int num14 = (int)Mathf.Sqrt(max_positions); if (!got_random_offsets) { got_random_offsets = true; rand_offsets = new Vector2[num14 * num14]; int num15 = 0; for (int num16 = 0; num16 < num14; num16++) { for (int num17 = 0; num17 < num14; num17++) { rand_offsets[num15] = new Vector2(UnityEngine.Random.Range(0f, extend_X * (float)(num14 / 2) * (float)num16) + 1.5f * (float)num15, UnityEngine.Random.Range(0f, extend_Y * (float)(num14 / 2) * (float)num17) + 1.1f * (float)num15); num15++; } } } int num18 = 0; for (int num19 = 0; num19 < num14; num19++) { for (int num20 = 0; num20 < num14; num20++) { float num21 = extend_X * (float)(num14 / 2) * (float)num19; float num22 = extend_Y * (float)(num14 / 2) * (float)num20; if (randomize) { num21 += UnityEngine.Random.Range(0f, extend_X * (float)(num14 / 2) * (float)num19); num22 += UnityEngine.Random.Range(0f, extend_Y * (float)(num14 / 2) * (float)num20); } if (!go_random) { ray_dest_positions.Add(new Vector3(0f - num21, 0f, 0f - num22)); ray_dest_positions.Add(new Vector3(num21, 0f, 0f - num22)); } if (go_random) { ray_dest_positions.Add(new Vector3(0f - rand_offsets[num18].x, 0f, 0f - rand_offsets[num18].y)); num18++; } } } } if (GetComponent() != null) { if ((GetComponent().type == LightType.Directional) | (GetComponent().type == LightType.Spot)) { Vector3 vector7 = vector2; Vector3 vector8 = forward3; if (!use_grid & (ray_dest_positions.Count < 1)) { ray_dest_positions.Add(new Vector3(0f, 0f, 0f)); } for (int num23 = 0; num23 < ray_dest_positions.Count; num23++) { if (use_grid) { vector8 = forward3; vector7 = ((!Rotate_grid) ? (vector2 + ray_dest_positions[num23]) : ((!Origin_at_Projector) ? (vector2 + LightTransform.rotation * ray_dest_positions[num23]) : (vector2 + Projector_OBJ.transform.rotation * ray_dest_positions[num23]))); } RaycastHit hitInfo7 = default(RaycastHit); if (!Physics.Raycast(vector7, vector8, out hitInfo7, float.PositiveInfinity)) { continue; } Vector3 vector9 = new Vector3(0f, 0f, 0f); vector9 = ((!Give_Offset) ? hitInfo7.point : ((!offset_on_normal) ? (hitInfo7.point + (vector2 - hitInfo7.point).normalized * placement_offset) : (hitInfo7.point + hitInfo7.normal.normalized * placement_offset))); if (Debug_on) { Debug.DrawLine(vector7, vector9, Color.magenta); } if (check_secondary_collisions) { RaycastHit hitInfo8 = default(RaycastHit); if (Physics.Raycast(hitInfo7.point, vector9 - hitInfo7.point, out hitInfo8, (vector9 - hitInfo7.point).magnitude) && (hitInfo8.point - hitInfo7.point).magnitude < (vector9 - hitInfo7.point).magnitude) { vector9 = ((!meet_half_way) ? hitInfo7.point : (hitInfo7.point + (hitInfo8.point - hitInfo7.point).normalized * (hitInfo8.point - hitInfo7.point).magnitude / 2f)); } } bool flag3 = true; bool flag4 = false; if (Lights.Count <= 0) { flag4 = true; } else { if (Enable_follow) { for (int num24 = Lights.Count - 1; num24 >= 0; num24--) { if (Vector3.Distance(Lights[num24].position, vector9) > Follow_dist) { Lights[num24].position = Vector3.Lerp(Lights[num24].position, vector9, Follow_speed * Time.deltaTime); } } } if (add_only_when_seen) { RaycastHit hitInfo9 = default(RaycastHit); if (Physics.Raycast(CameraTransform.position, vector9, out hitInfo9, float.PositiveInfinity) && hitInfo9.point.magnitude > 0f && Vector3.Distance(hitInfo9.point, CameraTransform.position) < Vector3.Distance(vector9, CameraTransform.position)) { flag3 = false; } } if (close_to_camera && Vector3.Distance(CameraTransform.position, vector9) > min_dist_to_camera) { flag3 = false; } for (int num25 = Lights.Count - 1; num25 >= 0; num25--) { if (Vector3.Distance(Lights[num25].position, vector9) < min_density_dist) { flag3 = false; } if (dynamic_update_color & get_hit_color) { if (Vector3.Distance(Lights[num25].position, vector9) < min_density_dist) { Lights[num25].gameObject.GetComponent().color = Get_color(Lights[num25].gameObject, hitInfo7, num); } if (Grab_Skylight) { RaycastHit hitInfo10 = default(RaycastHit); if (Physics.Raycast(vector7, -vector8, out hitInfo10, float.PositiveInfinity)) { bool flag5 = true; if (Sky != null && Sky.name != hitInfo10.collider.gameObject.name) { flag5 = false; } if (flag5) { Lights[num25].gameObject.GetComponent().color = Get_color(Lights[num25].gameObject, hitInfo10, num * Sky_influence); } if (Debug_on) { Debug.DrawLine(vector7, hitInfo10.point, Color.blue); } } } } } } if (Use_Height_cut_off) { if (Follow_Hero) { if (hitInfo7.point.y - HERO.position.y > Cut_off_height) { flag3 = false; } } else if (hitInfo7.point.y - floor_if_no_hero > Cut_off_height) { flag3 = false; } } if (Disable_on_tag) { for (int num26 = 0; num26 < Disable_Tags.Count; num26++) { if (hitInfo7.collider.gameObject.tag == Disable_Tags[num26]) { flag3 = false; } } } if (Disable_on_layer) { for (int num27 = 0; num27 < Disable_Layers.Count; num27++) { if (LayerMask.LayerToName(hitInfo7.collider.gameObject.layer) == Disable_Layers[num27]) { flag3 = false; } } } if (!((flag3 && !flag4) || flag4)) { continue; } GameObject gameObject = new GameObject("Bounce Light"); gameObject.AddComponent(typeof(Light)); if (!get_hit_color) { if (!mix_colors) { gameObject.GetComponent().color = Bounce_color; } else { gameObject.GetComponent().color = Color.Lerp(Bounce_color, GetComponent().color, num); } } else { gameObject.GetComponent().color = Get_color(gameObject, hitInfo7, num); } gameObject.GetComponent().intensity = Bounce_Intensity / Divide_init_intensity; gameObject.GetComponent().range = Bounce_Range; gameObject.transform.position = vector9; if (Set_light_mask) { gameObject.GetComponent().cullingMask = Bounce_light_mask; } Lights_destination_color.Add(gameObject.GetComponent().color); Color color = gameObject.GetComponent().color; if (use_light_sampling) { for (int num28 = 0; num28 < Lights.Count; num28++) { if (Vector3.Distance(Lights[num28].position, vector9) < sampling_dist) { color = Color.Lerp(color, Lights[num28].GetComponent().color, 0.1f); } } } if (Grab_Skylight) { RaycastHit hitInfo11 = default(RaycastHit); if (Physics.Raycast(vector7, -vector8, out hitInfo11, float.PositiveInfinity)) { bool flag6 = true; if (Sky != null && Sky.name != hitInfo11.collider.gameObject.name) { flag6 = false; } if (flag6) { color = Get_color(gameObject, hitInfo11, num * Sky_influence); } _ = Debug_on; } } gameObject.GetComponent().color = color; Lights.Add(gameObject.transform); if (Jove_Lights) { gameObject.AddComponent(typeof(Control_Jove_light)); } Lights_level.Add(1); Lights_source.Add(LightTransform); gameObject.transform.parent = LightPool.transform; } } if (GetComponent().type == LightType.Point) { Vector3 vector10 = vector2; Vector3 direction2 = forward3; if (sphere_dest_positions != null && sphere_dest_positions.Count <= 0) { Vector3[] sphereDirections = GetSphereDirections(hor_directions * ver_directions); foreach (Vector3 item in sphereDirections) { sphere_dest_positions.Add(item); } } for (int num30 = 0; num30 < sphere_dest_positions.Count; num30++) { if (use_grid) { vector10 = vector2; direction2 = sphere_dest_positions[num30]; } RaycastHit hitInfo12 = default(RaycastHit); if (!Physics.Raycast(vector10, direction2, out hitInfo12, min_dist_to_source - 1E-05f)) { continue; } Vector3 vector11 = new Vector3(0f, 0f, 0f); vector11 = ((!Give_Offset) ? hitInfo12.point : ((!offset_on_normal) ? (hitInfo12.point + (vector2 - hitInfo12.point).normalized * placement_offset) : (hitInfo12.point + hitInfo12.normal.normalized * placement_offset))); if (Debug_on) { Debug.DrawLine(vector10, vector11, Color.magenta); } if (check_secondary_collisions) { RaycastHit hitInfo13 = default(RaycastHit); if (Physics.Raycast(hitInfo12.point, vector11 - hitInfo12.point, out hitInfo13, (vector11 - hitInfo12.point).magnitude) && (hitInfo13.point - hitInfo12.point).magnitude < (vector11 - hitInfo12.point).magnitude) { vector11 = ((!meet_half_way) ? hitInfo12.point : (hitInfo12.point + (hitInfo13.point - hitInfo12.point).normalized * (hitInfo13.point - hitInfo12.point).magnitude / 2f)); } } bool flag7 = true; bool flag8 = false; if (Lights.Count <= 0) { flag8 = true; } else { if (Enable_follow) { for (int num31 = Lights.Count - 1; num31 >= 0; num31--) { if (Vector3.Distance(Lights[num31].position, vector11) > Follow_dist) { Lights[num31].position = Vector3.Lerp(Lights[num31].position, vector11, Follow_speed * Time.deltaTime); } } } if (add_only_when_seen) { RaycastHit hitInfo14 = default(RaycastHit); if (Physics.Raycast(CameraTransform.position, vector11, out hitInfo14, float.PositiveInfinity) && hitInfo14.point.magnitude > 0f && Vector3.Distance(hitInfo14.point, CameraTransform.position) < Vector3.Distance(vector11, CameraTransform.position)) { flag7 = false; } } if (close_to_camera && Vector3.Distance(CameraTransform.position, vector11) > min_dist_to_camera) { flag7 = false; } for (int num32 = Lights.Count - 1; num32 >= 0; num32--) { if (Vector3.Distance(Lights[num32].position, vector11) < min_density_dist) { flag7 = false; } if ((dynamic_update_color & get_hit_color) && Vector3.Distance(Lights[num32].position, vector11) < min_density_dist / 2f) { Lights[num32].gameObject.GetComponent().color = Get_color(Lights[num32].gameObject, hitInfo12, num); } } } if (PointLight_Radius < 0f) { PointLight_Radius = 0f; } if (PointLight_Radius != 0f && !(Vector3.Distance(hitInfo12.point, GetComponent().transform.position) < PointLight_Radius)) { flag7 = false; } if (Disable_on_tag) { for (int num33 = 0; num33 < Disable_Tags.Count; num33++) { if (hitInfo12.collider.gameObject.tag == Disable_Tags[num33]) { flag7 = false; } } } if (Disable_on_layer) { for (int num34 = 0; num34 < Disable_Layers.Count; num34++) { if (LayerMask.LayerToName(hitInfo12.collider.gameObject.layer) == Disable_Layers[num34]) { flag7 = false; } } } if (!((flag7 && !flag8) || flag8)) { continue; } GameObject gameObject2 = new GameObject("Bounce Light"); gameObject2.AddComponent(typeof(Light)); if (!get_hit_color) { if (!mix_colors) { gameObject2.GetComponent().color = Bounce_color; } else { gameObject2.GetComponent().color = Color.Lerp(Bounce_color, GetComponent().color, num); } } else { gameObject2.GetComponent().color = Get_color(gameObject2, hitInfo12, num); } gameObject2.GetComponent().intensity = Bounce_Intensity / Divide_init_intensity; gameObject2.GetComponent().range = Bounce_Range; gameObject2.transform.position = vector11; if (Set_light_mask) { gameObject2.GetComponent().cullingMask = Bounce_light_mask; } Lights_destination_color.Add(gameObject2.GetComponent().color); Color color2 = gameObject2.GetComponent().color; if (use_light_sampling) { for (int num35 = 0; num35 < Lights.Count; num35++) { if (Vector3.Distance(Lights[num35].position, vector11) < sampling_dist) { color2 = Color.Lerp(color2, Lights[num35].GetComponent().color, 0.1f); } } } gameObject2.GetComponent().color = color2; Lights.Add(gameObject2.transform); if (Jove_Lights) { gameObject2.AddComponent(typeof(Control_Jove_light)); } Lights_level.Add(1); Lights_source.Add(LightTransform); gameObject2.transform.parent = LightPool.transform; } } if (!SecondBounce) { return; } if (Cycle_ID > Lights.Count - 1) { Cycle_ID = 0; } for (int num36 = 0; num36 < Lights.Count; num36++) { if (Cycle_ID != num36) { continue; } Cycle_ID++; if (Cycle_ID > Lights.Count - 1) { Cycle_ID = 0; } if (Lights[num36].GetComponent().type != LightType.Point) { break; } Vector3 position3 = Lights[num36].position; Vector3 direction3 = forward3; if (sphere_dest_positions != null && sphere_dest_positions.Count <= 0) { Vector3[] sphereDirections = GetSphereDirections(hor_directions * ver_directions); foreach (Vector3 item2 in sphereDirections) { sphere_dest_positions.Add(item2); } } for (int num37 = 0; num37 < sphere_dest_positions.Count; num37++) { if (use_grid) { position3 = Lights[num36].position; direction3 = sphere_dest_positions[num37]; } RaycastHit hitInfo15 = default(RaycastHit); if (!Physics.Raycast(position3, direction3, out hitInfo15, PointLight_Radius_2ond)) { continue; } Vector3 vector12 = new Vector3(0f, 0f, 0f); vector12 = ((!Give_Offset) ? hitInfo15.point : ((!offset_on_normal) ? (hitInfo15.point + (vector2 - hitInfo15.point).normalized * placement_offset) : (hitInfo15.point + hitInfo15.normal.normalized * placement_offset))); if (Debug_2ond) { Debug.DrawLine(position3, vector12, Color.magenta); } if (check_secondary_collisions) { RaycastHit hitInfo16 = default(RaycastHit); if (Physics.Raycast(hitInfo15.point, vector12 - hitInfo15.point, out hitInfo16, (vector12 - hitInfo15.point).magnitude) && (hitInfo16.point - hitInfo15.point).magnitude < (vector12 - hitInfo15.point).magnitude) { vector12 = ((!meet_half_way) ? hitInfo15.point : (hitInfo15.point + (hitInfo16.point - hitInfo15.point).normalized * (hitInfo16.point - hitInfo15.point).magnitude / 2f)); } } bool flag9 = true; bool flag10 = false; if (Lights.Count <= 0) { flag10 = true; } else { if (Enable_follow) { for (int num38 = Lights.Count - 1; num38 >= 0; num38--) { if (Vector3.Distance(Lights[num38].position, vector12) > Follow_dist) { Lights[num38].position = Vector3.Lerp(Lights[num38].position, vector12, Follow_speed * Time.deltaTime); } } } if (add_only_when_seen) { RaycastHit hitInfo17 = default(RaycastHit); if (Physics.Raycast(CameraTransform.position, vector12, out hitInfo17, float.PositiveInfinity) && hitInfo17.point.magnitude > 0f && Vector3.Distance(hitInfo17.point, CameraTransform.position) < Vector3.Distance(vector12, CameraTransform.position)) { flag9 = false; } } if (close_to_camera && Vector3.Distance(CameraTransform.position, vector12) > min_dist_to_camera) { flag9 = false; } for (int num39 = Lights.Count - 1; num39 >= 0; num39--) { if (Vector3.Distance(Lights[num39].position, vector12) < min_density_dist) { flag9 = false; } if (Lights_level[num39] >= 2 && (dynamic_update_color & get_hit_color) && Vector3.Distance(Lights[num39].position, vector12) < min_density_dist / 2f) { Lights[num39].gameObject.GetComponent().color = Get_color(Lights[num39].gameObject, hitInfo15, num); } } } if (PointLight_Radius_2ond < 0f) { PointLight_Radius_2ond = 0f; } if (PointLight_Radius_2ond != 0f && !(Vector3.Distance(hitInfo15.point, Lights[num36].GetComponent().transform.position) < PointLight_Radius_2ond)) { flag9 = false; } if (Disable_on_tag) { for (int num40 = 0; num40 < Disable_Tags.Count; num40++) { if (hitInfo15.collider.gameObject.tag == Disable_Tags[num40]) { flag9 = false; } } } if (Disable_on_layer) { for (int num41 = 0; num41 < Disable_Layers.Count; num41++) { if (LayerMask.LayerToName(hitInfo15.collider.gameObject.layer) == Disable_Layers[num41]) { flag9 = false; } } } if (!((flag9 && !flag10) || flag10)) { continue; } if (Lights_level[num36] >= 2) { break; } GameObject gameObject3 = new GameObject("Indirect Bounce Light Level " + (Lights_level[num36] + 1)); gameObject3.AddComponent(typeof(Light)); if (!get_hit_color) { if (!mix_colors) { gameObject3.GetComponent().color = Bounce_color; } else { gameObject3.GetComponent().color = Color.Lerp(Bounce_color, Lights[num36].GetComponent().color, num); } } else { gameObject3.GetComponent().color = Color.Lerp(Get_color(gameObject3, hitInfo15, num), Lights[num36].GetComponent().color, 0.5f); } gameObject3.GetComponent().intensity = Bounce_Intensity / Divide_init_intensity; gameObject3.GetComponent().range = Bounce_Range; gameObject3.transform.position = vector12; if (Set_light_mask) { gameObject3.GetComponent().cullingMask = Bounce_light_mask; } Lights_destination_color.Add(gameObject3.GetComponent().color); Color color3 = gameObject3.GetComponent().color; if (use_light_sampling) { for (int num42 = 0; num42 < Lights.Count; num42++) { if (Vector3.Distance(Lights[num42].position, vector12) < sampling_dist) { color3 = Color.Lerp(color3, Lights[num42].GetComponent().color, 0.1f); } } } gameObject3.GetComponent().color = color3; if (Not_important_2ond) { gameObject3.GetComponent().renderMode = LightRenderMode.ForceVertex; } Lights.Add(gameObject3.transform); if (Jove_Lights) { gameObject3.AddComponent(typeof(Control_Jove_light)); } int item3 = 2; if (Lights_level[num36] > 1) { item3 = Lights_level[num36] + 1; } Lights_level.Add(item3); Lights_source.Add(Lights[num36]); gameObject3.transform.parent = LightPool.transform; break; } break; } } else { Debug.Log("Add the script to a light"); } } } private Vector3[] GetSphereDirections(int numDirections) { Vector3[] array = new Vector3[numDirections]; float num = MathF.PI * (3f - Mathf.Sqrt(5f)); float num2 = 2f / (float)numDirections; for (int i = 0; i < numDirections; i++) { float num3 = (float)i * num2 - 1f + num2 / 2f; float num4 = Mathf.Sqrt(1f - num3 * num3); float f = (float)i * num; float x = Mathf.Cos(f) * num4; float z = Mathf.Sin(f) * num4; array[i] = new Vector3(x, num3, z); } return array; } private Color Get_color(GameObject lightGameObject, RaycastHit hit1, float Color_speed) { Color result = lightGameObject.GetComponent().color; if (!(hit1.transform.GetComponent() != null)) { result = (mix_colors ? Color.Lerp(Bounce_color, GetComponent().color, Color_speed) : Bounce_color); } else if (hit1.transform.GetComponent().material != null) { if (!(get_texture_color & hit1.transform.GetComponent().material.HasProperty("_MainTex"))) { result = ((!hit1.transform.GetComponent().material.HasProperty("_Color")) ? GetComponent().color : ((!mix_colors) ? hit1.transform.GetComponent().material.color : ((!Use_light_color) ? Color.Lerp(lightGameObject.GetComponent().color, hit1.transform.GetComponent().material.color, Color_speed) : Color.Lerp(GetComponent().color, hit1.transform.GetComponent().material.color, Color_speed)))); } else if (!(hit1.transform.GetComponent().material.mainTexture != null)) { result = ((!hit1.transform.GetComponent().material.HasProperty("_Color")) ? GetComponent().color : ((!mix_colors) ? hit1.transform.GetComponent().material.color : ((!Use_light_color) ? Color.Lerp(lightGameObject.GetComponent().color, Color.Lerp(hit1.transform.GetComponent().material.color, GetComponent().color, 0.5f), Color_speed) : Color.Lerp(GetComponent().color, hit1.transform.GetComponent().material.color, Color_speed)))); } else { Texture2D texture2D = hit1.transform.GetComponent().material.mainTexture as Texture2D; bool flag = true; try { if (texture2D != null) { texture2D.GetPixel(0, 0); } else { flag = false; } } catch (UnityException ex) { if (ex.Message.StartsWith("Texture '" + texture2D.name + "' is not readable")) { flag = false; } } if (flag) { Vector2 textureCoord = hit1.textureCoord; textureCoord.x *= texture2D.width; textureCoord.y *= texture2D.height; result = ((!mix_colors) ? texture2D.GetPixel((int)textureCoord.x, (int)textureCoord.y) : ((!Use_light_color) ? Color.Lerp(lightGameObject.GetComponent().color, texture2D.GetPixel((int)textureCoord.x, (int)textureCoord.y), Color_speed) : Color.Lerp(GetComponent().color, lightGameObject.GetComponent().color, Color_speed))); } } } return result; } } }