//实现通过移动控制点来更新曲线的形状 public void UpdateLine(GameObject anchorPoint, Vector3 offsetPos1, Vector3 offsetPos2) { if (anchorPoint == null) { return; } if (anchorPoint.tag.Equals("AnchorPoint")) { CurvePointControl curvePoint = anchorPoint.GetComponent <CurvePointControl>(); //分别计算2个控制点的偏移量 if (curvePoint) { if (curvePoint.m_controlObject) { curvePoint.m_controlObject.transform.position = anchorPoint.transform.position + offsetPos1; } if (curvePoint.m_controlObject2) { curvePoint.m_controlObject2.transform.position = anchorPoint.transform.position + offsetPos2; } } } //重新绘制曲线 DrawCurve(); }
public void DeletePoint(GameObject anchorPoint) { if (anchorPoint == null) { return; } CurvePointControl curvePoint = anchorPoint.GetComponent <CurvePointControl>(); //是锚点 if (curvePoint && anchorPoint.tag.Equals("AnchorPoint")) { //删去控制点1 if (curvePoint.m_controlObject) { m_allPoints.Remove(curvePoint.m_controlObject.transform); Destroy(curvePoint.m_controlObject); } //删去控制点2 if (curvePoint.m_controlObject2) { m_allPoints.Remove(curvePoint.m_controlObject2.transform); Destroy(curvePoint.m_controlObject2); } if (m_allPoints.IndexOf(curvePoint.transform) == (m_allPoints.Count - 1)) {//先判断删除的是最后一个元素再移除 m_allPoints.Remove(curvePoint.transform); Transform lastPoint = m_allPoints[m_allPoints.Count - 2]; GameObject lastPointCtrObject = lastPoint.GetComponent <CurvePointControl>().m_controlObject2; if (lastPointCtrObject) { m_allPoints.Remove(lastPointCtrObject.transform); Destroy(lastPointCtrObject); lastPoint.GetComponent <CurvePointControl>().m_controlObject2 = null; } } else { m_allPoints.Remove(curvePoint.transform); } Destroy(anchorPoint); if (m_allPoints.Count == 1) { m_lineRenderer.positionCount = 0; } } //重新绘制曲线 DrawCurve(); }