Skip to content

Instantly share code, notes, and snippets.

View mattmccray's full-sized avatar

Matt McCray mattmccray

View GitHub Profile
@mattmccray
mattmccray / BaseGameEvent.cs
Last active September 17, 2018 22:59
Simple event base class for Unity.
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace WizBangify
{
public delegate void Subscription(bool add);
@mattmccray
mattmccray / yaml-frontmatter.js
Last active February 4, 2018 22:07
Updated YamlFrontMatter mode for CodeMirror that includes the trailing "---" in the yaml block.
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../yaml/yaml"))
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../yaml/yaml"], mod)
else // Plain browser env
mod(CodeMirror)
@mattmccray
mattmccray / Announcements.cs
Last active November 24, 2017 21:34
Game Event definitions for Drumpf Flinger 9000 (a Unity 3D game)
using UnityEngine;
/*
You could name this class GameEvents or whatever you want. I chose Announcments because
it doesn't conflict with any builtin Unity class names. I can just type 'ann' and my IDE's
auto-complete takes care of the rest.
*/
public static class Announcements
{
public static class Camera
@mattmccray
mattmccray / AnimationTools.cs
Last active October 28, 2017 07:24
Rotation With AnimationCurves in Coroutine
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class AnimationTools
{
public static IEnumerator AnimateRotation(Transform animationTarget, Vector3 rotateTo, AnimationCurve curve, float time)
{
var timer = 0f;
using UnityEngine;
/// <summary>
/// Be aware this will not prevent a non singleton constructor
/// such as `T myT = new T();`
/// To prevent that, add `protected T () {}` to your singleton class.
///
/// As a note, this is made as MonoBehaviour because we need Coroutines.
/// </summary>
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : MonoBehaviour
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class FsmMonoBehaviour<TEnum> : MonoBehaviour where TEnum : struct, IConvertible, IComparable, IFormattable
{
private class StateMethodCache
{
public Action enterState;
@mattmccray
mattmccray / CameraShake.cs
Created October 18, 2017 17:24
Camera Shake
using UnityEngine;
using System.Collections;
public class CameraShake : MonoBehaviour
{
public static CameraShake instance;
private Vector3 _originalPos;
private float _timeAtCurrentFrame;
@mattmccray
mattmccray / assignableRef.ts
Last active August 31, 2017 21:50
Assignable Ref Helper (TS)
/**
* For use with React Components. Example usage:
*
* usernameInput = assignableRef<HTMLInputElement>(this)
*
* // In render...
*
* <input type="text" ref={this.usernameInput.assign} />
*
* // In a handler somewhere...
@mattmccray
mattmccray / Traveler.ts
Created July 29, 2017 15:37
Path walker
export function walkPath<T = any>(path: string[] | string): (source: any) => T | undefined {
const steps = Array.isArray(path) ? path : path.split('.')
return (source: any) => steps
.reduce((node, name) => (node && name in node ? node[name] : undefined), source)
}
export function runPath<T = any>(path: string[] | string): (source: any) => T {
const steps = Array.isArray(path) ? path : path.split('.')
return (source: any) => {
@mattmccray
mattmccray / MyJsonAPI.ts
Created June 11, 2017 19:24
MyJsonAPI TypeScript
class MyJsonAPI<T = any> {
key: string
constructor(key?: string) {
if (validKey(key)) {
this.key = key
}
}