Doc2
Doc2
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
[SerializeField]
Vector3[]
points;
[SerializeField]
BezierControlPointMode[]
modes;
[SerializeField]
bool
loop;
public int
frequency;
if (loop) {
points [points.Length - 1] = points [0];
modes [modes.Length - 1] = modes [0];
EnforceMode (0);
}
}
if (loop) {
points [points.Length - 1] = points [0];
modes [modes.Length - 1] = modes [0];
EnforceMode (0);
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(BezierSpline))]
public class BezierSplineInspector : Editor
{
void DrawSelectedPointInspector ()
{
GUILayout.Label ("Selected Point");
EditorGUI.BeginChangeCheck ();
Vector3 point = EditorGUILayout.Vector3Field ("Position", spline.GetControlPoint
(selectedIndex));
if (EditorGUI.EndChangeCheck ()) {
Undo.RecordObject (spline, "Move Point");
EditorUtility.SetDirty (spline);
spline.SetControlPoint (selectedIndex, point);
}
EditorGUI.BeginChangeCheck ();
BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup
("Mode", spline.GetControlPointMode (selectedIndex));
if (EditorGUI.EndChangeCheck ()) {
Undo.RecordObject (spline, "Change Point Mode");
spline.SetControlPointMode (selectedIndex, mode);
EditorUtility.SetDirty (spline);
}
}
void OnSceneGUI ()
{
spline = target as BezierSpline;
handleTransform = spline.transform;
handleRotation = Tools.pivotRotation == PivotRotation.Local ?
handleTransform.rotation : Quaternion.identity;
Handles.color = Color.gray;
Handles.DrawLine (p0, p1);
Handles.DrawLine (p2, p3);
void ShowDirections ()
{
Handles.color = Color.green;
Vector3 point = spline.GetPoint (0f);
Handles.DrawLine (point, point + spline.GetDirection (0f) * directionScale);
int steps = stepsPerCurve * spline.CurveCount;
for (int i = 1; i <= steps; i++) {
point = spline.GetPoint (i / (float)steps);
Handles.DrawLine (point, point + spline.GetDirection (i / (float)steps) * directionScale);
}
}