void Start() { BezierPath path = GetComponent <PathCreator>().path; evenPoints = path.CalculateEvenlySpacedPoints(spacing * 2); BezierMovement.instance.SetPoints(evenPoints); }
//--------------------------------------------------------------- // // HELPER FUNCTIONS // //--------------------------------------------------------------- private List <Vector2[]> CreateBezierPath(List <Vector2[]> original) { var mainAnchorPoints = new List <Vector2>(); // Find one of the end points Vector2 start = Vector2.zero; foreach (var line in original) { foreach (var p in line) { if (!original.Any(a => a != line && (a[0] == p || a[1] == p))) { start = p; break; } } if (start != Vector2.zero) { break; } } if (start == Vector2.zero) { return(new List <Vector2[]>()); } mainAnchorPoints.Add(start); // Create main path control pointss while (original.Count > 0) { for (int i = 0; i < original.Count; i++) { var line = original[i]; if (line[0] == mainAnchorPoints.Last()) { mainAnchorPoints.Add((mainAnchorPoints.Last() + line[1]) / 2); mainAnchorPoints.Add(line[1]); original.Remove(line); break; } else if (line[1] == mainAnchorPoints.Last()) { mainAnchorPoints.Add((mainAnchorPoints.Last() + line[0]) / 2); mainAnchorPoints.Add(line[0]); original.Remove(line); break; } } } // Create main path bezier spline BezierPath path = new BezierPath(mainAnchorPoints); var curve = path.CalculateEvenlySpacedPoints(BiomeSettings.PathBezierSegmentSize); var result = new List <Vector2[]>(); for (int i = 0; i < curve.Length - 1; i++) { var p0 = curve[i]; var p1 = curve[i + 1]; result.Add(new[] { p0, p1 }); } return(result); }