Exemplo n.º 1
0
        private void MatryoshkaColliders_TriggerStay(object sender, ColliderTriggerEvent e)
        {
            ColliderTrigger ct = sender as ColliderTrigger;

            if (deepestColliderStay == null)
            {
                deepestColliderStay = ct;
                OnTStay(e.collider, ct.Collider);
            }
            else
            {
                if (greaterOrEqual)
                {
                    if (deepestColliderStay.depth >= ct.depth)
                    {
                        deepestColliderStay = ct;
                        OnTStay(e.collider, ct.Collider);
                    }
                }
                else
                {
                    if (deepestColliderStay.depth > ct.depth)
                    {
                        deepestColliderStay = ct;
                        OnTStay(e.collider, ct.Collider);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public List <ColliderTrigger> GetOuterColliders(ColliderTrigger colliderTrigger, bool greaterOrEqual = false)
 {
     if (greaterOrEqual)
     {
         return(_colliders.FindAll(c => c.depth >= colliderTrigger.depth));
     }
     else
     {
         return(_colliders.FindAll(c => c.depth > colliderTrigger.depth));
     }
 }
 public void RemoveColliderTrigger(ColliderTrigger colliderTrigger)
 {
     if (_colliders.IndexOf(colliderTrigger) >= 0)
     {
         _colliders.RemoveAll(c => c == colliderTrigger);
         colliderTrigger.TriggerEnter -= ColliderTrigger_TriggerEnter;
         colliderTrigger.TriggerStay  -= ColliderTrigger_TriggerStay;
         colliderTrigger.TriggerExit  -= ColliderTrigger_TriggerExit;
     }
     else
     {
         Debug.LogWarning("Removing a ColliderTrigger that isnt in the list");
     }
 }
 public void AddColliderTrigger(ColliderTrigger newColliderTrigger)
 {
     if (_colliders.IndexOf(newColliderTrigger) < 0)
     {
         _colliders.Add(newColliderTrigger);
         newColliderTrigger.TriggerEnter += ColliderTrigger_TriggerEnter;
         newColliderTrigger.TriggerStay  += ColliderTrigger_TriggerStay;
         newColliderTrigger.TriggerExit  += ColliderTrigger_TriggerExit;
     }
     else
     {
         Debug.LogWarning("Adding a ColliderTrigger that is already in the list");
     }
 }
        private void Setup()
        {
            _colliders.Clear();
            List <Collider> temp = GetComponentsInChildren <Collider>().ToList();

            for (int i = 0; i < temp.Count; i++)
            {
                ColliderTrigger ct = temp[i].GetComponent <ColliderTrigger>();
                if (ct == null)
                {
                    ct = temp[i].gameObject.AddComponent <ColliderTrigger>();
                }
                _colliders.Add(ct);
            }
        }
Exemplo n.º 6
0
        private void MatryoshkaColliders_TriggerExit(object sender, ColliderTriggerEvent e)
        {
            ColliderTrigger ct = sender as ColliderTrigger;

            deepestColliderExit = ct;
            if (deepestColliderExit == deepestColliderEnter)
            {
                deepestColliderEnter = null;
            }

            if (deepestColliderExit == deepestColliderStay)
            {
                deepestColliderStay = null;
            }
            OnTExit(e.collider, ct.Collider);

            //if (deepestColliderExit == null)
            //{
            //    deepestColliderExit = ct;
            //    OnTExit(e.collider, ct.Collider);
            //}
            //else
            //{
            //    if (greaterOrEqual)
            //    {
            //        if (deepestColliderExit.depth <= ct.depth)
            //        {
            //            deepestColliderExit = ct;
            //            OnTExit(e.collider, ct.Collider);
            //        }
            //    }
            //    else
            //    {
            //        if (deepestColliderExit.depth < ct.depth)
            //        {
            //            deepestColliderExit = ct;
            //            OnTExit(e.collider, ct.Collider);
            //        }
            //    }

            //    if (deepestColliderExit == deepestColliderEnter)
            //        deepestColliderEnter = null;

            //    if (deepestColliderExit == deepestColliderStay)
            //        deepestColliderStay = null;
            //}
        }
        private void ColliderTrigger_TriggerStay(object sender, ColliderTriggerEvent e)
        {
            ColliderTrigger s = sender as ColliderTrigger;

            if (ignoreSelfColliders)
            {
                if (_colliders.Exists(c => c.Collider == e.collider))
                {
                    return;
                }
            }

            foreach (Collider c in GetStayColliders())
            {
                OnTStay(c, s.Collider);
            }
        }
        private void ColliderTrigger_TriggerEnter(object sender, ColliderTriggerEvent e)
        {
            ColliderTrigger s = sender as ColliderTrigger;

            if (ignoreSelfColliders)
            {
                if (_colliders.Exists(c => c.Collider == e.collider))
                {
                    return;
                }
            }

            if (_currentStayingColliders.IndexOf(e.collider) < 0)
            {
                _currentStayingColliders.Add(e.collider);
                OnTEnter(e.collider, s.Collider);
            }
        }
        private void ColliderTrigger_TriggerExit(object sender, ColliderTriggerEvent e)
        {
            ColliderTrigger s = sender as ColliderTrigger;

            if (ignoreSelfColliders)
            {
                if (_colliders.Exists(c => c.Collider == e.collider))
                {
                    return;
                }
            }

            if (!exitTriggerAll)
            {
                if (_currentStayingColliders.IndexOf(e.collider) >= 0)
                {
                    _currentStayingColliders.Remove(e.collider);
                    OnTExit(e.collider, s.Collider);
                    return;
                }
                return;
            }
            else
            {
                foreach (ColliderTrigger ct in _colliders)
                {
                    if (ct.CurrentStayingCollider.IndexOf(e.collider) >= 0)
                    {
                        return;
                    }
                }

                if (_currentStayingColliders.IndexOf(e.collider) >= 0)
                {
                    _currentStayingColliders.Remove(e.collider);
                    OnTExit(e.collider, s.Collider);
                    return;
                }
            }
        }