/** * Adds the specified detector to the list of observed detectors. * * The same detector cannot be added more than once. * @param Detector the detector to watch. * @since 4.1.2 */ public void AddDetector(Detector detector){ if(!Detectors.Contains(detector)){ Detectors.Add(detector); activateDetector(detector); } }
/** * Removes the specified detector from the list of observed detectors; * * @param Detector the detector to remove. * @since 4.1.2 */ public void RemoveDetector(Detector detector){ detector.OnActivate.RemoveListener(CheckDetectors); detector.OnDeactivate.RemoveListener(CheckDetectors); Detectors.Remove(detector); }
private void activateDetector(Detector detector){ detector.OnActivate.RemoveListener(CheckDetectors); //avoid double subscription detector.OnDeactivate.RemoveListener(CheckDetectors); detector.OnActivate.AddListener(CheckDetectors); detector.OnDeactivate.AddListener(CheckDetectors); }