Пример #1
0
 private static bool SourceInCollisionTest(Vector3 sourcePoint, out GenericActionKind kind,
                                           out float yTranslateOffset)
 {
     _kind            = kind = GenericActionKind.Null;
     yTranslateOffset = 0.0f;
     return(Physics.OverlapSphere(sourcePoint, 0.3f, UnityLayers.SceneCollidableLayerMask).Length > 0);
 }
Пример #2
0
        private static void ClimbUpTest(Vector3 collisionPoint, PlayerEntity player, out GenericActionKind kind,
                                        out float yTranslateOffset)
        {
            _kind            = kind = GenericActionKind.Null;
            yTranslateOffset = 0.0f;

            var playerTransform = player.RootGo().transform;
            var distance        = collisionPoint.y - playerTransform.position.y;

            if (distance < MinClimbHeight || distance > MaxClimbHeight)
            {
                return;
            }

            //最终位置能否站人
            var overlapPos = collisionPoint + playerTransform.up * 0.2f;

            PlayerEntityUtility.GetCapsule(player, overlapPos, out _capsuleBottom, out _capsuleUp,
                                           out _capsuleRadius);
            if (Physics.OverlapCapsule(_capsuleBottom, _capsuleUp, _capsuleRadius, UnityLayers.SceneCollidableLayerMask)
                .Length > 0)
            {
                return;
            }

            _kind        = kind = CheckClimbKindByDistance(distance, GenericActionKind.Climb50Cm, out yTranslateOffset);
            _matchTarget = collisionPoint;
        }
Пример #3
0
        private static GenericActionKind CheckClimbKindByDistance(float distance, GenericActionKind kind, out float yOffset)
        {
            if (distance > 0.4 && distance <= 0.9)
            {
                yOffset = distance - 0.5f;
                return((GenericActionKind)((int)kind + 0));
            }

            if (distance > 0.9 && distance <= 1.4)
            {
                yOffset = distance - 1.0f;
                return((GenericActionKind)((int)kind + 1));
            }

            if (distance > 1.4 && distance <= 1.9)
            {
                yOffset = distance - 1.5f;
                return((GenericActionKind)((int)kind + 2));
            }

            if (distance > 1.9 && distance <= 2.3)
            {
                yOffset = distance - 2.0f;
                return((GenericActionKind)((int)kind + 3));
            }

            yOffset = 0;
            return(GenericActionKind.Null);
        }
Пример #4
0
        // 自上而下
        private static void DownRayTest(PlayerEntity player, out GenericActionKind kind, out Vector3 matchTarget)
        {
            var sphereCenter = new Vector3(_hit.point.x,
                                           _hit.collider.bounds.center.y + _hit.collider.bounds.extents.y + _capsuleHeight, _hit.point.z);

            if (SourceInCollisionTest(sphereCenter, out kind, out matchTarget))
            {
                return;
            }

            RaycastHit sphereHit;

            Physics.SphereCast(sphereCenter, 0.3f, Vector3.down, out sphereHit,
                               _hit.collider.bounds.center.y + _hit.collider.bounds.extents.y + _capsuleHeight,
                               UnityLayers.SceneCollidableLayerMask);

            if (VaultUpTest(sphereHit.point, player, out kind, out matchTarget))
            {
                return;
            }
            if (ClimbUpTest(sphereHit.point, player, out kind, out matchTarget))
            {
                return;
            }
            StepUpTest(sphereHit.point, player, out kind, out matchTarget);
        }
Пример #5
0
        private void CreateConcretenessAction(GenericActionKind kind, Vector3 matchTarget)
        {
            ResetConcretenessAction();

            switch (kind)
            {
            case GenericActionKind.Climb:
                _concretenessAction = _climbAction;
                break;

            case GenericActionKind.Step:
                _concretenessAction = _stepAction;
                break;

            case GenericActionKind.Vault:
                _concretenessAction = _vaultAction;
                break;

            case GenericActionKind.Null:
                _concretenessAction = null;
                break;

            default:
                _concretenessAction = null;
                break;
            }

            if (null == _concretenessAction)
            {
                return;
            }
            _concretenessAction.MatchTarget      = matchTarget;
            _concretenessAction.CanTriggerAction = true;
        }
Пример #6
0
 //四方向,镂空模型测试
 private static void AllRoundRayTest(PlayerEntity player, out GenericActionKind kind, out float yTranslateOffset)
 {
     if (RoundTestByYDistance(AllRoundCastYoOffsetOne, player, out kind, out yTranslateOffset))
     {
         return;
     }
     RoundTestByYDistance(AllRoundCastYoOffsetTwo, player, out kind, out yTranslateOffset);
 }
