Exemplo n.º 1
0
 /// <summary>
 /// Callback to draw gizmos that are pickable and always drawn.
 /// </summary>
 private void OnDrawGizmos()
 {
     if (points.Length > 0)
     {
         m_controlPoints = new Vector3[points.Length];
         for (int i = 0; i < m_controlPoints.Length; i++)
         {
             if (points[i])
             {
                 m_controlPoints[i] = points[i].transform.position;
             }
         }
         if (isUseBezier && m_controlPoints.Length > 2)
         {
             for (float i = 0; i <= 1; i += 0.1f)
             {
                 m_drawPos = GraphicMath.BezierToPoint(i, m_controlPoints);
                 Gizmos.DrawSphere(m_drawPos, 0.25f);
             }
         }
         else
         {
             if (m_controlPoints.Length >= 2)
             {
                 for (int i = 0; i < m_controlPoints.Length - 1; i++)
                 {
                     Gizmos.DrawLine(m_controlPoints[i], m_controlPoints[i + 1]);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
    private void _UpdatePosition(float dt)
    {
        switch (m_Type)
        {
        case 0:
            m_Destination.x    = m_PathMgr.GetTargetPosition(m_Delta.x).x;
            m_Destination.y    = transform.position.y;
            transform.position = m_Destination;
            break;

        case 1:
            m_Destination      = m_PathMgr.GetTargetPosition(m_DeltaBezier);
            transform.position = m_Destination;
            break;

        case 2:
            Vector3 p = m_Target.transform.position;
            // Debug.Log(GraphicMath.Distance2Point(transform.position, p));
            if (GraphicMath.Distance2Point(transform.position, p) <= 4 && m_RigidBody.IsSleeping())
            {
                m_RigidBody.WakeUp();
                m_RigidBody.AddForce(new Vector3(0f, m_JumpForce, 0f));
            }
            break;
        }
    }
Exemplo n.º 3
0
 private void _UpdateComplete()
 {
     if (!isCompletePath)
     {
         if (m_CurrentPath.isUseBezier)
         {
             if (GraphicMath.BezierToPoint(tempDelta, route) == route[route.Length - 1])
             {
                 isCompletePath = true;
             }
         }
         else
         {
             if (GraphicMath.MoveToPoint(tempDelta, m_CurrentPoint, m_NextPoint, true, false) == m_NextPoint)
             // && m_NextPoint == m_CurrentPath.GetRoute()[m_CurrentPath.GetRoute().Length - 1])
             {
                 isCompletePath = true;
             }
         }
     }
 }
Exemplo n.º 4
0
 public Vector2 GetTargetPosition(float dt)
 {
     tempDelta = dt;
     if (!isMoveComplete)
     {
         // Debug.Log("false");
         if (m_CurrentPath.isUseBezier)
         {
             return(GraphicMath.BezierToPoint(dt, route));
         }
         else
         {
             return(GraphicMath.MoveToPoint(dt, m_CurrentPoint, m_NextPoint, true, false));
         }
     }
     else
     {
         // Debug.Log(dt);
         // Debug.Log("complete");
         return(m_Paths[m_Paths.Length - 1].GetRoute()[m_Paths[m_Paths.Length - 1].GetRoute().Length - 1]);
     }
 }