private void ChangeSubHandlePositon(FlightPathCurveSODrawer curveDrawer, FlightPathCurveNode node) { EditorGUI.BeginChangeCheck(); Handles.DrawLine(node.NodePosiion + curveDrawer.transform.position, node.GetPrevHandlePos() + curveDrawer.transform.position); Vector3 newPrevHandlePositionReleative = Handles.FreeMoveHandle( node.GetPrevHandlePos() + curveDrawer.transform.position, Quaternion.identity, HandleUtility.GetHandleSize(node.NodePosiion + curveDrawer.transform.position) / 10f, Vector3.zero, Handles.CircleHandleCap); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(curveDrawer.CurveSO, "Change Sub Handle Position"); node.SubHandlePositionReleative = newPrevHandlePositionReleative - node.NodePosiion - curveDrawer.transform.position; if (node.HandlesMode == FlightCurveNodeHandlesMode.Similiar) { node.MainHandlePositionReleative = -node.SubHandlePositionReleative; } else if (node.HandlesMode == FlightCurveNodeHandlesMode.CoDirected) { node.MainHandlePositionReleative = -node.SubHandlePositionReleative.normalized * node.MainHandlePositionReleative.magnitude; } EditorUtility.SetDirty(curveDrawer); } }
private void OnSceneGUI() { FlightPathCurveSODrawer curveDrawer = target as FlightPathCurveSODrawer; if (curveDrawer.CurveSO == null) { return; } Handles.color = Color.gray; for (int i = 0; i < curveDrawer.CurveSO.CurveNodes.Count; i++) { FlightPathCurveNode node = curveDrawer.CurveSO.CurveNodes[i]; ChangeNodePosition(curveDrawer, node); if (node.HandlesMode != FlightCurveNodeHandlesMode.None) { ChangeMainHandlePosition(curveDrawer, node); ChangeSubHandlePositon(curveDrawer, node); } Handles.Label(node.NodePosiion + curveDrawer.transform.position, i.ToString()); } }
public static Vector3 NodeLerpPostion(FlightPathCurveNode startNode, FlightPathCurveNode endNode, float t) { return(CubicLerp( startNode.NodePosiion, startNode.GetMainHandlePos(), endNode.GetPrevHandlePos(), endNode.NodePosiion, t)); }
public static Quaternion NodeLerpRotation(FlightPathCurveNode startNode, FlightPathCurveNode endNode, Vector3 pointDirection, float t) { return((startNode.TransitionMode == FlightCurvePointerNodeTransitionMode.Aligned) ? Quaternion.LookRotation( Vector3.forward, Quaternion.Euler(Vector3.forward * 90f) * pointDirection) : Quaternion.Lerp( startNode.GetMainRotation(), endNode.GetMainRotation(), t)); }
public static float PathLength(FlightPathCurveNode startNode, FlightPathCurveNode endNode, int iterations = 10) { float length = 0f; Vector3 prevPoint = startNode.NodePosiion; Vector3 currPoint; for (int i = 1; i <= iterations; i++) { currPoint = NodeLerpPostion(startNode, endNode, (float)i / (float)iterations); length += Vector3.Distance(prevPoint, currPoint); prevPoint = currPoint; } return(length); }
private void ChangeNodePosition(FlightPathCurveSODrawer curveDrawer, FlightPathCurveNode node) { EditorGUI.BeginChangeCheck(); Vector3 newNodePosition = Handles.FreeMoveHandle( node.NodePosiion + curveDrawer.transform.position, Quaternion.identity, HandleUtility.GetHandleSize(node.NodePosiion + curveDrawer.transform.position) / 7f, Vector3.zero, Handles.RectangleHandleCap); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(curveDrawer.CurveSO, "Change Node Position"); node.NodePosiion = newNodePosition - curveDrawer.transform.position; EditorUtility.SetDirty(curveDrawer); } }