Skip to content

Instantly share code, notes, and snippets.

View Problematic's full-sized avatar

Derek Stobbe Problematic

View GitHub Profile
@Problematic
Problematic / useAnimationFrame.ts
Created November 25, 2020 20:14
React useAnimationFrame hook
import { useRef, useEffect, useCallback } from 'react'
const useAnimationFrame = (
tick: (dt: number, elapsed: number, frame: number) => void
) => {
const tickRef = useRef(tick)
const requestRef = useRef(0)
const prevTimeRef = useRef(0)
const elapsedRef = useRef(0)
const frameRef = useRef(0)
import React, { useState, useMemo, useContext } from 'react';
interface ToggleState {
items: any[];
toggleItem: (item: any, toggled?: boolean) => boolean;
}
const ToggleContext = React.createContext<ToggleState>({
items: [],
toggleItem: () => false,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Problematic/Query Helper")]
public class QueryHelper : ScriptableObject
{
[SerializeField]
protected float maxDistance = Mathf.Infinity;
[SerializeField]
@Problematic
Problematic / LSystemGenerator.cs
Last active March 21, 2018 17:51
L-System Generator
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public interface ILSystemGenerator {
string Generate (string axiom, int depth);
void Clear();
}
@Problematic
Problematic / PoissonDiscSampler.cs
Last active March 14, 2018 21:05
Poisson Disc Sampling for Unity3D
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Problematic.Toolkit {
// https://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf
public static class PoissonDiscSampler {
const int SAMPLE_LIMIT = 30;
public static IEnumerable<Vector2> Sample<T> (QuadTree<T> quadTree, float minSeparation, System.Func<Vector2, T> CreateSample, System.Func<Vector2, QuadTree<T>, float, bool> IsCandidateValid) where T : IQuadTreeObject{
@Problematic
Problematic / StateHistory.cs
Created January 24, 2018 16:09
StateHistory.cs
using System;
using System.Collections.Concurrent;
using UnityEngine;
public class StateHistory<T> where T : IState<T> {
protected T[] buffer;
public int Head { get; protected set; }
public int Tail {
get {
if (Count < buffer.Length) {
using UnityEngine;
using System.Collections.Generic;
public class PatrolBehaviour : MonoBehaviour {
Queue<Transform> patrolTargets;
void Start () {
patrolTargets = new Queue<Transform>();
patrolTargets.Enqueue(target1);
patrolTargets.Enqueue(target2);
function flatten (arr) {
if (!(arr instanceof Array)) {
return arr;
}
return arr.reduce((acc, val) => acc.concat(flatten(val)), []);
}
module.exports = flatten;
@Problematic
Problematic / RateLimiter.cs
Created January 21, 2017 17:12
Rate limiting for Unity
using UnityEngine;
[CreateAssetMenu (menuName = "Problematic/Rate Limiter")]
public class RateLimiter : ScriptableObject
{
[SerializeField]
float capacity;
[SerializeField]
float fillRate;
@Problematic
Problematic / LitParticle.shader
Created December 2, 2016 23:01
Standard-lit particle shader for Unity3D
Shader "Custom/Lit Particle" {
Properties {
_TintColor ("Tint Color", Color) = (1,1,1,1)
_MainTex ("Particle Texture", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 200
CGPROGRAM