示例#1
0
        /// <summary>
        /// Check if the given cover is fitting.
        /// </summary>
        private bool doesCoverFit(Cover cover, bool checkDistance)
        {
            if (cover == null || cover.Top < _position.y + 0.5f)
            {
                return(false);
            }

            var position = _position + cover.Forward * _capsuleRadius;
            var distance = Vector3.Distance(position, cover.ClosestPointTo(position, 0, 0));

            float radius;

            if (cover == _current.Main)
            {
                radius = cover.CheckTall(_position.y) ? _settings.TallSideLeaveRadius : _settings.LowSideLeaveRadius;
            }
            else
            {
                radius = cover.CheckTall(_position.y) ? _settings.TallSideEnterRadius : _settings.LowSideEnterRadius;
            }

            var isInFront = cover.IsInFront(_position, cover == _current.Main) &&
                            (cover.IsInFront(_position + cover.Right * radius, cover == _current.Main) || cover.RightAdjacent != null) &&
                            (cover.IsInFront(_position + cover.Left * radius, cover == _current.Main) || cover.LeftAdjacent != null);

            if (checkDistance)
            {
                var isOld = isInFront && distance <= _settings.LeaveDistance && cover == _current.Main;
                if (isOld)
                {
                    return(true);
                }

                var isNew = isInFront && distance <= _settings.EnterDistance && cover != _current.Main;
                if (isNew)
                {
                    return(true);
                }

                return(false);
            }
            else
            {
                return(isInFront);
            }
        }