void NotifyTriggerOn(AbstractDetectionTrigger <T> detectionTrigger) { if (!triggersThatDetected.ContainsKey(detectionTrigger.LastDetectedObject)) { triggersThatDetected.Add(detectionTrigger.LastDetectedObject, new List <AbstractDetectionTrigger <T> >()); triggersThatDetected[detectionTrigger.LastDetectedObject].Add(detectionTrigger); if (!CurrentObjectDetected.Contains(detectionTrigger.LastDetectedObject)) { CurrentObjectDetected.Add(detectionTrigger.LastDetectedObject); } if (!IsTriggered) { IsTriggered = true; InvokeTriggerEntered(); OnFirstObjectEntered.Invoke(); } else { OnNewObjectEntered.Invoke(); } } else { //the object was already detected, just note down that the trigger detected it. triggersThatDetected[detectionTrigger.LastDetectedObject].Add(detectionTrigger); } }
void NotifyTriggerOut(AbstractDetectionTrigger <T> detectionTrigger) { if (!triggersThatDetected.ContainsKey(detectionTrigger.LastDetectedObject)) { return; } triggersThatDetected[detectionTrigger.LastDetectedObject].Remove(detectionTrigger); if (triggersThatDetected[detectionTrigger.LastDetectedObject].Count != 0) { return; } triggersThatDetected.Remove(detectionTrigger.LastDetectedObject); if (CurrentObjectDetected.Contains(detectionTrigger.LastDetectedObject)) { CurrentObjectDetected.Remove(detectionTrigger.LastDetectedObject); if (CurrentObjectDetected.Count == 0) { IsTriggered = false; OnLastObjectExited.Invoke(); InvokeTriggerExited(); } else { OnObjectExited.Invoke(); } } }
public void RemoveTrigger(AbstractDetectionTrigger <T> detectionTrigger) { if (Triggers.Contains(detectionTrigger)) { Triggers.Remove(detectionTrigger); detectionTrigger.OnTriggerExited -= NotifyTriggerOut; detectionTrigger.OnTriggerEntered -= NotifyTriggerOn; } }
public void AddTrigger(AbstractDetectionTrigger <T> detectionTrigger) { if (!Triggers.Contains(detectionTrigger)) { Triggers.Add(detectionTrigger); detectionTrigger.OnTriggerExited += NotifyTriggerOut; detectionTrigger.OnTriggerEntered += NotifyTriggerOn; } }