public override IAspect Sense(System.Func <IAspect, bool> p = null)
        {
            if (_intersectingColliders.Count == 0)
            {
                return(null);
            }

            if (p == null && !_requiresLineOfSight)
            {
                return(ColliderAspect.GetAspect(_intersectingColliders.First()));
            }
            else
            {
                var e = _intersectingColliders.GetEnumerator();
                while (e.MoveNext())
                {
                    var a = ColliderAspect.GetAspect(e.Current);
                    if ((p == null || p(a)) && (!_requiresLineOfSight || this.IsLineOfSight(e.Current)))
                    {
                        return(a);
                    }
                }
                return(null);
            }
        }
 public override IEnumerable <IAspect> SenseAll(System.Func <IAspect, bool> p = null)
 {
     if (_getAll)
     {
         var hits = this.GetAllHits();
         if (p == null)
         {
             return(from h in hits select ColliderAspect.GetAspect(h.collider) as IAspect);
         }
         else
         {
             return(from h in hits let a = ColliderAspect.GetAspect(h.collider) as IAspect where p(a) select a);
         }
     }
     else if (p == null)
     {
         var hit = this.GetFirstHit();
         return((hit != null) ? new IAspect[] { ColliderAspect.GetAspect(hit) } : Enumerable.Empty <IAspect>());
     }
     else
     {
         var hits = this.GetAllHits();
         var hit  = (from h in hits let a = ColliderAspect.GetAspect(h.collider) as IAspect where p(a) select a).FirstOrDefault();
         return((hit != null) ? new IAspect[] { hit } : Enumerable.Empty <IAspect>());
     }
 }
 public override IEnumerable <IAspect> SenseAll(System.Func <IAspect, bool> p = null)
 {
     if (p == null && !_requiresLineOfSight)
     {
         return((from c in _intersectingColliders select ColliderAspect.GetAspect(c)).ToArray());
     }
     else
     {
         return((from c in _intersectingColliders let a = ColliderAspect.GetAspect(c) where (p == null || p(a)) && (!_requiresLineOfSight || this.IsLineOfSight(c)) select a).ToArray());
     }
 }
 public override IAspect Sense(System.Func <IAspect, bool> p = null)
 {
     if (p == null)
     {
         var hit = this.GetFirstHit();
         return((hit != null) ? ColliderAspect.GetAspect(hit) : null);
     }
     else
     {
         return(this.SenseAll(p).FirstOrDefault());
     }
 }
        public override int SenseAll <T>(ICollection <T> lst, System.Func <T, bool> p = null)
        {
            if (lst == null)
            {
                throw new System.ArgumentNullException("lst");
            }
            if (lst.IsReadOnly)
            {
                throw new System.ArgumentException("List to fill can not be read-only.", "lst");
            }
            if (_intersectingColliders.Count == 0)
            {
                return(0);
            }

            if (p == null && !_requiresLineOfSight)
            {
                int cnt = 0;
                var e   = _intersectingColliders.GetEnumerator();
                while (e.MoveNext())
                {
                    var a = ColliderAspect.GetAspect(e.Current);
                    var o = ObjUtil.GetAsFromSource <T>(a);
                    if (o != null)
                    {
                        lst.Add(o);
                        cnt++;
                    }
                }
                return(cnt);
            }
            else
            {
                var e   = _intersectingColliders.GetEnumerator();
                int cnt = 0;
                while (e.MoveNext())
                {
                    var a = ColliderAspect.GetAspect(e.Current);
                    var o = ObjUtil.GetAsFromSource <T>(a);
                    if ((p == null || p(o)) && (!_requiresLineOfSight || this.IsLineOfSight(e.Current)))
                    {
                        lst.Add(e.Current as T);
                        cnt++;
                    }
                }
                return(cnt);
            }
        }
        protected void OnTriggerEnter(Collider coll)
        {
            if (!this.ConcernedWith(coll))
            {
                return;
            }

            bool none = _intersectingColliders.Count == 0;

            if (_intersectingColliders.Add(coll))
            {
                if (this.HasSensedAspectListeners)
                {
                    this.OnSensedAspect(ColliderAspect.GetAspect(coll));
                }
                if (none)
                {
                    this.OnSensorAlert();
                }
            }
        }
        public override bool SenseAny(System.Func <IAspect, bool> p = null)
        {
            if (p == null && !_requiresLineOfSight)
            {
                return(_intersectingColliders.Count > 0);
            }
            else
            {
                var e = _intersectingColliders.GetEnumerator();
                while (e.MoveNext())
                {
                    var a = ColliderAspect.GetAspect(e.Current);
                    if ((p == null || p(a)) && (!_requiresLineOfSight || this.IsLineOfSight(e.Current)))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public override bool SenseAny(System.Func <IAspect, bool> p = null)
        {
            var t   = this.transform;
            var ray = new Ray(t.position, t.GetAxis(_axis));

            if (p == null)
            {
                if (_radius > 0f)
                {
                    return(Physics.SphereCast(ray, _radius, _distance, _layers));
                }
                else
                {
                    return(Physics.Raycast(ray, _distance, _layers));
                }
            }
            else
            {
                RaycastHit[] arr;
                if (_radius > 0f)
                {
                    arr = Physics.SphereCastAll(ray, _radius, _distance, _layers);
                }
                else
                {
                    arr = Physics.SphereCastAll(ray, _distance, _layers);
                }

                for (int i = 0; i < arr.Length; i++)
                {
                    var a = ColliderAspect.GetAspect(arr[i].collider);
                    if (p(a))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public override int SenseAll(ICollection <IAspect> lst, System.Func <IAspect, bool> p = null)
        {
            if (lst == null)
            {
                throw new System.ArgumentNullException("lst");
            }
            if (lst.IsReadOnly)
            {
                throw new System.ArgumentException("List to fill can not be read-only.", "lst");
            }

            if (_getAll)
            {
                var hits = this.GetAllHits();
                if (p == null)
                {
                    foreach (var h in hits)
                    {
                        lst.Add(ColliderAspect.GetAspect(h.collider));
                    }
                    return(hits.Length);
                }
                else
                {
                    int     cnt = 0;
                    IAspect a;
                    foreach (var h in hits)
                    {
                        a = ColliderAspect.GetAspect(h.collider);
                        if (p(a))
                        {
                            lst.Add(a);
                            cnt++;
                        }
                    }
                    return(cnt);
                }
            }
            else if (p == null)
            {
                var hit = this.GetFirstHit();
                if (hit != null)
                {
                    lst.Add(ColliderAspect.GetAspect(hit));
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                var hits = this.GetAllHits();
                var hit  = (from h in hits let a = ColliderAspect.GetAspect(h.collider) as IAspect where p(a) select a).FirstOrDefault();
                if (hit != null)
                {
                    lst.Add(hit);
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
        }