Пример #7
0
 public static void ClimbUpTypeTest(PlayerEntity player, out GenericActionKind climbUpKind, out Vector3 matchTarget)
 {
     DownRayTest(player, out climbUpKind, out matchTarget);
     if (GenericActionKind.Null == climbUpKind)
     {
         AllRoundRayTest(player, out climbUpKind, out matchTarget);
     }
 }
Пример #8
0
 public static void ClimbUpTypeTest(PlayerEntity player, out GenericActionKind climbUpKind,
                                    out float yTranslateOffset, out float yRotationOffset)
 {
     yRotationOffset = CreateMatchQuaternion(player.RootGo().transform.forward, -_hit.normal);
     DownRayTest(player, out climbUpKind, out yTranslateOffset);
     if (GenericActionKind.Null == climbUpKind)
     {
         AllRoundRayTest(player, out climbUpKind, out yTranslateOffset);
     }
 }
Пример #9
0
        private static void StepUpTest(Vector3 collisionPoint, PlayerEntity player, out GenericActionKind kind, out Vector3 matchTarget)
        {
            var playerTransform = player.RootGo().transform;
            var distance        = collisionPoint.y - playerTransform.position.y;

            if (distance > 0.5 && distance <= 1.5)
            {
                kind        = GenericActionKind.Step;
                matchTarget = collisionPoint - playerTransform.right * 0.2f;
                return;
            }

            kind        = GenericActionKind.Null;
            matchTarget = Vector3.zero;
        }
Пример #10
0
        private static bool ClimbUpTest(Vector3 collisionPoint, PlayerEntity player, out GenericActionKind kind, out Vector3 matchTarget)
        {
            var playerTransform = player.RootGo().transform;
            var distance        = collisionPoint.y - playerTransform.position.y;

            if (distance > 1.5 && distance < 2.3)
            {
                kind        = GenericActionKind.Climb;
                matchTarget = collisionPoint - playerTransform.right * 0.2f;
                return(true);
            }

            kind        = GenericActionKind.Null;
            matchTarget = Vector3.zero;
            return(false);
        }
Пример #11
0
        private static bool VaultUpTest(Vector3 collisionPoint, PlayerEntity player, out GenericActionKind kind,
                                        out float yTranslateOffset)
        {
            _kind            = kind = GenericActionKind.Null;
            yTranslateOffset = 0.0f;

            var playerTransform = player.RootGo().transform;
            var distance        = collisionPoint.y - playerTransform.position.y;

            if (distance < MinVaultHeight || distance > MaxVaultHeight)
            {
                return(false);
            }

            // 检测翻越过程中障碍
            var testPoint = new Vector3(playerTransform.position.x, collisionPoint.y, playerTransform.position.z);

            _capsuleBottom = testPoint + playerTransform.up * 0.3f;
            _capsuleUp     = _capsuleBottom + playerTransform.up * 0.5f;
            if (Physics.CapsuleCast(_capsuleBottom, _capsuleUp, 0.1f, _matchForward,
                                    1, UnityLayers.SceneCollidableLayerMask))
            {
                return(false);
            }

            //
            _overlapPos   = playerTransform.position + _matchForward * (VaultPly + 2.0f * _capsuleRadius - PlayerEntityUtility.CcSkinWidth);
            _overlapPos.y = (collisionPoint + -playerTransform.up * (VaultHeightLimit + 2 * PlayerEntityUtility.CcSkinWidth)).y;

            PlayerEntityUtility.GetCapsule(player, _overlapPos, out _capsuleBottom, out _capsuleUp,
                                           out _capsuleRadius);

//            DebugDraw.DebugWireSphere(_overlapPos, Color.red, 0.4f, 10.0f);
//            DebugDraw.DebugWireSphere(_capsuleBottom, Color.yellow, 0.4f, 10.0f);
//            DebugDraw.DebugWireSphere(_capsuleUp, Color.yellow, 0.4f, 10.0f);

            if (Physics.OverlapCapsule(_capsuleBottom, _capsuleUp, _capsuleRadius,
                                       UnityLayers.SceneCollidableLayerMask).Length > 0)
            {
                return(false);
            }

            _kind        = kind = CheckClimbKindByDistance(distance, GenericActionKind.Vault50Cm, out yTranslateOffset);
            _matchTarget = collisionPoint;
            return(true);
        }
Пример #12
0
        private void CreateConcretenessAction(GenericActionKind kind, float yTranslateOffset, float yRotationOffset)
        {
            ResetConcretenessAction();

            if ((int)kind < 0 || (int)kind >= _climbClasses.Length)
            {
                return;
            }

            _concretenessAction = _climbClasses[(int)kind];

            if (null == _concretenessAction)
            {
                return;
            }

            _concretenessAction.ModelYTranslateOffset = yTranslateOffset;
            _concretenessAction.ModelYRotationOffset  = yRotationOffset;
            _concretenessAction.CanTriggerAction      = true;
        }
