Skip to content

Instantly share code, notes, and snippets.

View fversnel's full-sized avatar

Frank Versnel fversnel

View GitHub Profile
public enum MoveType { LightPunch, MediumPunch, HeavyPunch, SuperPunch, Fireball }
public class InputSequence
{
public IList<IList> sequence;
}
public class Move
{
public MoveType type;
@fversnel
fversnel / UnetAvailablePort.md
Last active December 4, 2015 16:17
Get available port for UNET socket
using System.Net;
using System.Net.Sockets;
using UnityEngine.Networking;

var address = IPAddress.Parse("0.0.0.0");
int port;
using (var tempSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) {
    tempSocket.Bind(new IPEndPoint(address, port: 0));
 port = ((IPEndPoint) tempSocket.LocalEndPoint).Port;
frank@ui:~/Desktop/RakNet/DependentExtensions/Swig$ ./MakeSwig.sh ../../Source/
Performing Swig build
without SQLiteClientLogger
../../Source/RakNetDefines.h:28: Warning 305: Bad constant value (ignored).
../../Source/RakPeer.h:57: Warning 401: Nothing known about base class 'RNS2EventHandler'. Ignored.
../../Source/NatTypeDetectionClient.h:45: Warning 401: Nothing known about base class 'RNS2EventHandler'. Ignored.
../../Source/NatTypeDetectionServer.h:55: Warning 401: Nothing known about base class 'RNS2EventHandler'. Ignored.
../../Source/RakWString.h:40: Warning 503: Can't wrap 'operator wchar_t*' unless renamed to a valid identifier.
Swig build complete
Removing and replacing the sample cs files with fresh ones
@fversnel
fversnel / FunctionalEntitas.cs
Created June 26, 2015 11:22
First version of a functional API for the Entitas framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Entitas.Functional {
/// <summary>
/// TODO Naming systems with string instead of Type
@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 / 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(_ =>
{