Skip to content

Instantly share code, notes, and snippets.

View craigmjohnston's full-sized avatar
👍

Craig Johnston craigmjohnston

👍
View GitHub Profile
@craigmjohnston
craigmjohnston / UnityDirectoryContextMenuExample.cs
Created May 2, 2018 09:23
Example of how to have a context menu item in Unity that can only be used on folders.
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
public static class UnityDirectoryContextMenuExample
{
[MenuItem("Assets/My Context Item")]
public static void DoSomething()
{
@craigmjohnston
craigmjohnston / Entity.cs
Created February 28, 2017 10:59
Modified Entity.cs from GeonBit.UI with LimitPositionToParentBoundaries added (doesn't work properly)
#region File Description
//-----------------------------------------------------------------------------
// Base UI entity. Every widget inherit from this class.
// The base entity implement the following key functionality:
// 1. Drawing basic stuff like tiled textures with frames etc.
// 2. Positioning and calculating destination rect.
// 3. Basic events.
// 4. Visibility / Disabled / Locked modes.
// 5. Managing child entities.
//
class Plant : MonoBehaviour {
Sprite sprite;
float growTime;
AudioClip sfx;
void Start() {
StartCoroutine(WaitForSeconds(growTime));
}
IEnumerator WaitForSeconds Grow(float duration) {
@craigmjohnston
craigmjohnston / MusicControls.ahk
Created May 26, 2016 14:07
AutoHotkey script for media controls, including the SpotifySaveToMusic script snippet.
/*
Spotify "Save to Music"
Based on: http://superuser.com/a/879589
Fires on Ctrl+Shift+L, but obviously you can change that to whatever you want.
*/
^+l::
spotify = ahk_class SpotifyMainWindow
IfWinExist, %spotify%
{
;Store active window and mouse position.
@craigmjohnston
craigmjohnston / SpotifySaveToMusic.ahk
Last active June 5, 2017 21:51
AutoHotkey script for saving current song to your music. Moves to Spotify, rightclicks the currently playing song's title, checks the pixel colour of a certain position to find out the size of the context menu (it's wider if you've already added the song) and then saves it if it isn't already and moves back to what you were doing before.
/*
Spotify "Save to Music"
Based on: http://superuser.com/a/879589
Fires on Ctrl+Shift+L, but obviously you can change that to whatever you want.
*/
^+l::
spotify = ahk_class SpotifyMainWindow
IfWinExist, %spotify%
{
;Store active window and mouse position.
@craigmjohnston
craigmjohnston / Build.cs
Created April 1, 2016 15:07
A Unity3d editor script used to perform generic builds from the command line.
using System;
using System.Collections.Generic;
using UnityEditor;
public class Build {
static string[] SCENES = FindEnabledEditorScenes();
static void PerformBuild() {
GenericBuild(
SCENES,
///
/// Simple pooling for Unity.
/// Author: Martin "quill18" Glaude (quill18@quill18.com)
/// Latest Version: https://gist.github.com/quill18/5a7cfffae68892621267
/// License: CC0 (http://creativecommons.org/publicdomain/zero/1.0/)
/// UPDATES:
/// 2015-04-16: Changed Pool to use a Stack generic.
///
/// Usage:
///
@craigmjohnston
craigmjohnston / qwerty_nearbykeys_alphanum
Created May 21, 2015 12:25
A mapping of the alphanumeric keys on a QWERTY keyboard to all adjacent alphanumeric keys. Intended for use in generating possible typos.
'1': ['q', '2'],
'2': ['1', 'q', 'w', '3'],
'3': ['2', 'w', 'e', '4'],
'4': ['3', 'e', 'r', '5'],
'5': ['4', 'r', 't', '6'],
'6': ['5', 't', 'y', '7'],
'7': ['6', 'y', 'u', '8'],
'8': ['7', 'u', 'i', '9'],
'9': ['8', 'i', 'o', '0'],
'0': ['9', 'o', 'p'],
@craigmjohnston
craigmjohnston / .gitignore
Last active August 29, 2015 14:18
Gamejam .gitignore file for Unity projects. Ignores all of the usual disposable Unity files, as well as a Assets/Libraries folder that holds any 3rd party libraries.
# Unity
*.unityproj
[Oo]bj/
[Tt]emp/
[Ll]ibrary/
[Bb]uild/
# OSX
.DS_Store*
._*
@craigmjohnston
craigmjohnston / Mathfx.cs
Created December 10, 2014 17:28
Extra maths stuff for Unity - taken from http://wiki.unity3d.com/index.php?title=Mathfx
using UnityEngine;
using System;
public class Mathfx
{
public static float Hermite(float start, float end, float value)
{
return Mathf.Lerp(start, end, value * value * (3.0f - 2.0f * value));
}