Skip to content

Instantly share code, notes, and snippets.

View BrianMacIntosh's full-sized avatar

Brian MacIntosh BrianMacIntosh

View GitHub Profile
@BrianMacIntosh
BrianMacIntosh / Image2.cs
Created March 4, 2021 18:03
Shader for Unity UI that uses a four-color gradient, and custom Image component for using the shader with Sliced images.
using UnityEngine;
using UnityEngine.UI;
// Based on the Unity built-in image source (Unity Reference-Only License, https://unity3d.com/legal/licenses/Unity_Reference_Only_License)
// Modified to add full-mesh UVs by Brian MacIntosh
namespace UI
{
/// <summary>
/// Image override that fills the second UV channel with uniform UVs over the entire image.
@BrianMacIntosh
BrianMacIntosh / DialogueDesignerExample.cs
Last active October 16, 2021 05:34
Bare-bones example of using the Dialogue Designer Unity package (https://github.com/BrianMacIntosh/DialogueDesignerUnity)
using UnityEngine;
// Include the DialogueDesigner namespace
using DD;
/// <summary>
/// Complete example that plays a Dialogue Designer dialogue in the unity debug console.
/// Use the number keys to make choices.
/// </summary>
public class DialogueDesignerExample : MonoBehaviour
using System.Collections.Generic;
using System.Globalization;
using UnityEditor;
using UnityEngine;
/*
Copyright (c) 2019-2020 Brian MacIntosh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@BrianMacIntosh
BrianMacIntosh / ItemQuantityPropertyDrawer.cs
Created December 9, 2019 01:33
Base class for a Unity property drawer for structures like "quantity" of "thing"
using UnityEditor;
using UnityEngine;
// Author: Brian MacIntosh (The Periodic Group)
// MIT License
/// <summary>
/// Base class that can be extended to quickly create a property drawer for a structure containing
/// data like "quantity" of "thing".
/// </summary>
@BrianMacIntosh
BrianMacIntosh / UI-Gradient.shader
Last active March 22, 2023 16:09
Shader for Unity UI that uses a four-color gradient instead of a solid color as the tint color. Improved version with Sliced support: https://gist.github.com/BrianMacIntosh/23275e79bb7489b42ad4ac0916a56824.
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
// Modified to add gradient color by Brian MacIntosh
Shader "UI/Gradient"
{
Properties
{
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
_TopLeftColor("Gradient Top Left", Color) = (1,1,1,1)
_TopRightColor("Gradient Top Right", Color) = (1,1,1,1)
@BrianMacIntosh
BrianMacIntosh / Sprites.cs
Created May 28, 2018 04:47
These classes provide easy methods for displaying animated sprites in XNA.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
/*
* XNA Lightweight Sprite Animation
* by Brian MacIntosh for ThunderFish Entertainment/BoneFish Studios
@BrianMacIntosh
BrianMacIntosh / Microphone.cs
Last active May 28, 2018 04:47
This class provides easy access to the Windows Phone microphone hardware with XNA.
using System;
using System.IO;
using Microsoft.Xna.Framework.Audio;
/*
* XNA Windows Phone Easy Microphone Access
* by Brian MacIntosh for ThunderFish Entertainment/BoneFish Studios
*
* Version: 1.1
*
@BrianMacIntosh
BrianMacIntosh / Accelerometer.cs
Last active May 28, 2018 04:50
This class greatly simplifies access to the accelerometer on the Windows Phone with XNA. Features include easy zeroing and "shake" gesture detection.
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Devices.Sensors;
/*
* XNA Windows Phone Easy Accelerometer Access
* by Brian MacIntosh for ThunderFish Entertainment/BoneFish Studios
*
* Version: 1.0
@BrianMacIntosh
BrianMacIntosh / DegreesRadians.cs
Last active August 9, 2017 16:49
Shows how type-safe, automatically-converted degree and radian types could be created in C#.
using System;
class Program
{
static void Main(string[] args)
{
AngleDegrees angleA = new AngleDegrees(90);
AngleRadians angleB = new AngleRadians(Math.PI / 2);
// angleA will be implicitly converted to AngleRadians because that's what the method parameter is
@BrianMacIntosh
BrianMacIntosh / ContactListenerSample.js
Last active June 4, 2019 07:55
Sample code showing how to create a contact listener in box2d.js
//sample code showing how to create a contact listener with
//kripken's Javascript port of Box2D.js
//https://github.com/kripken/box2d.js/
var gravity = new Box2D.b2Vec2(0.0, 10.0);
var world = new Box2D.b2World(gravity);
var contactListener = new Box2D.JSContactListener();
contactListener.BeginContact = function(contact)