Skip to content

Instantly share code, notes, and snippets.

@renaudbedard
renaudbedard / gist:3715057
Created September 13, 2012 15:23
JsonFx WFH
// ...
static JsonWriter jsonWriter;
static JsonReader jsonReader;
ReadResponse readResponse;
class ReadResponse
{
public string Message;
public interface IEdible
{
void Eat();
}
public interface IOrganic
{
void ApplyDubiousHealthBenefits(Body a);
}
public class PriceyApple : IEdible, IOrganic
@renaudbedard
renaudbedard / gist:7a90ec4a5a7359712202
Created September 11, 2014 18:39
Billboarding for Unity surface shaders
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
// get the camera basis vectors
float3 forward = -normalize(UNITY_MATRIX_V._m20_m21_m22);
float3 up = float3(0, 1, 0); //normalize(UNITY_MATRIX_V._m10_m11_m12);
float3 right = normalize(UNITY_MATRIX_V._m00_m01_m02);
// rotate to face camera
@renaudbedard
renaudbedard / gist:71b80bd7d76e4967376c
Created September 17, 2014 04:16
Barely tested Unity "Rich Text" substring tool
struct SubstringInfo
{
public int StartsAt;
public string TagSuffix;
public SubstringInfo(int startsAt, IEnumerable<string> tagSuffixChain)
{
StartsAt = startsAt;
TagSuffix = string.Empty;
foreach (var tagSuffix in tagSuffixChain)
@renaudbedard
renaudbedard / WaveformDisplay.cs
Created September 25, 2014 03:37
Waveform visualizer
using System;
using System.Collections;
using System.Threading;
using UnityEngine;
class WaveformDisplay : MonoBehaviour
{
public Tracker Tracker;
public int LineSegments;
@renaudbedard
renaudbedard / ADSR.cs
Last active August 3, 2023 09:14
ADSR Envelope for Unity
using System;
using System.Collections.Generic;
using UnityEngine;
/* ****************
* Sample Usage *
****************
// prerequisite : put a gameobject with the ADSR script on it in your scene
// this enables the update loop that transparently updates Envelope objects
@renaudbedard
renaudbedard / Waiters.cs
Created May 6, 2015 14:55
Stateful and stateless waiting classes
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using XnaCommons.Structure;
using XnaCommons.Tools;
namespace XnaCommons.Components
{
public static class Waiters
{
@renaudbedard
renaudbedard / EventExtensions.cs
Last active July 8, 2016 03:27
Generic method to hook events to Unity 4.6+ UI EventTriggers
public static class EventExtensions
{
public static void AddEvent<TSource, TEvent>(this EventTrigger _trigger, EventTriggerType _eventType, TSource _source, Action<TSource, TEvent> _delegate)
where TEvent : BaseEventData
{
EventTrigger.TriggerEvent triggerEvent = new EventTrigger.TriggerEvent();
triggerEvent.AddListener(_data => _delegate(_source, _data as TEvent));
_trigger.triggers.Add(new EventTrigger.Entry { eventID = _eventType, callback = triggerEvent });
}
}
@renaudbedard
renaudbedard / DrawActionScheduler.cs
Created August 17, 2016 01:17
The load-time GL call scheduler that FEZ 1.12 uses
using System;
using System.Collections.Concurrent;
namespace FezEngine.Tools
{
public static class DrawActionScheduler
{
static readonly ConcurrentQueue<Action> DeferredDrawActions = new ConcurrentQueue<Action>();
public static void Schedule(Action action)
using System;
using System.Globalization;
using UnityEngine;
namespace Yarn
{
// A value from inside Yarn.
public struct Value : IComparable, IComparable<Value>, IEquatable<Value>
{
internal readonly Type type;