示例#1
0
    public bool IsPlayerInView_ConsideringCampWall()
    {
        if (plHead == null)
        {
            print("Player's head is not assigned. Do it!");
            return(false);
        }

        Vector3 raycastDirection = plHead.position - soldHead.position;
        float   rayDirMag        = raycastDirection.magnitude;
        float   range            = rayDirMag;

        if (range > charInfo.Range)
        {
            return(false);
        }

        Vector3 raycastStart = soldHead.position;

        RaycastHit[] hits = Physics.RaycastAll(raycastStart, raycastDirection, range, GameGeneralInfo.Instance.SoldierCampModeViewRaycastLayer);

        foreach (RaycastHit hit in hits)
        {
            if (hit.transform.root == gameObject.transform)
            {
                continue;
            }

            if (hit.transform.gameObject.tag.ToLower() == GeneralStats.camWallTagName_ToLower)
            {
                CampWall cWall = hit.transform.gameObject.GetComponent <CampWall>();

                if (mapLogic.CanKeepRaycastingThroughCampWall(cWall, hit.point))
                {
                    continue;
                }
            }

            return(false);
        }

        return(true);
    }
示例#2
0
    public bool IsPlayerInView_ForCamp()
    {
        if (PlayerCharacterNew.Instance == null)
        {
            Debug.LogError("Player doesn't exist in map!");
            return(false);
        }

        PlayerCharacterNew player    = PlayerCharacterNew.Instance;
        GameObject         playerObj = PlayerCharacterNew.Instance.gameObject;

        Vector3    rayCastPos  = soldierEye.position;
        Quaternion rayCastRot  = soldierEye.rotation;
        float      viewRange   = mapLogic.camp_CurUpdate_SoldsViewRange * mapLogic.campSoldierViewRangeCoef;
        float      viewHalfAng = mapLogic.camp_CurUpdate_SoldsViewAngle;

        float distToPlayer = Vector3.Magnitude(playerObj.transform.position - transform.position);

        //Back
        if (player.IsVertMovementState(PlayerVertMovementStateEnum.Stand) || player.IsVertMovementState(PlayerVertMovementStateEnum.Jump))
        {
            if (distToPlayer <= SoldierStats.campSoldier_BackMaxDist)
            {
                Transform targTr = player.campViewRaysactTargets[0];

                if (!GeneralStats.IsVecInView(targTr.position, rayCastPos, rayCastRot, -viewHalfAng, viewHalfAng, viewRange)) //<--- NOT
                {
                    Vector3 raycastDirection = targTr.position - soldierEye.position;
                    float   rayDirMag        = raycastDirection.magnitude;
                    float   range            = rayDirMag;

                    if (range > viewRange)
                    {
                        return(false);
                    }

                    Vector3 raycastStart = soldierEye.position;

                    RaycastHit[] hits = Physics.RaycastAll(raycastStart, raycastDirection, range, GameGeneralInfo.Instance.SoldierCampModeViewRaycastLayer);

                    bool isHittedToObs = false;

                    foreach (RaycastHit hit in hits)
                    {
                        if (hit.transform.root == gameObject.transform)
                        {
                            continue;
                        }

                        if (hit.transform.gameObject.tag.ToLower() == GeneralStats.camWallTagName_ToLower)
                        {
                            CampWall cWall = hit.transform.gameObject.GetComponent <CampWall>();

                            if (mapLogic.CanKeepRaycastingThroughCampWall(cWall, hit.point))
                            {
                                continue;
                            }
                        }

                        isHittedToObs = true;
                    }

                    if (!isHittedToObs)
                    {
                        return(true);
                    }
                }
            }
        }

        foreach (Transform targTr in player.campViewRaysactTargets)
        {
            if (!GeneralStats.IsVecInView(targTr.position, rayCastPos, rayCastRot, -viewHalfAng, viewHalfAng, viewRange))
            {
                return(false);
            }

            Vector3 raycastDirection = targTr.position - soldierEye.position;
            float   rayDirMag        = raycastDirection.magnitude;
            float   range            = rayDirMag;

            if (range > viewRange)
            {
                return(false);
            }

            Vector3 raycastStart = soldierEye.position;

            RaycastHit[] hits = Physics.RaycastAll(raycastStart, raycastDirection, range, GameGeneralInfo.Instance.SoldierCampModeViewRaycastLayer);

            foreach (RaycastHit hit in hits)
            {
                if (hit.transform.root == gameObject.transform)
                {
                    continue;
                }

                if (hit.transform.gameObject.tag.ToLower() == GeneralStats.camWallTagName_ToLower)
                {
                    CampWall cWall = hit.transform.gameObject.GetComponent <CampWall>();

                    if (mapLogic.CanKeepRaycastingThroughCampWall(cWall, hit.point))
                    {
                        continue;
                    }
                }

                return(false);
            }
        }

        return(true);

        //CharRaycastResult charRaycastRes;

        //mapLogic.IsCharacterOkAsTarget(gameObject, playerObj, soldierEye.position, soldierEye.rotation, viewRange, -viewHalfAng, viewHalfAng, out charRaycastRes);

        //return charRaycastRes.isCharacterHitted;
    }