This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DrawTriangle : DrawShape | |
{ | |
// ... | |
private PolygonCollider2D _polygonCollider2D; | |
// Triangle vertices (in absolute coordinates) | |
private readonly List<Vector2> _vertices = new List<Vector2>(3); | |
public override bool ShapeFinished { get { return _vertices.Count >= 3; } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DrawController : MonoBehaviour | |
{ | |
public DrawMode Mode = DrawMode.Rectangle; | |
public DrawShape RectanglePrefab; | |
public DrawShape CirclePrefab; | |
public DrawShape TrianglePrefab; | |
// Associates a draw mode to the prefab to instantiate | |
private Dictionary<DrawMode, DrawShape> _drawModeToPrefab; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DrawCircle : DrawShape | |
{ | |
private CircleCollider2D _circleCollider2D; | |
// ... | |
private void Awake() | |
{ | |
_circleCollider2D = GetComponent<CircleCollider2D>(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class DrawShape : MonoBehaviour | |
{ | |
/// <summary> | |
/// Whether all the points in the shape have been specified | |
/// </summary> | |
public abstract bool ShapeFinished { get; } | |
/// <summary> | |
/// The status of whether the shape is simulating its physics. | |
/// Setting this property will enable or disable physics. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DrawController : MonoBehaviour | |
{ | |
// ... | |
private void AddShapeVertex(Vector2 position) | |
{ | |
if (CurrentShapeToDraw == null) { | |
// ... | |
} else { | |
if (IsDrawingShape) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DrawRectangle : MonoBehaviour | |
{ | |
// ... | |
private Rigidbody2D _rigidbody2D; | |
private BoxCollider2D _boxCollider2D; | |
private bool _simulating; | |
public bool SimulatingPhysics | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Util | |
{ | |
/// <summary> | |
/// Extension that converts an array of Vector2 to an array of Vector3 | |
/// </summary> | |
public static Vector3[] ToVector3(this Vector2[] vectors) | |
{ | |
return System.Array.ConvertAll<Vector2, Vector3>(vectors, v => v); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DrawRectangle : MonoBehaviour | |
{ | |
public Color FillColor = Color.white; | |
private MeshFilter _meshFilter; | |
private LineRenderer _lineRenderer; | |
// Start and end vertices (in absolute coordinates) | |
private readonly List<Vector2> _vertices = new List<Vector2>(2); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DrawController : MonoBehaviour | |
{ | |
public DrawRectangle RectanglePrefab; | |
private readonly List<DrawRectangle> _allShapes = new List<DrawRectangle>(); | |
private DrawRectangle CurrentShapeToDraw { get; set; } | |
private bool IsDrawingShape { get; set; } | |
private void Update() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestPolygon : MonoBehaviour | |
{ | |
private void Start () { | |
// Create Vector2 vertices | |
var vertices2D = new Vector2[] { | |
new Vector2(0,0), | |
new Vector2(0,1), | |
new Vector2(1,1), | |
new Vector2(1,2), | |
new Vector2(0,2), |
NewerOlder