Exemplo n.º 1
0
    // Follow the path to cover.
    // This code turn/stop immediately on waypoints, differing from Unity default navmesh agent.
    void NavigateToCover()
    {
        // Already at destination?
        if (navPath.Length == 0)
        {
            StartTakeCover();
            return;
        }

        // Change waypoint.
        if (Vector3.Distance(transform.position, navPath [wayPointIndex]) < coverDist)
        {
            wayPointIndex++;

            // Arrived at destination?
            if (wayPointIndex == navPath.Length)
            {
                path.ClearCorners();
                StartTakeCover();
                return;
            }
        }

        // Re-orientate the player to the next waypoint.
        behaviourManager.GetAnim.SetFloat(speedFloat, 2.0f);
        Vector3 direction = navPath [wayPointIndex] - transform.position;

        direction.y = 0;
        Rotating(direction.normalized);
    }
 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
 }
Exemplo n.º 3
0
 public override void OnInterupt()
 {
     if (CurrentActor.m_isDeposited)
     {//托管中,发送action被打断的消息
         IMiniServer.Singleton.SendActionInterupt_C2BS(CurrentActor.ID, (int)GetActionType());
     }
     CurrentActor.MainRigidBody.mass = 1000 * CurrentActor.BaseMass;
     SetVelocity(Vector3.zero, 0f);
     //CurrentActor.MainRigidBody.isKinematic = true;
     m_pathList.ClearCorners();
     if (null != OnInterupted)
     {
         OnInterupted();
     }
     if (null != CurrentActor.mActorBlendAnim)
     {
         CurrentActor.mActorBlendAnim.Reset();
     }
 }
