void Update() { if (Input.GetKey(KeyCode.J)) { for (int i = 0; i < rageSpline.spline.points.Length - 1; i++) { float rnd = Random.Range(-0.25f, 0.25f); var newPos = rageSpline.GetPosition(i); rageSpline.SetPoint(i, new Vector3(newPos.x + rnd, newPos.y + rnd)); } } rageSpline.RefreshMesh(); }
public static void UpdateFarseerPhysics(RageSpline spline) { #if !UNITY_FLASH var fsConcave = spline.GetComponent <FSConcaveShapeComponent>(); if (fsConcave == null) { fsConcave = spline.gameObject.AddComponent <FSConcaveShapeComponent>(); } var fsBody = spline.GetComponent <FSBodyComponent>(); if (fsBody == null) { spline.gameObject.AddComponent <FSBodyComponent>(); } fsConcave.PointInput = FSShapePointInput.Vector2List; var points = new List <Vector2>(); if (spline.FarseerPhysicsPointsOnly) { for (int i = 0; i < spline.GetPointCount(); i++) { points.Add(spline.GetPosition(i)); } } else { int splitCount = spline.LockPhysicsToAppearence ? spline.GetVertexCount() : spline.GetPhysicsColliderCount(); for (int i = 0; i < splitCount; i++) { float splinePos = (float)i / (float)splitCount; Vector3 normal = spline.GetNormal(splinePos); points.Add(spline.GetPosition(splinePos) + normal * spline.GetPhysicsNormalOffset()); } } fsConcave.PointsCoordinates = points.ToArray(); fsConcave.ConvertToConvex(); #endif }
public RageSplinePreviewData(RageSpline spline) { _points = new List <RageSplinePreviewPointData>(); for (int i = 0; i <= spline.GetPointCount() - 1; i++) { var pointPosition = spline.GetPosition(i); if (i == 0) { _boundary = new Rect(pointPosition.x, pointPosition.y, 0, 0); } else { if (_boundary.xMin > pointPosition.x) { _boundary.xMin = pointPosition.x; } if (_boundary.xMax < pointPosition.x) { _boundary.xMax = pointPosition.x; } if (_boundary.yMin > pointPosition.y) { _boundary.yMin = pointPosition.y; } if (_boundary.yMax < pointPosition.y) { _boundary.yMax = pointPosition.y; } } _points.Add(new RageSplinePreviewPointData { Position = pointPosition, StartTangent = spline.GetInControlPosition(i), EndTangent = spline.GetOutControlPosition(i) }); } }
private void ShowCoordinatesData(RageSpline rageSpline) { EditorGUILayout.Separator(); GuiExtensions.Horizontal (( ) => { EditorGUILayout.LabelField ("Point X|Y", "", GUILayout.MinWidth (40f)); EditorGUILayout.LabelField ("Handle In X|Y", "", GUILayout.MinWidth (40f)); EditorGUILayout.LabelField ("Handle Out X|Y", "", GUILayout.MinWidth (40f)); }); EditorGUIUtility.LookLikeControls(); for (int p = 0; p < selectedControlPoints.Count; p++) { int i = selectedControlPoints[p]; switch (rageSpline.showCoordinates) { case RageSpline.ShowCoordinates.Local: EditorGUILayout.BeginHorizontal(); Vector2 newPos = new Vector2(); newPos.x = EditorGUILayout.FloatField (rageSpline.GetPosition (i).x, GUILayout.MinWidth (30f)); newPos.y = EditorGUILayout.FloatField (rageSpline.GetPosition (i).y, GUILayout.MinWidth (30f)); rageSpline.SetPoint (i, newPos); Vector2 newIn = new Vector2(); Vector2 newOut = new Vector2(); newIn.x = EditorGUILayout.FloatField (rageSpline.GetInControlPositionPointSpace (i).x, GUILayout.MinWidth (30f)); newIn.y = EditorGUILayout.FloatField (rageSpline.GetInControlPositionPointSpace (i).y, GUILayout.MinWidth (30f)); newOut.x = EditorGUILayout.FloatField (rageSpline.GetOutControlPositionPointSpace (i).x, GUILayout.MinWidth (30f)); newOut.y = EditorGUILayout.FloatField (rageSpline.GetOutControlPositionPointSpace (i).y, GUILayout.MinWidth (30f)); rageSpline.SetInControlPositionPointSpace (i, newIn); rageSpline.SetOutControlPositionPointSpace (i, newOut); EditorGUILayout.EndHorizontal(); break; case RageSpline.ShowCoordinates.World: EditorGUILayout.BeginHorizontal(); Vector2 newPos2 = new Vector2(); newPos2.x = EditorGUILayout.FloatField (rageSpline.GetPositionWorldSpace (i).x, GUILayout.MinWidth (30f)); newPos2.y = EditorGUILayout.FloatField (rageSpline.GetPositionWorldSpace (i).y, GUILayout.MinWidth (30f)); rageSpline.SetPointWorldSpace (i, newPos2); Vector2 newIn2 = new Vector2(); Vector2 newOut2 = new Vector2(); newIn2.x = EditorGUILayout.FloatField (rageSpline.GetInControlPositionWorldSpace (i).x, GUILayout.MinWidth (30f)); newIn2.y = EditorGUILayout.FloatField (rageSpline.GetInControlPositionWorldSpace (i).y, GUILayout.MinWidth (30f)); newOut2.x = EditorGUILayout.FloatField (rageSpline.GetOutControlPositionWorldSpace (i).x, GUILayout.MinWidth (30f)); newOut2.y = EditorGUILayout.FloatField (rageSpline.GetOutControlPositionWorldSpace (i).y, GUILayout.MinWidth (30f)); rageSpline.SetInControlPositionWorldSpace (i, newIn2); rageSpline.SetOutControlPositionWorldSpace (i, newOut2); EditorGUILayout.EndHorizontal(); break; } } }