Ejemplo n.º 1
0
        public bool Raycast(RaySegment ray, out RaycastHit hitInfo, int hitboxLayerMask)
        {
            for (int i = 0; i < _entities.Length; i++)
            {
                IGameEntity entity = _entities[i];
                if (!entity.IsCompensation)
                {
                    continue;
                }
                if (!entity.HasComponent <PositionComponent>())
                {
                    continue;
                }
                if (entity.EntityKey == Self)
                {
                    _hitboxHandler.EnableHitBox(entity, false);
                    continue;
                }
                if (entity.EntityType == Self.EntityType && ExcludePlayerList.Contains(entity.EntityId))
                {
                    _hitboxHandler.EnableHitBox(entity, false);
                    continue;
                }
                if (!_updateAndEnabled[i]) // 同一个serverTime,hitbox只需要计算一次
                {
                    Vector3 position;
                    float   radius;
                    if (_hitboxHandler.GetPositionAndRadius(entity, out position, out radius))
                    {
                        if (IsLineInPointRadius(ray.Ray.origin, ray.Ray.GetPoint(ray.Length), position, radius))
                        {
                            try
                            {
                                _enableHitBox.BeginProfileOnlyEnableProfile();
                                _hitboxHandler.EnableHitBox(entity, true);
                                _hitboxHandler.UpdateHitBox(entity);
                                _hitboxHandler.DrawHitBoxOnBullet(entity);
                                _updateAndEnabled[i] = true;
                            }
                            finally
                            {
                                _enableHitBox.EndProfileOnlyEnableProfile();
                            }
                        }
                    }
                    else
                    {
                        _updateAndEnabled[i] = true;
                        Logger.ErrorFormat("{0} Is Not Exist any more", entity.EntityKey);
                    }
                }
            }



            return(_hitboxHandler.Raycast(ray.Ray, out hitInfo, ray.Length, hitboxLayerMask));
        }
Ejemplo n.º 2
0
 public static float DistanceToLine(RaySegment ray, Vector3 point)
 {
     return(DistanceToLine(ray.Ray.origin, ray.Ray.GetPoint(ray.Length), point));
 }
Ejemplo n.º 3
0
        public bool Raycast(RaySegment ray, out RaycastHit hitInfo, int hitboxLayerMask, int cmdSeq)
        {
            if (pphysicsCast == null)
            {
                pphysicsCast = SingletonManager.Get <DurationHelp>().GetCustomProfileInfo("pphysicsCast");
            }
            if (plogicCast == null)
            {
                plogicCast = SingletonManager.Get <DurationHelp>().GetCustomProfileInfo("plogicCast");
            }
            plogicCast.BeginProfileOnlyEnableProfile();
            for (int i = 0; i < _entities.Length; i++)
            {
                IGameEntity entity = _entities[i];

                if (!entity.IsCompensation)
                {
                    continue;
                }
                if (!entity.HasComponent <PositionComponent>())
                {
                    continue;
                }

                if (entity.EntityKey == Self)
                {
                    _hitboxHandler.EnableHitBox(entity, false);
                    continue;
                }

                if (entity.EntityType == Self.EntityType && ExcludePlayerList.Contains(entity.EntityId))
                {
                    _hitboxHandler.EnableHitBox(entity, false);
                    continue;
                }

                bool isLineInPoint = false;

                if (!_updateAndEnabled[i]) // 同一个serverTime,hitbox只需要计算一次
                {
                    Vector3 position;
                    float   radius;
                    //获取当前物体逻辑层位置信息(非transform)
                    if (_hitboxHandler.GetPositionAndRadius(entity, out position, out radius))
                    {
                        //当前Ray行动轨迹是否打在Radius上,圆形碰撞检测
                        isLineInPoint = (IsLineInPointRadius(ray.Ray.origin, ray.Ray.GetPoint(ray.Length),
                                                             position, radius));
                        if (isLineInPoint)
                        {
                            try
                            {
                                _enableHitBox.BeginProfileOnlyEnableProfile();
                                //开启collider和Rigidbody
                                _hitboxHandler.EnableHitBox(entity, true);
                                //更新碰撞组件及物体实际位置信息
                                _hitboxHandler.UpdateHitBox(entity, _serverTime, cmdSeq);
                                _hitboxHandler.DrawHitBoxOnBullet(entity);
                                _updateAndEnabled[i] = true;
                            }
                            finally
                            {
                                _enableHitBox.EndProfileOnlyEnableProfile();
                            }
                        }

                        // DebugUtil.AppendShootText(cmdSeq,
                        //     "[Inspect]Ray:{0},target player postion:{1},radius:{2},isLineInPoint:{3}", ray.Ray, position, radius,
                        //     isLineInPoint);
                    }
                    else
                    {
                        _updateAndEnabled[i] = true;
                        //   Logger.ErrorFormat("{0} Is Not Exist any more", entity.EntityKey);
                        Logger.ErrorFormat("[Hit{0}]GetPositionAndRadius Expection", cmdSeq);
                    }
                }
                else
                {
                    Vector3 position;
                    float   radius;
                    if (_hitboxHandler.GetPositionAndRadius(entity, out position, out radius))
                    {
                        //当前Ray行动轨迹是否打在Radius上
                        isLineInPoint = (IsLineInPointRadius(ray.Ray.origin, ray.Ray.GetPoint(ray.Length),
                                                             position, radius));
                        if (isLineInPoint)
                        {
                            _hitboxHandler.EnableHitBox(entity, true);
                        }
                    }
                    else
                    {
                        _updateAndEnabled[i] = true;
                        //   Logger.ErrorFormat("{0} Is Not Exist any more", entity.EntityKey);
                        Logger.ErrorFormat("[Hit{0}]GetPositionAndRadius Expection", cmdSeq);
                    }
                }
            }
            plogicCast.EndProfileOnlyEnableProfile();
            pphysicsCast.BeginProfileOnlyEnableProfile();
            var val = _hitboxHandler.Raycast(ray.Ray, out hitInfo, ray.Length, hitboxLayerMask);

            pphysicsCast.EndProfileOnlyEnableProfile();
            return(val);
        }