Skip to content

Instantly share code, notes, and snippets.

@Problematic
Problematic / useAnimationFrame.ts
Created Nov 25, 2020
React useAnimationFrame hook
View useAnimationFrame.ts
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)
View ToggleManager.tsx
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,
View QueryHelper.cs
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]
View LSystemGenerator.cs
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 Mar 14, 2018
Poisson Disc Sampling for Unity3D
View PoissonDiscSampler.cs
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{
View 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) {
View PatrolBehaviour.cs
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);
View flatten.js
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 Jan 21, 2017
Rate limiting for Unity
View RateLimiter.cs
using UnityEngine;
[CreateAssetMenu (menuName = "Problematic/Rate Limiter")]
public class RateLimiter : ScriptableObject
{
[SerializeField]
float capacity;
[SerializeField]
float fillRate;
@Problematic
Problematic / LitParticle.shader
Created Dec 2, 2016
Standard-lit particle shader for Unity3D
View LitParticle.shader
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