/// <summary> /// Sets a point in the line /// This function is not guaranteed to have an effect /// </summary> /// <param name="pointIndex"></param> /// <param name="point"></param> public void SetPoint(int pointIndex, Vector3 point) { if (pointIndex < 0 || pointIndex >= PointCount) { Debug.LogError("Invalid point index"); return; } SetPointInternal(pointIndex, LineTransform.InverseTransformPoint(point)); }
private Vector3 InverseTransformPoint(Vector3 point) { switch (transformMode) { case LinePointTransformMode.UseTransform: default: return(LineTransform.InverseTransformPoint(point)); case LinePointTransformMode.UseMatrix: return(worldToLocalMatrix.MultiplyPoint3x4(point)); } }
protected override void OnRenderPoint(int index, BoundaryVertex point, Vector3 pos, float handleSize) { EventType eventType = Event.current.type; int arrowId = GUIUtility.GetControlID(FocusType.Passive); Vector3 dir = LineTransform.TransformDirection(point.Normal); RenderNormal(pos, dir, eventType, arrowId); if (eventType == EventType.MouseDown) { if (HandleUtility.nearestControl == arrowId) { selectedNormalIndex = index; SelectPoint(index, notify: false); } } if (selectedNormalIndex != index) { return; } EditorGUI.BeginChangeCheck(); Vector3 destination = Handles.DoPositionHandle(pos + dir, HandleTransform); destination = LineTransform.InverseTransformPoint(destination); if (!EditorGUI.EndChangeCheck()) { return; } Undo.RecordObject(Line, "Move Normal"); EditorUtility.SetDirty(Line); point.Normal = destination - point.Position; float sqrMagnitude = point.Normal.sqrMagnitude; // Don't normalize if less that 1 to avoid glitchy movement if (sqrMagnitude > 1) { point.Normal /= Mathf.Sqrt(sqrMagnitude); } Line.SetPoint(index, point); }