private void OnEnable()
 {
     pathPoint       = target as EZPathPoint;
     m_BrokenTangent = serializedObject.FindProperty("m_BrokenTangent");
     m_StartTangent  = serializedObject.FindProperty("m_StartTangent");
     m_EndTangent    = serializedObject.FindProperty("m_EndTangent");
 }
        public static void DrawTangentHandles(EZPathPoint pathPoint)
        {
            Handles.matrix = pathPoint.transform.localToWorldMatrix;

            Handles.color = Color.green;
            Vector3 startTangent = Handles.FreeMoveHandle(pathPoint.startTangent, Quaternion.identity, HandleUtility.GetHandleSize(pathPoint.startTangent) * 0.15f, Vector3.zero, Handles.SphereHandleCap);

            if (startTangent != pathPoint.startTangent)
            {
                Undo.RegisterCompleteObjectUndo(pathPoint, "Change StartTangent");
                pathPoint.startTangent = startTangent;
                if (!pathPoint.brokenTangent)
                {
                    pathPoint.endTangent = -startTangent;
                }
                EditorUtility.SetDirty(pathPoint);
            }
            Handles.DrawDottedLine(Vector3.zero, pathPoint.startTangent, 1);

            Handles.color = Color.red;
            Vector3 endTangent = Handles.FreeMoveHandle(pathPoint.endTangent, Quaternion.identity, HandleUtility.GetHandleSize(pathPoint.endTangent) * 0.15f, Vector3.zero, Handles.SphereHandleCap);

            if (endTangent != pathPoint.endTangent)
            {
                Undo.RegisterCompleteObjectUndo(pathPoint, "Change EndTangent");
                pathPoint.endTangent = endTangent;
                if (!pathPoint.brokenTangent)
                {
                    pathPoint.startTangent = -endTangent;
                }
                EditorUtility.SetDirty(pathPoint);
            }
            Handles.DrawDottedLine(Vector3.zero, pathPoint.endTangent, 1);
        }
Exemple #3
0
 private void RebuildPath()
 {
     m_PathPoints.Clear();
     for (int i = 0; i < transform.childCount; i++)
     {
         Transform child = transform.GetChild(i);
         child.name = string.Format("PathPoint-{0:D2}", i);
         EZPathPoint point = child.GetComponent <EZPathPoint>();
         if (point == null)
         {
             point = child.gameObject.AddComponent <EZPathPoint>();
         }
         m_PathPoints.Add(point);
     }
 }
Exemple #4
0
        public bool GetPoint(ref Vector3 position, ref Quaternion rotation, ref Vector3 scale, int section, float progress, bool loop)
        {
            if (pathPoints.Count < 2)
            {
                Debug.LogError("Invalid Path, a path should be consist of at least two points");
                return(false);
            }
            if (section < 0)
            {
                Debug.LogException(new ArgumentOutOfRangeException("section"));
                return(false);
            }
            int totalSection = closedPath ? pathPoints.Count : (pathPoints.Count - 1);

            if (section >= totalSection && !loop)
            {
                EZPathPoint pathPoint = pathPoints[pathPoints.Count - 1];
                position = pathPoint.position;
                rotation = pathPoint.transform.rotation;
                scale    = pathPoint.transform.localScale;
                return(true);
            }
            else
            {
                EZPathPoint pathPoint1 = pathPoints[section % (totalSection)];
                EZPathPoint pathPoint2 = pathPoints[(section + 1) % (pathPoints.Count)];
                if (pathMode == PathMode.Bezier)
                {
                    position = CalcBezierPoint(pathPoint1, pathPoint2, progress);
                }
                else
                {
                    position = Vector3.Lerp(pathPoint1.position, pathPoint2.position, progress);
                }
                rotation = Quaternion.Lerp(pathPoint1.transform.rotation, pathPoint2.transform.rotation, progress);
                scale    = Vector3.Lerp(pathPoint1.transform.localScale, pathPoint2.transform.localScale, progress);
                return(true);
            }
        }
Exemple #5
0
 public static Vector3 CalcBezierPoint(EZPathPoint p1, EZPathPoint p2, float progress)
 {
     return(CalcBezierPoint(p1.position, p1.startTangentPosition, p2.endTangentPosition, p2.position, progress));
 }
Exemple #6
0
 private void DrawBezierGizmos(EZPathPoint p1, EZPathPoint p2)
 {
     UnityEditor.Handles.DrawBezier(p1.position, p2.position, p1.startTangentPosition, p2.endTangentPosition, Gizmos.color, null, 1f);
 }
Exemple #7
0
 private void DrawLinearGizmos(EZPathPoint p1, EZPathPoint p2)
 {
     UnityEditor.Handles.DrawLine(p1.position, p2.position);
 }