Skip to content

Instantly share code, notes, and snippets.

View sinbad's full-sized avatar

Steve Streeting sinbad

View GitHub Profile
@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.
@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 / MeshRendererSortingEditor.cs
Last active November 3, 2023 14:40
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 / LightFlickerEffect.cs
Last active March 22, 2024 09:02
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 / 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 / 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 / License.txt
Last active May 29, 2024 08:30
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
private Dictionary<int, Action<Localisation.VariableSetter>> localisationVariableFuncs;
private void InitLocalisation() {
Localisation.Instance.DefaultVariableCallback = LocalisationVariableCallback;
localisationVariableFuncs = new Dictionary<int, Action<Localisation.VariableSetter>>{
{LocalisationConsts.Variables.ShotStyleBonusHash, setter => setter.SetValue(shotStyleBonuses)},
{LocalisationConsts.Variables.ShotPegScoreHash, setter => setter.SetValue(shotPegScore)}
};
// Iterate over all strings and pre-convert action tags to IDs so we only do this once
Localisation.Instance.ProcessMessages(InitLocalisationMessage);
@sinbad
sinbad / CombinedOverlapCollider.cs
Last active November 29, 2019 15:52
Quick hack to use a single shared array for results from multiple Unity OverlapCollider calls
// I always use the Unity collider calls which place results in a single pre-allocated array to avoid allocations.
// However it's a bit annoying that you can't make a call like `collider2D.OverlapCollider` and tell it to start
// inserting results at a non-zero index in that results array, in order to collect multiple tests in a single
// result array.
// Yes, you can (and should) use CompoundCollider2D if this is a single object you're tracking, but if it's not and
// you just want combined results from different colliders it's a ball-ache to not be able to get all results in a
// single array easily.
// This little snippet shunts results of earlier OverlapCollider calls to the end of the array temporarily,
@sinbad
sinbad / SpriteMeshRaycastFilter.cs
Last active May 11, 2023 05:35
SpriteMeshRaycastFilter: easy Unity UI non-rectangular click detector without reading textures
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// Restrict raycasting to a sprite mesh shape
// Could use Image.alphaHitTestMinimumThreshold to mask but that requires read/write images which can't be packed
[RequireComponent(typeof(Image))]
public class SpriteMeshRaycastFilter : MonoBehaviour, ICanvasRaycastFilter {
private RectTransform rectTransform;