Skip to content

Instantly share code, notes, and snippets.

View paulhayes's full-sized avatar

Paul Hayes paulhayes

View GitHub Profile
@paulhayes
paulhayes / ColorExt.cs
Last active July 20, 2022 11:37
Extension to Unity3d Color and Color32. Allows easy converting of Color to hex string.
using UnityEngine;
using System.Collections;
public static class ColorExt {
public static string ToHexString(this Color32 c){
return string.Format ("{0:X2}{1:X2}{2:X2}", c.r, c.g, c.b);
}
public static string ToHexString(this Color color){
@paulhayes
paulhayes / range.js
Last active January 28, 2016 16:08
Port of pythons range function into javascript.
var range=function(x,y,z){ if(typeof(y)=='undefined'){y=x;x=0};if(typeof(z)=='undefined')z=1;var a=new Array(Math.floor(y-x)/z);for(var i=0;z*i<(y-x);i++)a[i]=(z*i)+x;return a }
@paulhayes
paulhayes / GyroControls.cs
Last active January 28, 2016 15:56
For Unity3d. Intended to be used as a member property of component. Simple Gyro input controller that tracks the relative rotation of the device while the screen is being touched.
[System.Serializable]
public class GyroControls{
public Vector3 clampRotation = new Vector3(30f,30f,30f);
public Vector3 deadZone = new Vector3(3f,3f,3f);
Quaternion startRotation;
bool touching;
Vector3 mRotation;
We wonder,—and some Hunter may express
Wonder like ours, when thro' the wilderness
Where London stood, holding the Wolf in chace,
He meets some fragment huge, and stops to guess
What powerful but unrecorded race
Once dwelt in that annihilated place.
@paulhayes
paulhayes / SavePrefab.cs
Last active May 13, 2016 11:05
Allows a user to save a prefab in play mode.
using UnityEngine;
using System.Collections;
public class SavePrefab : MonoBehaviour {
}
@paulhayes
paulhayes / DllLoadingAtRuntimeExample.cs
Last active February 21, 2024 14:00
Runtime loading dlls in Unity3d
using System;
using UnityEngine;
public class DllLoadingAtRuntimeExample : MonoBehaviour
{
static IntPtr nativeLibraryPtr;
delegate int MultiplyFloat(float number, float multiplyBy);
delegate void DoSomething(string words);
var psi = new ProcessStartInfo("shutdown","/s /t 0");
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
Process.Start(psi);
using System;
public class AppArgs {
public static T GetNamedArgument<T>(string key,T defaultValue) {
string[] args = Environment.GetCommandLineArgs();
int index = -1;
for(int i=0; i<args.Length-1; i++ ){
if( args[i] == key ){
index = i+1;
break;
public class CameraUtil {
public static void AdjustCustomProjectionClipPlanes(Camera sourceCamera){
Matrix4x4 projMatix = sourceCamera.projectionMatrix;
//-(far + near) / (far - near)
float m22 = projMatix.m22;
//-(2.0F * far * near) / (far - near);
float m23 = projMatix.m23;
float fmap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}