Skip to content

Instantly share code, notes, and snippets.

View paulhayes's full-sized avatar

Paul Hayes paulhayes

View GitHub Profile
@paulhayes
paulhayes / StencilMask
Created October 24, 2016 20:21
Example of creating a window to see objects tagged with a specific stencil ID > 0
Shader "Stencils/Masks/StencilMask"
{
Properties{
_MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
_Stencil("Stencil ID", Int) = 0
}
SubShader
{
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;
}
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;
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;
var psi = new ProcessStartInfo("shutdown","/s /t 0");
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
Process.Start(psi);
@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);
@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 {
}
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 / 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;
@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 }