public void RecalculateWayPoint(int index) { float closestPositionOnSpline = _spline.FindClosestPoint(GetPositionFromPoint(index), 0, -1, 10); float currentUnits = _spline.FromPathNativeUnits(closestPositionOnSpline, _positionUnits); GetWayPoint(index).PathPosition = currentUnits; }
private void UpdateDraggingPositionOnSpline() { Vector3 positionOnSpline = _target.PositionWithoutOffsetFromSpline(_target.PathPosition); Quaternion rotationOnSpline = _target.RotationWithoutOffsetFromSpline(_target.PathPosition); EditorGUI.BeginChangeCheck(); Vector3 newPosition = Handles.PositionHandle(Tools.pivotMode != PivotMode.Center ? positionOnSpline : _target.transform.position, Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : rotationOnSpline); //newPosition = _target.SplineBase.AttemptToApplyGrid(newPosition, 0.1f); if (EditorGUI.EndChangeCheck()) { SerializedProperty offset = this.GetPropertie("_offsetFromTarget"); SerializedProperty splineProperty = this.GetPropertie("_spline"); SplineBase spline = splineProperty.GetValue <SplineBase>(); float closestPositionOnSpline = spline.FindClosestPoint(newPosition, 0, -1, 10); float currentUnits = spline.FromPathNativeUnits(closestPositionOnSpline, _target.PositionUnits); currentUnits = _target.SplineBase.AttemptToApplyGrid(currentUnits, 0.01f); offset.floatValue = currentUnits - _target.PathPositionTarget; UpdatePositionFromEditor(offset); this.ApplyModification(); } }
private void ChangePosition(Vector3 newPosition) { SerializedProperty pathPosition = this.GetPropertie("_pathPosition"); SerializedProperty splineProperty = this.GetPropertie("_spline"); SplineBase spline = splineProperty.GetValue <SplineBase>(); float closestPositionOnSpline = spline.FindClosestPoint(newPosition, 0, -1, 10); float currentUnits = spline.FromPathNativeUnits(closestPositionOnSpline, _splineController.PositionUnits); currentUnits = _splineController.SplineBase.AttemptToApplyGrid(currentUnits, 0.01f); pathPosition.floatValue = _previousDraggingPosition = currentUnits; UpdatePositionFromEditor(); this.GetPropertie("_lastPosition").vector3Value = _splineController.transform.position; this.ApplyModification(); }