Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
IgnoreLightSource.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 using System.Linq;
3 using UnityEngine;
4 
5 namespace droid.Runtime.Utilities.GameObjects.NeodroidCamera {
9  [ExecuteInEditMode]
10  public class IgnoreLightSource : MonoBehaviour {
11  [SerializeField] bool _automatically_add_lights_without_infrared_component = false;
12  [SerializeField] bool _ignore_infrared_if_empty = true;
13 
14  [SerializeField] Light[] _lights_to_ignore = null;
15 
16  // Use this for initialization
17  void Start() {
18  if (this._lights_to_ignore == null
19  || this._lights_to_ignore.Length == 0 && this._ignore_infrared_if_empty) {
20  var infrared_light_sources = FindObjectsOfType<InfraredLightSource>();
21  var lights = new List<Light>();
22  foreach (var ils in infrared_light_sources) {
23  lights.Add(ils.GetComponent<Light>());
24  }
25 
26  this._lights_to_ignore = lights.ToArray();
27  } else if (this._automatically_add_lights_without_infrared_component) {
28  var lights = this._lights_to_ignore.ToList();
29  var d = FindObjectsOfType<Light>();
30  foreach (var light1 in d) {
31  if (!light1.gameObject.GetComponent<InfraredLightSource>()) {
32  if (!lights.Exists(l => l != null && light1.GetHashCode() == l.GetHashCode())) {
33  lights.Add(light1);
34  }
35  }
36  }
37 
38  this._lights_to_ignore = lights.ToArray();
39  }
40  }
41 
42  // Update is called once per frame
43  void Update() { }
44 
45  void OnPreCull() {
46  if (this._lights_to_ignore != null) {
47  foreach (var l in this._lights_to_ignore) {
48  if (l) {
49  l.enabled = false;
50  }
51  }
52  }
53  }
54 
55  void OnPreRender() {
56  if (this._lights_to_ignore != null) {
57  foreach (var l in this._lights_to_ignore) {
58  if (l) {
59  l.enabled = false;
60  }
61  }
62  }
63  }
64 
65  void OnPostRender() {
66  if (this._lights_to_ignore != null) {
67  foreach (var l in this._lights_to_ignore) {
68  if (l) {
69  l.enabled = true;
70  }
71  }
72  }
73  }
74  }
75 }