Exemplo n.º 4
0
 static public int ClearCorners(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshPath self = (UnityEngine.AI.NavMeshPath)checkSelf(l);
         self.ClearCorners();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 5
0
 public override void MoveTo(Vector3 v, bool needToAdjustPosY = true)
 {
     speed            = 3f;
     isMovingToTarget = true;
     navAgent.speed   = 0.0f;
     navAgent.SetDestination(v);
     path.ClearCorners();
     navAgent.CalculatePath(v, path);
     cornersIdx               = 1;
     moveDirection            = (path.corners[cornersIdx] - transform.position).normalized;
     currentPathPointDistance = Vector3.Distance(transform.position, path.corners[cornersIdx]);
 }
Exemplo n.º 6
0
    //计算到目标点的距离,若不能到达,则计算的是两点之间的距离
    public static float CalculatePathLength(Vector3 _position, Vector3 targetPosition, UnityEngine.AI.NavMeshAgent _nav, UnityEngine.AI.NavMeshPath _path)
    {
        _path.ClearCorners();
        allWayPoints.Clear();

        UnityEngine.AI.NavMeshPath path = _path;
        if (_nav.enabled)
        {
            if (_path != null)
            {
                _nav.CalculatePath(targetPosition, _path);
                path = _path;
            }
            else
            {
                path = new UnityEngine.AI.NavMeshPath();
                _nav.CalculatePath(targetPosition, path);
            }
        }

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

        allWayPoints.Add(targetPosition);

        float pathLength = 0;

        for (int i = 0; i < allWayPoints.Count - 1; i++)
        {
            pathLength += Vector3.Distance(allWayPoints[i], allWayPoints[i + 1]);
        }
        return(pathLength);
    }
Exemplo n.º 7
0
 public static bool CalculatePath(Vector3 sourcePosition, Vector3 targetPosition, NavMeshQueryFilter filter, NavMeshPath path)
 {
     path.ClearCorners();
     return(NavMesh.CalculatePathFilterInternal(sourcePosition, targetPosition, path, filter.agentTypeID, filter.areaMask, filter.costs));
 }
Exemplo n.º 8
0
 public static bool CalculatePath(Vector3 sourcePosition, Vector3 targetPosition, int areaMask, NavMeshPath path)
 {
     path.ClearCorners();
     return(NavMesh.CalculatePathInternal(sourcePosition, targetPosition, areaMask, path));
 }
Exemplo n.º 9
0
 public bool CalculatePath(Vector3 targetPosition, NavMeshPath path)
 {
     path.ClearCorners();
     return(this.CalculatePathInternal(targetPosition, path));
 }
Exemplo n.º 10
0
    void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3 destPoint = hit.point;
                if (UnityEngine.AI.NavMesh.CalculatePath(transform.position, destPoint, -1, m_navPath))
                {
                    m_moving      = true;
                    m_cornerIndex = -1;
                    Debug.Log("auto pathing begin,dest x:" + destPoint.x + ",z:" + destPoint.z);
                }
            }
        }

        if (m_navPath.corners.Length > 0)
        {
            bool changeCorner = false;
            if (m_cornerIndex < 0)
            {
                m_cornerIndex = 0;
                changeCorner  = true;
            }

            if (0.5f > Vector3.Distance(transform.position, m_navPath.corners[m_cornerIndex]))
            {
                m_cornerIndex++;
                if (m_navPath.corners.Length <= m_cornerIndex)
                {
                    m_moving = false;
                    m_navPath.ClearCorners();
                    Debug.Log("auto pathing end,current pos,x:" + transform.position.x + ",z:" + transform.position.z);
                }
                else
                {
                    changeCorner = true;
                }
            }

            if (changeCorner)
            {
                m_destRotation = xInputManager.GetWorldRotation(
                    m_navPath.corners[m_cornerIndex].x - transform.position.x,
                    m_navPath.corners[m_cornerIndex].z - transform.position.z);

                Debug.Log("next nav corner:" + m_navPath.corners[m_cornerIndex].x + "," + m_navPath.corners[m_cornerIndex].z);
            }
        }

        float h = xInputManager.GetHorizontalValue();
        float v = xInputManager.GetVerticalValue();

        if (h != 0f || v != 0f)
        {
            m_moving       = true;
            m_destRotation = xInputManager.GetWorldRotation(h, v);
        }
        else
        {
            if (m_navPath.corners.Length <= 0)
            {
                m_moving = false;
            }
        }

        if (m_moving)
        {
            m_character.SimpleMove(transform.forward * m_moveSpeed);
            //m_animator.SetFloat("Forward", 1f);
            m_animator.SetBool("Run", true);
        }
        else
        {
            //m_animator.SetFloat("Forward", 0f);
            m_animator.SetBool("Run", false);
        }
        transform.rotation = Quaternion.RotateTowards(transform.rotation, m_destRotation, m_rotateSpeed);

        /*
         * if (Input.touchCount == 1)
         * {
         *  Touch t = Input.GetTouch(0);
         *  if (t.phase == TouchPhase.Began)
         *  {
         *      m_touchStartPos = t.position;
         *  }
         *  else if (t.phase == TouchPhase.Ended)
         *  {
         *      Vector2 deltaPos = t.position - m_touchStartPos;
         *      if (deltaPos.x > 0f)
         *      {
         *          if (deltaPos.y > 0f && deltaPos.y > deltaPos.x)
         *          {
         *              Debug.Log("touch slide to up");
         *          }
         *          else if (deltaPos.y < 0f && Mathf.Abs(deltaPos.y) > deltaPos.x)
         *          {
         *              Debug.Log("touch slide bottom");
         *          }
         *          else
         *          {
         *              Debug.Log("touch slide right");
         *          }
         *      }
         *      else if (deltaPos.x < 0f)
         *      {
         *          if (deltaPos.y > 0f && deltaPos.y > Mathf.Abs(deltaPos.x))
         *          {
         *              Debug.Log("touch slide to up");
         *          }
         *          else if (deltaPos.y < 0f && Mathf.Abs(deltaPos.y) >  Mathf.Abs(deltaPos.x))
         *          {
         *              Debug.Log("touch slide bottom");
         *          }
         *          else
         *          {
         *              Debug.Log("touch slide left");
         *          }
         *      }
         *
         *      m_touchStartPos = Vector2.zero;
         *  }
         * }
         */
    }
 void ClearCorners()
 {
     path.ClearCorners();
 }