Skip to content

Instantly share code, notes, and snippets.

@thebne
thebne / PointOnBounds.cs
Last active January 21, 2021 09:33
Get closest point on bounds (not within)
Vector3 GetClosestPointOnBounds(Bounds bounds, Vector3 point)
{
var boundPoint1 = bounds.min;
var boundPoint2 = bounds.max;
var points = new Vector3[] {
new Vector3(boundPoint1.x, boundPoint1.y),
new Vector3(boundPoint1.x, boundPoint2.y),
new Vector3(boundPoint2.x, boundPoint2.y),
new Vector3(boundPoint2.x, boundPoint1.y),
@thebne
thebne / BezierCurve5Points.cs
Created January 14, 2021 09:51
Unity Bezier 5 points
void DrawBezierCurve(Vector3 point0, Vector3 point1, Vector3 point2, Vector3 point3, Vector3 point4)
{
lineRenderer.positionCount = 50;
float t = 0f;
Vector3 B;
for (int i = 0; i < lineRenderer.positionCount; i++)
{
B = 1 * (1 - t) * (1 - t) * (1 - t) * (1 - t) * point0
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class GuardianJsonRecorder : MonoBehaviour
{
void Update()
{
@thebne
thebne / ExpandConvexHull.cs
Last active June 30, 2020 15:03
Expand fill of convex polygon - Unity (C#)
// this is an adaptation to Unity of the algorithm described
//. in https://stackoverflow.com/questions/3749678/expand-fill-of-convex-polygon/3897471
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
static class ConvexHull
{
public static Vector2[] ExpandConvexHull(Vector2[] poly, float distance)
{