static public int ClearCorners(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.AI.NavMeshPath self = (UnityEngine.AI.NavMeshPath)checkSelf(l);
         self.ClearCorners();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.AI.NavMeshPath o;
         o = new UnityEngine.AI.NavMeshPath();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
示例#3
0
    private void AssignFollowPosition()
    {
        var     playerVehicle = PlayerController.Current.GetVehicle();
        Vector3 destination;

        if (playerVehicle != null)
        {
            destination = playerVehicle.transform.position;
        }
        else
        {
            var randomSpherePoint = Random.insideUnitSphere;
            destination = vehicle.transform.position + vehicle.transform.forward * 10f + 10f * new Vector3(randomSpherePoint.x, 0f, randomSpherePoint.z);
        }
        var navPath = new UnityEngine.AI.NavMeshPath();

        if (UnityEngine.AI.NavMesh.CalculatePath(vehicle.transform.position, destination, UnityEngine.AI.NavMesh.AllAreas, navPath))
        {
            path = navPath.corners;
        }
        else
        {
            path = new[] { vehicle.transform.position };
        }
        curPathIndex = 0;
    }
示例#4
0
    float CalculatePathLength(Vector3 targetPosition) //soundpath
    {
        UnityEngine.AI.NavMeshPath path = new UnityEngine.AI.NavMeshPath();

        if (nav.enabled)
        {
            nav.CalculatePath(targetPosition, path);
        }

        Vector3[] allWayPoints = new Vector3[path.corners.Length + 2];

        allWayPoints[0] = transform.position;
        allWayPoints[allWayPoints.Length - 1] = targetPosition;

        for (int i = 0; i < path.corners.Length; i++)
        {
            allWayPoints[i + 1] = path.corners[i];
        }

        float pathLength = 0f;

        for (int i = 0; i < allWayPoints.Length - 1; i++)
        {
            pathLength += Vector3.Distance(allWayPoints[i], allWayPoints[i + 1]);
        }

        return(pathLength);
    }
 static public int GetCornersNonAlloc(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.AI.NavMeshPath self = (UnityEngine.AI.NavMeshPath)checkSelf(l);
         UnityEngine.Vector3[]      a1;
         checkArray(l, 2, out a1);
         var ret = self.GetCornersNonAlloc(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
示例#6
0
    // Use this for initialization
    void Start()
    {
        move = GetComponent <Move>();
        seek = GetComponent <SteeringSeek>();

        path = new UnityEngine.AI.NavMeshPath();
    }
示例#7
0
    private void LookAhead()
    {
        if (Physics.Raycast(_transform.position, _actualTarget - _transform.position, 20, 1 << 6)) // layer 6 for navmeshobstacles
        {
            NavMeshPath path             = new UnityEngine.AI.NavMeshPath();
            GameObject  instantiatedLine = null;
            NavMesh.CalculatePath(_transform.position, _destination, 1, path);
            SetPath(path.corners);

            if (!SpawnController.SpawnControllerInstance.alreadyUsedPaths.ContainsValue(path))
            {
                instantiatedLine = (GameObject)Instantiate(lineObject);
                instantiatedLine.GetComponent <DrawPath>().DrawPathOnFloor(path.corners);
                SpawnController.SpawnControllerInstance.alreadyUsedPaths.Add(SpawnController.SpawnControllerInstance.pathID, path);
                SpawnController.SpawnControllerInstance.instantiatedLineList.Add(SpawnController.SpawnControllerInstance.pathID, instantiatedLine);
                SpawnController.SpawnControllerInstance.pathID++;
            }
            else
            {
                foreach (var pair in SpawnController.SpawnControllerInstance.alreadyUsedPaths)
                {
                    if (pair.Value == path)
                    {
                        SpawnController.SpawnControllerInstance.instantiatedLineList[pair.Key].GetComponent <DrawPath>().ChangeWidthOfLine();
                    }
                }
            }
        }
    }
示例#8
0
 public WorkerQuad(Worker worker, UnityEngine.AI.NavMeshAgent navAgent, float distance, UnityEngine.AI.NavMeshPath path)
 {
     this.worker   = worker;
     this.navAgent = navAgent;
     this.distance = distance;
     this.path     = path;
 }
示例#9
0
    float CalculatePathLength(Vector3 targetPosition)
    {
        NavMeshPath path = new UnityEngine.AI.NavMeshPath();

        NavMesh.CalculatePath(transform.position, targetPosition, NavMesh.AllAreas, path);
        //nav.CalculatePath(targetPosition, path);
        Vector3[] allWayPoints = new Vector3[path.corners.Length + 2];

        allWayPoints[0] = transform.position;
        allWayPoints[allWayPoints.Length - 1] = targetPosition;

        for (int i = 0; i < path.corners.Length; i++)
        {
            allWayPoints[i + 1] = path.corners[i];
        }

        float pathLength = 0f;

        for (int i = 0; i < allWayPoints.Length - 1; i++)
        {
            pathLength += Vector3.Distance(allWayPoints[i], allWayPoints[i + 1]);
        }

        return(pathLength);
    }
示例#10
0
    public override Status Update()
    {
        timer += Time.deltaTime;

        if (timer >= wanderTime)
        {
            Vector3 wanderPos = RandomNavSphere(owner.root.transform.position, wanderRadius);
            agent.SetDestination(wanderPos);
            timer = 0;
            NavMeshPath path = new UnityEngine.AI.NavMeshPath();

            bool success = agent.CalculatePath(wanderPos, path);
            if (success)
            {
                agent.SetPath(path);
                return(Status.Success);
            }
            else
            {
                Debug.LogError("No path found.");
                return(Status.Failure);
            }
        }

        return(Status.Success);
    }
        public bool IsHearable(IListener listener, IAudioSource source, AudioSourceInfo info)
        {
            if (info.volume >= listener.config.minHearingVolume)
            {
                var  path      = new UnityEngine.AI.NavMeshPath();
                bool foundPath = UnityEngine.AI.NavMesh.CalculatePath(source.transform.position, listener.transform.position, UnityEngine.AI.NavMesh.AllAreas, path);
                if (foundPath && path.status == UnityEngine.AI.NavMeshPathStatus.PathComplete)
                {
                    var corners = path.corners;

                    float pathLength = 0f;
                    for (int i = 0; i < corners.Length - 1; i++)
                    {
                        pathLength += Vector3.Distance(corners[i], corners[i + 1]);
                        if (_config.debug)
                        {
                            Debug.DrawLine(corners[i], corners[i + 1], Color.red, 0.2f);
                        }
                    }

                    //Debug.Log("Path length is " + pathLength);
                    return(pathLength < Vector3.Distance(source.transform.position, listener.transform.position) * PathMaxLengthMultiplier);
                }
            }

            return(false);
        }
示例#12
0
    // Use this for initialization
    void Start()
    {
        m_animator  = GetComponent <Animator>();
        m_character = GetComponent <CharacterController>();

        m_navPath = new UnityEngine.AI.NavMeshPath();
    }
    //calculates the path distance between enemy and target
    float CalculatePathLength(Vector3 targetPosition)
    {
        //creates a new nav mesh path
        UnityEngine.AI.NavMeshPath path = new UnityEngine.AI.NavMeshPath();

        //makes sure the navigation is there, and get path from agent
        if (Agent.enabled)
        {
            Agent.CalculatePath(targetPosition, path);
        }

        Vector3[] addedPatrolPoints = new Vector3[path.corners.Length + 2];

        //set the first point to the enemy pos, and last point to target pos
        addedPatrolPoints[0] = transform.position;
        addedPatrolPoints[addedPatrolPoints.Length - 1] = targetPosition;


        //the loops sets all the inbetween values of the waypoints. So the first value will be enemy pos, second
        //value will be first patrol point or corner,
        for (int i = 0; i < path.corners.Length; i++)
        {
            addedPatrolPoints[i + 1] = path.corners[1];
        }
        //tracks length
        float pathLength = 0f;

        //add calues of the lengths between patrols points
        for (int i = 0; i < addedPatrolPoints.Length - 1; i++)
        {
            pathLength += Vector3.Distance(addedPatrolPoints[i], addedPatrolPoints[i + 1]);
        }

        return(pathLength);
    }
示例#14
0
    //根据导航图初始化路径
    public void InitByNavMeshPath(Vector3 pos, Vector3 targetPos)
    {
        //重置
        waypoints = null;
        index     = -1;
        //计算路径
        UnityEngine.AI.NavMeshPath navPath = new UnityEngine.AI.NavMeshPath();
        bool hasFoundPath = UnityEngine.AI.NavMesh.CalculatePath(pos, targetPos, UnityEngine.AI.NavMesh.AllAreas, navPath);

        if (!hasFoundPath)
        {
            return;
        }
        //生成路径
        int length = navPath.corners.Length;

        waypoints = new Vector3[length];
        for (int i = 0; i < length; i++)
        {
            waypoints[i] = navPath.corners[i];
        }

        index    = 0;
        waypoint = waypoints[index];
        isFinish = false;
    }
示例#15
0
    private void AssignChasePosition()
    {
        Vehicle targetVehicle = null;

        if (target != null)
        {
            targetVehicle = target.GetComponent <Vehicle>();
        }
        if (targetVehicle != null)
        {
            var targetPosition = targetVehicle.transform.position;
            if ((targetPosition - lastTargetPosition).sqrMagnitude > 1f)
            {
                var toTarget    = targetPosition - vehicle.transform.position;
                var destination = targetPosition - (vehicle.GetPrimaryWeapon().SplashRadius() + 1f) * toTarget.normalized;

                var navPath = new UnityEngine.AI.NavMeshPath();
                if (UnityEngine.AI.NavMesh.CalculatePath(vehicle.transform.position, destination, UnityEngine.AI.NavMesh.AllAreas, navPath))
                {
                    path         = navPath.corners;
                    curPathIndex = 0;
                }
                else
                {
                    path         = new[] { vehicle.transform.position };
                    curPathIndex = 0;
                }
            }
            lastTargetPosition = targetPosition;
        }
    }
示例#16
0
    public static List <Vector3> GetMapNav(Vector3 srcPos, Vector3 tPos)
    {
        UnityEngine.AI.NavMeshPath path = new UnityEngine.AI.NavMeshPath();
        if (NavMesh.CalculatePath(srcPos, tPos, NavMesh.AllAreas, path))
        {
        }
        else
        {
            NavMeshHit hit;
            if (UnityEngine.AI.NavMesh.SamplePosition(tPos, out hit, 100.0f, UnityEngine.AI.NavMesh.AllAreas))
            {
                NavMesh.CalculatePath(srcPos, hit.position, NavMesh.AllAreas, path);
            }
        }

        if (path.status == NavMeshPathStatus.PathComplete || path.status == NavMeshPathStatus.PathPartial)
        {
            if (path.corners.Length > 1)
            {
                List <Vector3> pathList = new List <Vector3>();
                pathList.AddRange(path.corners);
                pathList.RemoveAt(0);
                return(pathList);
            }
        }
        return(null);
    }
示例#17
0
    private void AssignWanderPosition()
    {
        var     nearestTarget = Targeting.FindNearest(Targeting.GetOpposingTeam(Team), vehicle.transform.position, float.PositiveInfinity);
        Vector3 wanderTo;
        var     randomSpherePoint = Random.insideUnitSphere;

        if (nearestTarget != null)
        {
            wanderTo = (vehicle.transform.position - nearestTarget.transform.position) + 30f * new Vector3(randomSpherePoint.x, 0f, randomSpherePoint.z);
        }
        else
        {
            wanderTo = vehicle.transform.position + vehicle.transform.forward * 10f + 10f * new Vector3(randomSpherePoint.x, 0f, randomSpherePoint.z);
        }

        var navPath = new UnityEngine.AI.NavMeshPath();

        if (UnityEngine.AI.NavMesh.CalculatePath(vehicle.transform.position, wanderTo, UnityEngine.AI.NavMesh.AllAreas, navPath))
        {
            path = navPath.corners;
        }
        else
        {
            path = new[] { vehicle.transform.position };
        }
        curPathIndex = 0;
    }
示例#18
0
 public ActorPathFinding(Actor owner)
 {
     mOwner             = owner;
     mGameObject        = mOwner.Obj;
     this.mNavMeshAgent = mGameObject.GET <UnityEngine.AI.NavMeshAgent>();
     this.mNavMeshPath  = new UnityEngine.AI.NavMeshPath();
     if (owner.ActorType == EActorType.MONSTER)
     {
         mOwner.AiConeDetection               = mOwner.mActorPart.AIConeDetection.gameObject.GET <AIConeDetection>();
         mOwner.AiConeDetection.StartAngle    = owner.GetAttr(EAttr.StartAngle);
         mOwner.AiConeDetection.EndAngle      = owner.GetAttr(EAttr.EndAngle);
         mOwner.AiConeDetection.m_fConeLenght = owner.GetAttr(EAttr.ViewLength);
     }
     if (owner.ActorType == EActorType.PLAYER)
     {
         mOwner.AiConeDetection                = mOwner.mActorPart.AIConeDetection.gameObject.GET <AIConeDetection>();
         mOwner.AiConeDetection.StartAngle     = 0;
         mOwner.AiConeDetection.EndAngle       = -90;
         mOwner.AiConeDetection.m_fAngleOfView = 180;
         mOwner.AiConeDetection.m_fConeLenght  = owner.GetAttr(EAttr.ViewLength);
     }
     mNavMeshAgent.enabled               = false;
     mNavMeshAgent.radius                = mOwner.Radius;
     mNavMeshAgent.height                = mOwner.Height;
     mNavMeshAgent.acceleration          = 360;
     mNavMeshAgent.angularSpeed          = 360;
     mNavMeshAgent.obstacleAvoidanceType = UnityEngine.AI.ObstacleAvoidanceType.HighQualityObstacleAvoidance;
 }
示例#19
0
 protected void SetDestination()
 {
     //do this instead of setting agent.destination to force immediate path calculation
     UnityEngine.AI.NavMeshPath path = new UnityEngine.AI.NavMeshPath();
     agent.CalculatePath(getRandomPositionOnNavMesh(), path);
     agent.path = path;
 }
示例#20
0
//	//leash
//	public GameObject homePrefab;
//	private GameObject homeInstance;

    // Use this for initialization
    void Start()
    {
        audio            = GetComponent <AudioSource> ();
        pos              = transform.position;
        pos2             = pos;
        home             = pos;
        tr               = transform;
        faceDirection    = 0;
        newfaceDirection = 0;
        stop             = false;
        dead             = false;
        attacking        = false;
        particles        = true;

        chaseDist   = 10;
        homeRadious = 10;

        direction = 1;

        //navmesh
        navPath = new UnityEngine.AI.NavMeshPath();
        elapsed = 0.0f;

        //collider that occupy 2 blocks
        colliderNextBlock = Instantiate(colliderPrefab);
        colliderPrevBlock = Instantiate(colliderPrefab);
    }
示例#21
0
    float CalculatePathLength(Vector3 targetPosition)
    {
        // Create a path and set it based on a target position.
        UnityEngine.AI.NavMeshPath path = new UnityEngine.AI.NavMeshPath();
        if (nav.enabled)
        {
            nav.CalculatePath(targetPosition, path);
        }

        // Create an array of points which is the length of the number of corners in the path + 2.
        Vector3 [] allWayPoints = new Vector3[path.corners.Length + 2];

        // The first point is the enemy's position.
        allWayPoints[0] = transform.position;

        // The last point is the target position.
        allWayPoints[allWayPoints.Length - 1] = targetPosition;

        // The points inbetween are the corners of the path.
        for (int i = 0; i < path.corners.Length; i++)
        {
            allWayPoints[i + 1] = path.corners[i];
        }

        // Create a float to store the path length that is by default 0.
        float pathLength = 0;

        // Increment the path length by an amount equal to the distance between each waypoint and the next.
        for (int i = 0; i < allWayPoints.Length - 1; i++)
        {
            pathLength += Vector3.Distance(allWayPoints[i], allWayPoints[i + 1]);
        }

        return(pathLength);
    }
示例#22
0
 void Start()
 {
     m_CalculatedPath = new UnityEngine.AI.NavMeshPath();
     //enable finding for path/leader formation positions
     StartCoroutine(CheckObjFound());
     //enable making a path if the above coroutine finds an object to goto
     StartCoroutine(NavGetPath());
 }
    public override bool IsDestinationNavigable(Vector3 destination)
    {
//		Debug.Log (destination + ":" + navigation);
        UnityEngine.AI.NavMeshPath path = new UnityEngine.AI.NavMeshPath();
        navigation.CalculatePath(destination, path);

        return(path.status == UnityEngine.AI.NavMeshPathStatus.PathComplete);
    }
示例#24
0
 void Start()
 {
     goal    = go.transform.position;
     diff    = goal - transform.position;
     diffMod = Vector3.Distance(diff, new Vector3(0f, 0f, 0f));
     g       = diff / diffMod;
     path    = new UnityEngine.AI.NavMeshPath();
 }
示例#25
0
    protected void RecalculatePath()
    {
        NavMeshPath path = new UnityEngine.AI.NavMeshPath();

        NavMesh.CalculatePath(this.transform.position, goal.Value, int.MaxValue, path);
        this.currentPath = path;
        this.pathNode    = Mathf.Min(1, path.corners.Length - 1);
    }
示例#26
0
 // Use this for initialization
 void Start()
 {
     navAgent                   = transform.GetComponent <UnityEngine.AI.NavMeshAgent>();
     characterController        = transform.GetComponent <CharacterController>();
     characterController.center = new Vector3(0, 1, 0);
     path = new UnityEngine.AI.NavMeshPath();
     GetComponent <Animator>().applyRootMotion = false;
 }
示例#27
0
 protected override void Start()
 {
     base.Start();
     path                  = new UnityEngine.AI.NavMeshPath();
     currentBiteTimer      = m_EnemyStats.biteCooldown;
     currentDisengageTimer = m_EnemyStats.disengageTimer;
     currentPathTimer      = m_EnemyStats.pathCheckFrequenzy;
 }
示例#28
0
    public static int GetFixNearestPlace(Vector3 playerPosition, int main, Vector3 stardardPosition)
    {
        int result = 0;

        tempPathPointDic.Clear();
        tempPathPointDistance.Clear();

        if (pathPointDistance[main] <= 1.5)
        {
            return(result);
        }

        UnityEngine.AI.NavMeshPath path = new UnityEngine.AI.NavMeshPath();
        if (!UnityEngine.AI.NavMesh.CalculatePath(playerPosition, pathPointDic[main], -1, path))
        {
            return(result);
        }

        if (path.corners.Length < 2)
        {
            return(result);
        }

        for (int i = 0; i < RANDOM_SUBPATHPOINT; i++)
        {
            Vector3 fixPosition = GetRandomVector3InRangeCircle(pathPointDistance[main] - 1.5f);

            tempPathPointDic.Add(100 * main + i, fixPosition + stardardPosition);
            tempPathPointDistance.Add(100 * main + i, 1);
        }

        Vector3 turn = path.corners[path.corners.Length - 2];

        float standardDistance = Vector3.Distance(turn, pathPointDic[main]);
        float resultDistance   = standardDistance;
        float offset           = standardDistance;

        foreach (var tempData in tempPathPointDic)
        {
            float tempSourceDistance = Vector3.Distance(pathPointDic[main], tempData.Value);
            if (tempSourceDistance < 0.6f)
            {
                continue;
            }

            float tempDistance1 = Vector3.Distance(tempData.Value, pathPointDic[main]);
            float tempDistance2 = Vector3.Distance(tempData.Value, turn);

            if (tempDistance1 < standardDistance && tempDistance2 < standardDistance &&
                tempDistance1 > 0 && tempDistance2 > 0)
            {
                return(tempData.Key);
            }
        }

        return(result);
    }
示例#29
0
    IEnumerator GetPath()
    {
        while (true)
        {
            m_PathToTravel = gameObject.GetComponent <NavMeshGet>().PathToUse;
            m_PathCorner   = 1;

            yield return(new WaitForSeconds(m_ReGetPathTmer));
        }
    }
示例#30
0
    void Start()
    {
        characterController = GetComponent <CharacterController>();
        animator            = GetComponent <Animator>();
        path        = new UnityEngine.AI.NavMeshPath();
        gravity     = 20f;//��ֹͬʱ����NavMeshAgent��CharacterControllerʱ����������
        m_navHelper = new MogoNavHelper(transform);

        InvokeRepeating("AdjustPosition", 0, 1);
    }