Skip to content

Instantly share code, notes, and snippets.

View simonwittber's full-sized avatar

Simon Wittber simonwittber

  • Different Methods
  • Australia
View GitHub Profile
@simonwittber
simonwittber / TouchGesture.cs
Last active July 10, 2018 14:14
Simple touch recogniser for Unity.
public class TouchRecognizer : MonoBehaviour
{
const float LOWPASS_FILTER = 0.1f;
const float ANGLE_DELTA_THRESHOLD = 0.001f;
const float PINCH_DELTA_THRESHOLD = 0.1f;
const float TIME_REQUIRED_FOR_SINGLE_TOUCH = 0.05f;
float _angleDelta, _pinchDelta, angleDelta, pinchDelta;
Vector3 delta;
@simonwittber
simonwittber / Event.cs
Created July 31, 2018 08:58
Another pub-sub system for loose coupling.
/*
// Example Usage:
public class SomeEv : Event<SomeEv> { }
public class SomeOtherEv : Event<SomeOtherEv> { }
public class EVTest : MonoBehaviour
{
void Start()
@simonwittber
simonwittber / HeapQueue.cs
Created August 16, 2018 12:09
Pooled Discrete Event Simulator in C#
using System;
using System.Collections.Generic;
namespace Simulator
{
public class HeapQueue<T> where T : IComparable<T>
{
List<T> items;
public int Count { get { return items.Count; } }
public static class ServiceLocator<TA> where TA : class
{
static System.Func<TA> constructor = null;
static System.Type type;
public static void Bind<TB> () where TB:TA,new()
{
type = typeof(TB);
@simonwittber
simonwittber / Goroutine.cs
Created October 1, 2018 14:18
Pooled coroutines for Unity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StopAction : YieldInstruction
{
}
public class GoroutinePool
@simonwittber
simonwittber / InstancedRenderer.cs
Created February 11, 2019 13:02
Instance Rendering Helper
public class InstancedRenderer : System.IDisposable
{
const int BATCH_MAX = 1023;
public NativeArray<Matrix4x4> matrices;
public readonly int count, allocated;
public readonly Mesh mesh;
public readonly Material material;
Matrix4x4[] batchedMatrices = new Matrix4x4[BATCH_MAX];
@simonwittber
simonwittber / AddThingToSomeScriptableObject.cs
Last active February 12, 2019 11:34
Using Unity's ScriptableWizards as Dialogs in CustomEditors.
public class AddThingToSomeScriptableObject : ScriptableWizard
{
internal SomeScriptableObject someScriptableObject;
public SomeThing someThing;
void OnCreateButton()
{
//add someThing to someScriptableObject.
}
}
@simonwittber
simonwittber / InstanceTracker.cs
Created March 25, 2019 09:04
Tracks enabled MonoBehaviours.
public class InstanceTracker<T> : MonoBehaviour where T : MonoBehaviour
{
public static List<T> Instances { get; private set; } = new List<T>();
int instanceIndex = 0;
void OnEnable()
{
instanceIndex = Instances.Count;
Instances.Add(this as T);
}
@simonwittber
simonwittber / ColorBlindCorrection.cs
Last active October 16, 2025 17:31
Color Blindness Correction PostProcessing Effect for Unity.
using System;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
[Serializable]
[PostProcess(typeof(ColorBlindCorrectionRenderer), PostProcessEvent.AfterStack, "Custom/ColorBlindCorrection")]
public sealed class ColorBlindCorrection : PostProcessEffectSettings
{
[Header("1:Protanopia 2:Deuteranopia 3:Tritanopia")]
[Range(0, 2)]
@simonwittber
simonwittber / Domain.cs
Created May 1, 2019 12:56
DSL for HTN declaration.
public class AI
{
Domain CreateDomain()
{
using (domain = Domain.New())
{
worldState = DefineWorldState(health, fuel, speed, angularSpeed);
DefinePrimitiveTask(SetRandomDestination);
DefinePrimitiveTask(MoveToDestination)