コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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();
                }
            }
        }
コード例 #3
0
 public void RemoveTrigger(AbstractDetectionTrigger <T> detectionTrigger)
 {
     if (Triggers.Contains(detectionTrigger))
     {
         Triggers.Remove(detectionTrigger);
         detectionTrigger.OnTriggerExited  -= NotifyTriggerOut;
         detectionTrigger.OnTriggerEntered -= NotifyTriggerOn;
     }
 }
コード例 #4
0
 public void AddTrigger(AbstractDetectionTrigger <T> detectionTrigger)
 {
     if (!Triggers.Contains(detectionTrigger))
     {
         Triggers.Add(detectionTrigger);
         detectionTrigger.OnTriggerExited  += NotifyTriggerOut;
         detectionTrigger.OnTriggerEntered += NotifyTriggerOn;
     }
 }