Skip to content

Instantly share code, notes, and snippets.

@LotteMakesStuff
LotteMakesStuff / EditorExtensionMethods.cs
Last active January 12, 2025 14:33
A reimplementation of the logic in the Unity Editor that draws an inspector for a component. We can use this to learn how unity actually draws the inspector. for more info see https://www.patreon.com/posts/16724128
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Reflection;
public static class EditorExtensionMethods
{
// Public reimplmentation of extention methods and helpers that are marked internal in UnityEditor.dll
@JohannesMP
JohannesMP / 2DLineRectIntersection.md
Last active November 20, 2024 07:09
[C#, Unity3D] An optimized solver for intersection between a Line Segment and a Rect in 2D space with spacial partitioning.

Overview

For a 2D Unity Project, I needed a really efficient way to get the intersection points between a line segment (as defined by two Vector2) and an axis-aligned Rect in 2D space, where the intersection points are returned as a parametric fraction of the length of the original line segment:

Note how when the line intersects the rect, the green line represents the portion inside the rect, and the parametric representation of the point of intersection along the line is displayed

In my use case the vast majority of lines are either completely inside or completely outside the rect, and so I needed an approach that was very efficient in cases where there is guaranteed no intersection and avoids unecessary raycasts when possible.

@JohannesMP
JohannesMP / AttributeDemo.cs
Last active July 16, 2018 17:52
Conveniently extracting data of members on an object that were tagged with a given Attribute, with Reflection caching.
using UnityEngine;
using UnityEditor;
using Utils.Reflection;
using System.Linq;
public class AttributeDemo
{
/// <summary>
/// A quick demo for grabing fields on an object that were tagged with a given Attribute.
/// In this case an ‘Order’ attribute is used to display the tagged fields in a specific order.
@nfantone
nfantone / before-shutdown.js
Created September 23, 2020 13:00
Node.js graceful shutdown handler
'use strict';
/**
* @callback BeforeShutdownListener
* @param {string} [signalOrEvent] The exit signal or event name received on the process.
*/
/**
* System signals the app will listen to initiate shutdown.
* @const {string[]}