예제 #1
0
        private void ProcessTriggers(ref RaycastHit[] hits, ref int hitsLength)
        {
            _currentTriggers = _currentTriggers.View(0, 0);

            for (int i = hitsLength - 1; i >= 0; --i)
            {
                if (hits[i].collider.isTrigger)
                {
                    //if (hits[i].distance == 0) {
                    _currentTriggers.Add(hits[i].collider);
                    //}
                    for (int j = i; j < hitsLength - 1; ++j)
                    {
                        hits[j] = hits[j + 1];
                    }
                    --hitsLength;
                }
            }

            if (InteractsWithTriggers)
            {
                foreach (Collider collider in _currentTriggers)
                {
                    if (_stayTriggers.Contains(collider))
                    {
                        collider.SendMessage("OnTriggerStay", _collider, SendMessageOptions.DontRequireReceiver);
                    }
                    else
                    {
                        collider.SendMessage("OnTriggerEnter", _collider, SendMessageOptions.DontRequireReceiver);
                        _stayTriggers.Add(collider);
                    }
                }

                for (int i = _stayTriggers.Count - 1; i >= 0; --i)
                {
                    Collider collider = _stayTriggers[i];
                    if (!_currentTriggers.Contains(collider))
                    {
                        collider.SendMessage("OnTriggerExit", _collider, SendMessageOptions.DontRequireReceiver);
                        _stayTriggers.Remove(collider);
                    }
                }
            }
        }