public override void OnInspectorGUI() { curve = target as TestBezierLineForStu; //绘制选中的point if (m_nSelectedIndex != -1) { DrawSelectedIndexPoint(); } GameObject source = EditorGUILayout.ObjectField(curve.m_oCube, typeof(GameObject), true) as GameObject; if (source != curve.m_oCube) { Undo.RecordObject(curve, "Add Cube"); curve.m_oCube = source; EditorUtility.SetDirty(curve); } if (GUILayout.Button("Add Curve")) { Undo.RecordObject(curve, "Add Curve"); curve.AddCurve(); EditorUtility.SetDirty(curve); } }
//根据进度获取点 public Vector3 GetPoint(float t) { int i; if (t >= 1.0f) { t = 1.0f; i = PointNum - 4; } else { t *= CurveNum; i = (int)t; t = t - i; i *= 3; } return(transform.TransformPoint(TestBezierLineForStu.GetPoint(m_vPoints[i], m_vPoints[i + 1], m_vPoints[i + 2], m_vPoints[i + 3], t))); }
public void OnSceneGUI() { //获取曲线实例对象 curve = target as TestBezierLineForStu; curveTransform = curve.transform; Vector3 p0 = ShowPoint(0); for (int i = 1; i < curve.PointNum; i += 3) { Vector3 p1 = ShowPoint(i); Vector3 p2 = ShowPoint(i + 1); Vector3 p3 = ShowPoint(i + 2); Handles.color = Color.gray; Handles.DrawLine(p0, p1); Handles.DrawLine(p2, p3); Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f); p0 = p3; } //显示所有点的切线方向 //ShowDirection(); }