46 lines
1.0 KiB
C#
46 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class RopeBuilder
|
|
{
|
|
List<Point> points = new();
|
|
List<Stick> sticks = new();
|
|
|
|
public RopeBuilder() { }
|
|
public RopeBuilder(List<Point> points, List<Stick> sticks)
|
|
{
|
|
this.points = points;
|
|
this.sticks = sticks;
|
|
}
|
|
|
|
public RopeBuilder AddPoint(Point point)
|
|
{
|
|
points.Add(point);
|
|
return this;
|
|
}
|
|
|
|
public RopeBuilder ConnectPoints(Point A, Point B)
|
|
{
|
|
sticks.Add(new Stick(A, B));
|
|
return this;
|
|
}
|
|
|
|
public RopeBuilder ConnectPoints(int idxA, int idxB)
|
|
{
|
|
sticks.Add(new Stick(points[idxA], points[idxB]));
|
|
return this;
|
|
}
|
|
|
|
public RopeBuilder ConnectPointsWithDesiredLength(int idxA, int idxB, float desiredLength)
|
|
{
|
|
sticks.Add(new Stick(points[idxA], points[idxB], desiredLength));
|
|
return this;
|
|
}
|
|
|
|
public Rope Build()
|
|
{
|
|
return new Rope(points: points.ToArray(), sticks: sticks.ToArray());
|
|
}
|
|
}
|