public static void GizmosDrawLineInterpolated(LineBase source, LineRenderer renderer) { Vector3 firstPos = source.GetPoint(0f); Vector3 lastPos = firstPos; Color gColor = renderer.GetColor(0); gColor.a = 0.5f; Gizmos.color = gColor; Gizmos.DrawSphere(firstPos, renderer.GetWidth(0) / 2); for (int i = 1; i < renderer.NumLineSteps; i++) { float normalizedLength = (1f / renderer.NumLineSteps) * i; Vector3 currentPos = source.GetPoint(normalizedLength); gColor = renderer.GetColor(normalizedLength); gColor.a = 0.5f; Gizmos.color = gColor; Gizmos.DrawLine(lastPos, currentPos); Gizmos.DrawSphere(currentPos, renderer.GetWidth(normalizedLength) / 2); lastPos = currentPos; } if (source.Loops) { Gizmos.DrawLine(lastPos, firstPos); } }
public void UpdateCollection() { if (source == null) { source = gameObject.GetComponent <LineBase>(); } if (source == null) { return; } if (transformHelper == null) { transformHelper = transform.Find("TransformHelper"); if (transformHelper == null) { transformHelper = new GameObject("TransformHelper").transform; transformHelper.parent = transform; } } switch (StepMode) { case LineUtils.StepModeEnum.FromSource: break; case LineUtils.StepModeEnum.Interpolated: for (int i = 0; i < Objects.Count; i++) { if (Objects[i] == null) { continue; } float normalizedDistance = Mathf.Repeat(((float)i / Objects.Count) + DistributionOffset, 1f); Objects[i].position = source.GetPoint(normalizedDistance); Objects[i].rotation = source.GetRotation(normalizedDistance, RotationTypeOverride); transformHelper.localScale = Vector3.one; transformHelper.position = Objects[i].position; transformHelper.localRotation = Quaternion.identity; Transform tempParent = Objects[i].parent; Objects[i].parent = transformHelper; transformHelper.localEulerAngles = RotationOffset; Objects[i].parent = tempParent; Objects[i].transform.localScale = Vector3.one * ObjectScale.Evaluate(Mathf.Repeat(ScaleOffset + normalizedDistance, 1f)) * ScaleMultiplier; /*if (FlipRotation) { * Objects[i].forward = -Objects[i].forward; * }*/ } break; } }
protected void DrawManualUpVectorHandles(LineBase line) { if (line.ManualUpVectors == null || line.ManualUpVectors.Length < 2) { line.ManualUpVectors = new Vector3[2]; } for (int i = 0; i < line.ManualUpVectors.Length; i++) { float normalizedLength = (1f / (line.ManualUpVectors.Length - 1)) * i; Vector3 currentPoint = line.GetPoint(normalizedLength); Vector3 currentUpVector = line.ManualUpVectors[i]; float maxHandleLength = (HandleUtility.GetHandleSize(currentPoint) * rotationHandleLength); Vector3 upVectorPoint = currentPoint + (currentUpVector * (maxHandleLength * currentUpVector.magnitude)); Handles.color = Color.Lerp(Color.black, Color.cyan, currentUpVector.magnitude); Handles.DrawDottedLine(currentPoint, upVectorPoint, rotationHandleSize); Handles.Label(upVectorPoint, currentUpVector.magnitude.ToString("0.00")); Vector3 newUpVectorPoint = Handles.FreeMoveHandle( upVectorPoint, Quaternion.identity, HandleUtility.GetHandleSize(currentPoint) * rotationHandleSize, Vector3.zero, Handles.RectangleHandleCap); if (newUpVectorPoint != upVectorPoint) { if (!recordingUndo) { recordingUndo = true; Undo.RegisterCompleteObjectUndo(line, "Edit Manual Up Vector"); } Vector3 newUpVector = (newUpVectorPoint - currentPoint) / maxHandleLength; if (newUpVector.magnitude > 1) { newUpVector.Normalize(); } line.ManualUpVectors[i] = newUpVector; } } }