protected virtual void DrawSeparateTangentEditor(int index, HermiteAnchor anchor) { if (index > 0) { Handles.color = Color.cyan; var inTangent = anchor.point - anchor.inTangent; Handles.DrawLine(anchor.point, inTangent); DrawFreeMoveHandle(inTangent, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position => { anchor.inTangent = anchor.point - position; Target.SetAnchor(index, anchor); Target.Rebuild(); }); } if (index < Target.AnchorsCount - 1) { Handles.color = Color.green; var outTangent = anchor.point + anchor.outTangent; Handles.DrawLine(anchor.point, outTangent); DrawFreeMoveHandle(outTangent, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position => { anchor.outTangent = position - anchor.point; Target.SetAnchor(index, anchor); Target.Rebuild(); }); } }
protected virtual void DrawInsertEditor(int index, HermiteAnchor anchor) { Handles.color = Color.green; DrawAdaptiveButton(anchor.point, Quaternion.identity, NodeSize, NodeSize, SphereCap, () => { var offset = Vector3.zero; if (index > 0) { offset = (anchor.point - Target.GetAnchor(index - 1).point).normalized * GetHandleSize(anchor.point); } else { //Considering that it may be used on UI, so use Vector2.one. offset = Target.transform.TransformVector(Vector2.one).normalized *GetHandleSize(anchor.point); } select = index + 1; if (adsorbent > 0) { adsorbent++; } Target.InsertAnchor(index + 1, new HermiteAnchor(anchor.point + offset)); Target.Rebuild(); }); }
protected virtual void DrawRemoveEditor(int index, HermiteAnchor anchor) { Handles.color = Color.red; DrawAdaptiveButton(anchor.point, Quaternion.identity, NodeSize, NodeSize, SphereCap, () => { if (select >= index) { select--; } if (adsorbent > 0) { adsorbent--; } Target.RemoveAnchor(index); Target.Rebuild(); }); }
protected virtual void DrawSelectEditor(int index, HermiteAnchor anchor) { var nodeSize = NodeSize; if (index == 0 || index == Target.AnchorsCount - 1) { if (Target.IsClose) { if (index != adsorbent) { return; } nodeSize = NodeSize * 1.25f; } } Handles.color = Color.blue; DrawAdaptiveButton(anchor.point, Target.transform.rotation, nodeSize, nodeSize, SphereCap, () => select = index); }
protected virtual void DrawMoveEditor(int index, HermiteAnchor anchor) { Handles.color = Color.white; if (index == 0 || index == Target.AnchorsCount - 1) { var nodeSize = NodeSize; if (Target.IsClose) { if (index != adsorbent && index > 0) { return; } nodeSize = NodeSize * 1.25f; } DrawFreeMoveHandle(anchor.point, Quaternion.identity, nodeSize, MoveSnap, SphereCap, position => { var adjacent = Target.GetAnchor(Target.AnchorsCount - 1 - index); if (Vector3.Distance(position, adjacent.point) <= NodeSize * GetHandleSize(position)) { adsorbent = index; position = adjacent.point; } else { adsorbent = -1; } anchor.point = position; Target.SetAnchor(index, anchor); Target.Rebuild(); }); } else { DrawFreeMoveHandle(anchor.point, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position => { anchor.point = position; Target.SetAnchor(index, anchor); Target.Rebuild(); }); } }
protected virtual void DrawUnifyTangentEditor(int index, HermiteAnchor anchor) { Handles.color = Color.cyan; if (index > 0) { var inTangent = anchor.point - anchor.inTangent; Handles.DrawLine(anchor.point, inTangent); DrawFreeMoveHandle(inTangent, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position => { anchor.inTangent = anchor.outTangent = anchor.point - position; Target.SetAnchor(index, anchor); if (Target.IsClose && index == Target.AnchorsCount - 1) { var firstAnchor = Target.GetAnchor(0); firstAnchor.outTangent = anchor.inTangent; Target.SetAnchor(0, firstAnchor); } Target.Rebuild(); }); } if (index < Target.AnchorsCount - 1) { var outTangent = anchor.point + anchor.outTangent; Handles.DrawLine(anchor.point, outTangent); DrawFreeMoveHandle(outTangent, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position => { anchor.inTangent = anchor.outTangent = position - anchor.point; Target.SetAnchor(index, anchor); if (Target.IsClose && index == 0) { var lastAnchor = Target.GetAnchor(Target.AnchorsCount - 1); lastAnchor.inTangent = anchor.outTangent; Target.SetAnchor(Target.AnchorsCount - 1, lastAnchor); } Target.Rebuild(); }); } }