Ejemplo n.º 1
0
    public void updateRaycastAndSubRaycast(float currDistance, Vector2 startPoint, Quaternion currRotation, RaycastHit2D hit, float residueDistance)
    {
        ConfigRaycast(currDistance, fireWeapon, residueTimes, startPoint, currRotation, maskLayer, raycastHoldTime);
        float residueNextDistance = residueDistance - currDistance;

        if (residueTimes > 0 && residueNextDistance > 0)
        {
            //计算下条的数据信息
            Vector2 incomingVector = hit.point - startPoint;
            Vector2 reflectVector  = Vector2.Reflect(incomingVector, hit.normal);
            Vector2 NextstartPoint = hit.point - incomingVector.normalized * sr.size.y * 0.5f - reflectVector.normalized * sr.size.y * 0.5f + reflectVector.normalized * 0.0001f;


            float nextDistance;

            RaycastHit2D nextHit = Physics2D.Raycast(NextstartPoint, reflectVector, residueNextDistance, LayerMask.GetMask(maskLayer));
            if (nextHit.collider)
            {
                nextDistance = nextHit.fraction * residueNextDistance;
            }
            else
            {
                nextDistance = residueNextDistance;
            }
            Quaternion nextRotation = Quaternion.FromToRotation(Vector2.right, reflectVector);
            if (nextRaycast != null)
            {
                Debug.Log("updateRaycastAndSubRaycast ");
                nextRaycast.updateRaycastAndSubRaycast(nextDistance, NextstartPoint, nextRotation, nextHit, residueNextDistance);
            }
            else if (nextRaycast == null)
            {
                Debug.Log("updateRaycastAndSubRaycast _N");
                //生成
                ReboundRaycast(nextHit, residueNextDistance, incomingVector);
                nextRaycast.updateRaycastAndSubRaycast(nextDistance, NextstartPoint, nextRotation, nextHit, residueNextDistance);
            }
        }
        else
        {
            //没有距离/没有反弹数量了 但是还有链路,则销毁链路
            if (nextRaycast != null)
            {
                nextRaycast.DestroyRaycastChain();
            }
        }
    }