Skip to content

Instantly share code, notes, and snippets.

View sinbad's full-sized avatar

Steve Streeting sinbad

View GitHub Profile
@sinbad
sinbad / License.txt
Last active March 14, 2025 01:22
Unity 2D Line Segment Intersection
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@sinbad
sinbad / SlotArray.cs
Created November 9, 2018 15:27
SlotArray: an array as convenient as a dynamic list but with exposed indexes (similar to using a Dictionary<int,T> but more memory friendly, or an ArrayList which self-manages free slots)
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Utility class which stores a dynamic array of objects or value types, and exposes
/// where it places them in its internal storage so you can remove them by index
/// if you need to. Indexes remain stable at all times.
///
/// This is useful for cases like Coroutine where you may not have a reference
@sinbad
sinbad / HashStream.cs
Last active January 15, 2023 14:21
HashStream: simple C# Stream wrapper that calculates a hash of anything passed through it, but doesn't alter the content
using System.IO;
using System.Security.Cryptography;
// Copyright 2018 Steve Streeting
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@sinbad
sinbad / LightFlickerEffect.cs
Last active March 29, 2025 02:16
Unity simple & fast light flicker script
using UnityEngine;
using System.Collections.Generic;
// Written by Steve Streeting 2017
// License: CC0 Public Domain http://creativecommons.org/publicdomain/zero/1.0/
/// <summary>
/// Component which will flicker a linked light while active by changing its
/// intensity between the min and max values given. The flickering can be
/// sharp or smoothed depending on the value of the smoothing parameter.
@sinbad
sinbad / MeshRendererSortingEditor.cs
Last active January 28, 2025 17:11
Expose sorting layer in MeshRenderer inspector, for rendering on top of sprites
using UnityEngine;
using UnityEditor;
using System.Linq;
/// This just exposes the Sorting Layer / Order in MeshRenderer since it's there
/// but not displayed in the inspector. Getting MeshRenderer to render in front
/// of a SpriteRenderer is pretty hard without this.
[CustomEditor(typeof(MeshRenderer))]
public class MeshRendererSortingEditor : Editor
{
@sinbad
sinbad / spriterecolour.md
Last active November 9, 2016 13:58
Sprite recolouring approach

Approach

  1. Analyse the image and convert all colours to hue/saturation/value (HSV)
  2. Consolidate a list of all unique hue/saturation/value combinations
  3. Group HSV values with same H and similar SV; S & V ranges configurable
  4. Create a list of unique grouped reference colours, write this to a 1D texture and/or a list of shader constants
  5. Write another sprite texture the same size as the original, which we call the reference sprite. Set the colour components as follows:
    • R = index of reference colour
@sinbad
sinbad / gist:4a3d01077324f47dc82a
Created October 22, 2015 15:02
git-lfs Windows integration tests clean
steve@STEVENSTREED3AA MINGW64 ~/Documents/projects/Go/src/github.com/github/git-lfs (windows-tests)
$ script/integration
compile git-lfs for script/integration
commands\mancontent_gen.go
Using go1.5.1
Git LFS: /c/Users/steve/Documents/projects/Go/src/github.com/github/git-lfs/bin/git-lfs
git-lfs/1.0.0 (GitHub; windows amd64; go 1.5.1; git e980edd)
git version 2.5.1.windows.1
Updated pre-push hook.
Git LFS initialized.