void OnEnable() { spline = target as BezierSpline; if (spline.path == null) { spline.CreatePath(); } path = spline.path; splineTransform = spline.transform; splineRotation = spline.transform.rotation; }
public void UpdateRope() { BezierSplinePath path = GetComponent <BezierSpline>().path; Vector3[] points = path.CalculateEvenlySpacedPoints(spacing); GetComponent <MeshFilter>().mesh = CreateRopeMesh(points, path.IsClosed); int textureRepeat = Mathf.RoundToInt(tiling * points.Length * spacing * 0.5f); GetComponent <MeshRenderer>().sharedMaterial.mainTextureScale = new Vector2(1f, textureRepeat); }
public override void OnInspectorGUI() { base.DrawDefaultInspector(); EditorGUI.BeginChangeCheck(); /*********** DISPLAY CURRENT POINT POS **********/ if (selectedIndex >= 0 && selectedIndex < path.PointCount) { DrawSelectedPointInspector(); } /*********** Create New **********/ if (GUILayout.Button("Create New")) { Undo.RecordObject(spline, "Create New"); EditorUtility.SetDirty(spline); spline.CreatePath(); path = spline.path; } /*********** BUTTON ADD SEGMENT **********/ if (GUILayout.Button("Add Segment")) { Undo.RecordObject(spline, "Add Segment"); EditorUtility.SetDirty(spline); path.AddSegment(); } /*********** TOGGLE CLOSED **********/ bool isClosed = GUILayout.Toggle(path.IsClosed, "Closed"); if (isClosed != path.IsClosed) { Undo.RecordObject(spline, "Toggle Closed"); EditorUtility.SetDirty(spline); path.IsClosed = isClosed; } /*********** TOGGLE AUTOSET **********/ bool isAutoSet = GUILayout.Toggle(path.AutoSetPoints, "Auto Set Points"); if (path.AutoSetPoints != isAutoSet) { Undo.RecordObject(spline, "Toggle AutoSet"); EditorUtility.SetDirty(spline); path.AutoSetPoints = isAutoSet; } if (EditorGUI.EndChangeCheck()) { SceneView.RepaintAll(); } }
public override void OnInspectorGUI() { spline = target as BezierSplinePath; EditorGUI.BeginChangeCheck(); bool loop = EditorGUILayout.Toggle("Loop", spline.Loop); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Toggle Loop"); EditorUtility.SetDirty(spline); spline.Loop = loop; } if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount) { DrawSelectedPointInspector(); } if (GUILayout.Button("Add Curve")) { Undo.RecordObject(spline, "Add Curve"); spline.AddCurve(); EditorUtility.SetDirty(spline); } }
private void OnSceneGUI() { spline = target as BezierSplinePath; handleTransform = spline.transform; handleRotation = Tools.pivotRotation == PivotRotation.Local ? handleTransform.rotation : Quaternion.identity; Vector3 p0 = ShowPoint(0); for (int i = 1; i < spline.ControlPointCount; 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; } ShowDirections(); }
public void CreatePath() { path = new BezierSplinePath(transform.position); }