Skip to content

Instantly share code, notes, and snippets.

View fversnel's full-sized avatar

Frank Versnel fversnel

View GitHub Profile
@fversnel
fversnel / GameObjectFactory.cs
Created January 29, 2015 11:51
Unity Game Object Factory
using System;
using UnityEngine;
namespace RamjetAnvil.GameObjectFactories
{
public struct ObjectFactory {
private readonly bool _isObjectActive;
private readonly Func<GameObject> _instantiator;
public ObjectFactory(bool isObjectActive, Func<GameObject> instantiator) {
@fversnel
fversnel / SmartSortable.js
Created December 30, 2014 11:36
React SmartSortable
var cloneWithProps = React.addons.cloneWithProps;
var SmartSortable = React.createClass({
getDefaultProps: function() {
return {component: "ul", childComponent: "li"};
},
render: function() {
var props = jQuery.extend({}, this.props);
@fversnel
fversnel / SingleAxisDeadzone.cs
Last active August 29, 2015 14:03
Single axis deadzone
public static Func<float, float> SingleAxisDeadzone(float deadzone)
{
var scalingFactor = 1 - deadzone;
return axisState =>
{
if (Mathf.Abs(axisState) < deadzone)
{
return 0f;
}
@fversnel
fversnel / ObserveVsSelect.cs
Last active August 29, 2015 14:01
Difference between Select and Observable.Create
void Start ()
{
var onNext = UnityObservable.EveryUpdate<float>(observer =>
{
Debug.Log("on next call: " + Time.time);
observer.OnNext(Time.time);
});
var select = UnityObservable.EveryUpdate<Unit>(observer => observer.OnNext(Unit.Default))
.Select(_ =>
{
@fversnel
fversnel / UnitySingleton.cs
Created October 15, 2013 14:13
Singleton implementation from the 'Unite 2013 - Internal Unity Tips and Tricks' talk (http://www.youtube.com/watch?v=Ozc_hXzp_KU)
using UnityEngine;
public class Example : MonoBehaviour
{
public static Example Singleton;
void OnEnable()
{
if (Singleton == null)
Singleton = this;
@fversnel
fversnel / AnonymousMonobehaviours.cs
Last active December 25, 2015 07:49
Creates an anonymous MonoBehaviour instance from a given update Action.
public static class AnonymousMonoBehaviours
{
private static readonly Action EmptyAction = () => { };
/// <summary>
/// Creates an anonymous MonoBehaviour instance from a given update Action.
/// The instance can be destroyed by calling Dispose on the returned IDisposable.
/// </summary>
/// <param name="updateFn">Called whenever AnonymousMonobehaviour.Update() is called.</param>
/// <param name="startFn">Called whenever AnonymousMonobehaviour.Start() is called.</param>
public enum MoveType { LightPunch, MediumPunch, HeavyPunch, SuperPunch, Fireball }
public class InputSequence
{
public IList<IList> sequence;
}
public class Move
{
public MoveType type;