/// <summary> /// fit primitive between one point in the bottom and one point in the top /// </summary> /// <param name="bottom">bottom point</param> /// <param name="top">top point</param> /// <param name="offset">distance offset from point</param> /// <param name="option">offset option</param> public void FitBetweenPoints(Vector3 bottom, Vector3 top, float offset, FitOffsetOption option) { var dir = (top - bottom).normalized; switch (option) { case FitOffsetOption.Top: top -= dir * offset; break; case FitOffsetOption.Bottom: bottom += dir * offset; break; case FitOffsetOption.Both: top -= dir * offset; bottom += dir * offset; break; } var length = (top - bottom).magnitude; SetHeight(length); switch (pivotPosition) { case PivotPosition.Botttom: transform.position = bottom; break; case PivotPosition.Center: transform.position = bottom + (top - bottom) * 0.5f; break; case PivotPosition.Top: transform.position = top; break; } GenerateGeometry(); transform.rotation = Quaternion.FromToRotation(Vector3.up, dir); }
/// <summary> /// fit primitive between one point in the bottom and one point in the top /// </summary> /// <param name="bottom">bottom point</param> /// <param name="top">top point</param> /// <param name="offset">distance offset from point</param> /// <param name="option">offset option</param> public void FitBetweenPoints(Vector3 bottom, Vector3 top, float offset, FitOffsetOption option) { var dir = (top - bottom).normalized; switch (option) { case FitOffsetOption.Top: top -= dir*offset; break; case FitOffsetOption.Bottom: bottom += dir*offset; break; case FitOffsetOption.Both: top -= dir*offset; bottom += dir*offset; break; } var length = (top - bottom).magnitude; SetHeight(length); switch (pivotPosition) { case PivotPosition.Botttom: transform.position = bottom; break; case PivotPosition.Center: transform.position = bottom + (top - bottom)*0.5f; break; case PivotPosition.Top: transform.position = top; break; } GenerateGeometry(); transform.rotation = Quaternion.FromToRotation(Vector3.up, dir); }