Skip to content

Instantly share code, notes, and snippets.

View mstevenson's full-sized avatar

Michael Stevenson mstevenson

View GitHub Profile
@mstevenson
mstevenson / InklewriterSharpSaveRestore.cs
Created January 11, 2018 22:44
An idea for how to save and restore the state of an InklewriterSharp game.
// Load story file
string storyJson = File.ReadAllText ("Stories/musgraveritual.json");
StoryModel model = StoryModel.Create (storyJson);
// Find the saved stitch and fast forward the story's initial stitch:
string restoredStitchName = "holmesResumedHis"; // load this from disk
foreach (var stitch in model.Story.Stitches) {
if (stitch.Name == restoredStitchName) {
// Fast forward the story to this stitch
model.Story.InitialStitch = stitch;
# OS X Tweaks
# ===========
# General
# -------
# Disable smart quotes and dashes
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
@mstevenson
mstevenson / ogg2mp3.sh
Created June 12, 2016 21:50
Convert Ogg to MP3 with ffmpeg
for name in *.ogg; do ffmpeg -i "$name" -ab 128k -map_metadata 0:s:0 "${name/.ogg/.mp3}"; done;
@mstevenson
mstevenson / IEnumeratorExtension.cs
Created April 10, 2016 00:31
Execute a Unity Coroutine in one frame without yielding
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public static class IEnumeratorExtensions
{
/// <summary>
/// Execute an entire Unity Coroutine in one frame.
/// This is useful for testing coroutines with NUnit.
///
@mstevenson
mstevenson / DoForSeconds.cs
Created January 23, 2016 08:56
An alternative to Unity's WaitForSeconds yield instruction that invokes a callback during each Update.
/// <summary>
/// Yield on a DoForSeconds object within a coroutine and the supplied callback method
/// will be invoked during each Unity Update cycle.
///
/// Example: yield return DoForSeconds (1, (elapsed, duration) => { Debug.Log (elapsed/duration); });
/// </summary>
public class DoForSeconds : CustomYieldInstruction
{
public delegate void UpdateCallback (float elapsed, float duration);
@mstevenson
mstevenson / lfs.gitattributes
Last active September 27, 2023 00:57
Git LFS attributes file for Unity, Maya and ZBrush
# unity
*.unitypackage filter=lfs diff=lfs merge=lfs -text
*.cubemap filter=lfs diff=lfs merge=lfs -text
*.spm filter=lfs diff=lfs merge=lfs -text
# models
*.mb filter=lfs diff=lfs merge=lfs -text
*.MB filter=lfs diff=lfs merge=lfs -text
@mstevenson
mstevenson / Instruments.cs
Created February 4, 2015 10:15
Unity tool for measuring execution time
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Debugging tools
/// </summary>
public static class Instruments
{
static string stopwatchName;
@mstevenson
mstevenson / FindReferences.cs
Last active September 24, 2021 04:31
Find Unity objects that reference a selected asset
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class FindReferences : EditorWindow, ISerializationCallbackReceiver
{
List<string> displayedRefs = new List<string>();
@mstevenson
mstevenson / InputEvents.cs
Created January 6, 2015 08:09
Bind key presses to methods in Unity at runtime
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public delegate void InputKeyDelegate (KeyCode key);
public delegate void InputAxisDelegate (string name,float value);
public class InputEvents : MonoBehaviour
{
@mstevenson
mstevenson / SpriteAnimator.cs
Created November 20, 2014 01:11
2D sprite animator for Unity
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
[RequireComponent (typeof(SpriteRenderer))]
public class SpriteAnimator : MonoBehaviour
{
public List<Sprite> frames = new List<Sprite> ();
public float fps = 15;