Skip to content

Instantly share code, notes, and snippets.

View Hyperparticle's full-sized avatar
📝
Researching

Dan Kondratyuk Hyperparticle

📝
Researching
View GitHub Profile
@Hyperparticle
Hyperparticle / DrawTriangle.cs
Created November 28, 2017 17:36
Triangle Prefab Script
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; } }
@Hyperparticle
Hyperparticle / DrawControllerV2.cs
Created November 28, 2017 17:24
Draw Controller - Version 2
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;
@Hyperparticle
Hyperparticle / DrawCircle.cs
Last active June 1, 2019 17:28
Circle Prefab Script
public class DrawCircle : DrawShape
{
private CircleCollider2D _circleCollider2D;
// ...
private void Awake()
{
_circleCollider2D = GetComponent<CircleCollider2D>();
@Hyperparticle
Hyperparticle / DrawShape.cs
Created November 28, 2017 16:27
Abstract class for all shapes
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.
@Hyperparticle
Hyperparticle / DrawControllerV1.cs
Last active November 28, 2017 16:01
Draw Controller - Version 1
public class DrawController : MonoBehaviour
{
// ...
private void AddShapeVertex(Vector2 position)
{
if (CurrentShapeToDraw == null) {
// ...
} else {
if (IsDrawingShape) {
@Hyperparticle
Hyperparticle / DrawRectangleV1.cs
Last active May 25, 2018 11:30
Rectangle Prefab Script - Version 1
public class DrawRectangle : MonoBehaviour
{
// ...
private Rigidbody2D _rigidbody2D;
private BoxCollider2D _boxCollider2D;
private bool _simulating;
public bool SimulatingPhysics
{
@Hyperparticle
Hyperparticle / Util.cs
Last active November 24, 2017 13:02
Utility Class for Vectors
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);
}
@Hyperparticle
Hyperparticle / DrawRectangleV0.cs
Last active November 24, 2017 13:03
Rectangle Prefab Script - Version 0
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);
@Hyperparticle
Hyperparticle / DrawControllerV0.cs
Last active November 28, 2017 15:59
Draw Controller - Version 0
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()
@Hyperparticle
Hyperparticle / TestPolygon.cs
Last active June 25, 2022 04:57
Draw a polygon mesh in Unity
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),