Пример #13
0
        private static bool RoundTestByYDistance(float yDistance, PlayerEntity player, out GenericActionKind kind,
                                                 out float yTranslateOffset)
        {
            _kind            = kind = GenericActionKind.Null;
            yTranslateOffset = 0.0f;
            var playerTransform = player.RootGo().transform;

            // boxCast 测试前方向是否有障碍物
            var castStartPos = playerTransform.position + playerTransform.up * yDistance;

            if (Physics.BoxCast(castStartPos, new Vector3(0.05f, 0.05f, 0.05f), _matchForward,
                                playerTransform.rotation,
                                1.0f, UnityLayers.SceneCollidableLayerMask))
            {
                return(false);
            }

            var castCenter = castStartPos + _matchForward * AllRoundCastZoOffset;

            AllRoundRayTestImpl(castCenter, player, out kind, out yTranslateOffset);

            return(GenericActionKind.Null != kind);
        }
Пример #14
0
        // Vault测试需在Step测试之前
        private static bool VaultUpTest(Vector3 collisionPoint, PlayerEntity player, out GenericActionKind kind, out Vector3 matchTarget)
        {
            kind        = GenericActionKind.Null;
            matchTarget = Vector3.zero;

            var playerTransform = player.RootGo().transform;
            var distance        = collisionPoint.y - playerTransform.position.y;

            if (distance < 0.8 || distance > 2.3)
            {
                return(false);
            }

            // 检测翻越过程中障碍
            _capsuleBottom.y = (collisionPoint + playerTransform.up * 0.3f).y;
            _capsuleUp.y     = _capsuleBottom.y + _capsuleHeight;
            if (Physics.CapsuleCast(_capsuleBottom, _capsuleUp, 0.1f, playerTransform.forward,
                                    1, UnityLayers.SceneCollidableLayerMask))
            {
                return(false);
            }

            // 人物当前位置,往前移动1m,往上移动0.2m
            _overlapPos = playerTransform.position + playerTransform.forward * (1.0f + _capsuleRadius) +
                          playerTransform.up * 0.2f;
            PlayerEntityUtility.GetCapsule(player, _overlapPos, out _capsuleBottom, out _capsuleUp,
                                           out _capsuleRadius);
            if (Physics.OverlapCapsule(_capsuleBottom, _capsuleUp, _capsuleRadius,
                                       UnityLayers.SceneCollidableLayerMask).Length > 0)
            {
                return(false);
            }

            kind        = GenericActionKind.Vault;
            matchTarget = collisionPoint - playerTransform.right * 0.2f;
            return(true);
        }
Пример #15
0
        private static void AllRoundRayTestImpl(Vector3 castCenter, PlayerEntity player, out GenericActionKind kind,
                                                out float yTranslateOffset)
        {
            _kind            = kind = GenericActionKind.Null;
            yTranslateOffset = 0.0f;

            Vector3 top, bottom, left, right;

            CalcBorderHitPoint(castCenter, Vector3.up, _matchRotation, out top);
            CalcBorderHitPoint(castCenter, -Vector3.up, _matchRotation, out bottom);
            CalcBorderHitPoint(castCenter, -_matchRight, _matchRotation, out left);
            CalcBorderHitPoint(castCenter, _matchRight, _matchRotation, out right);

            if (Vector3.Distance(top, bottom) < 1.0f || Vector3.Distance(left, right) < 0.8f)
            {
                return;
            }

            if (VaultUpTest(bottom, player, out kind, out yTranslateOffset))
            {
                return;
            }
            ClimbUpTest(bottom, player, out kind, out yTranslateOffset);
        }
Пример #16
0
 public VaultUp(GenericActionKind kind)
 {
     _kind = kind;
 }
Пример #17
0
 private static bool SourceInCollisionTest(Vector3 sourcePoint, out GenericActionKind kind, out Vector3 matchTarget)
 {
     kind        = GenericActionKind.Null;
     matchTarget = Vector3.zero;
     return(Physics.OverlapSphere(sourcePoint, 0.3f, UnityLayers.SceneCollidableLayerMask).Length > 0);
 }
Пример #18
0
 public ClimbUp(GenericActionKind kind)
 {
     _kind = kind;
 }
Пример #19
0
 //四方向
 private static void AllRoundRayTest(PlayerEntity player, out GenericActionKind kind, out Vector3 matchTarget)
 {
     kind        = GenericActionKind.Null;
     matchTarget = Vector3.zero;
 }