Skip to content

Instantly share code, notes, and snippets.

View flarb's full-sized avatar

Ralph Barbagallo flarb

View GitHub Profile
@flarb
flarb / DiffuseDetailAmbient.shader
Created February 16, 2012 09:42
Mobile Ambient Diffuse Detail shader for Unity3D - just a simple one line change.
Shader "Mobile/Ambient Diffuse Detail" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Detail ("Detail (RGB)", 2D) = "gray" {}
}
SubShader {
Pass{
@flarb
flarb / PlayScene.cs
Created December 20, 2012 08:50
Lets you save the currently selected Unity3D scene. Then automatically load and run the saved scene via keyboard shortcut. If you break up your Unity3D projects into multiple scenes--including a loading scene--this saves a lot of manual switching of scenes.
using UnityEngine;
using System.Collections;
using UnityEditor;
/*
* Written by Ralph A. Barbagallo III
*
* www.ralphbarbagallo.com
*
* I wrote this becuase I was sick of switching scenes to play my loader scene and test my game.
syntax: glob
Build
Temp
obj
*.suo
*.sln
*.sln.docstates
*.csproj
*.unityproj
*.pidb
@flarb
flarb / Controller.cs
Created December 30, 2016 22:52
Simple Daydream controller shake / direction detection. Modified from Daydream sample controller code and a low pass filter example I found on stack overflow
using UnityEngine;
using System.Collections;
public class Controller : MonoBehaviour {
public GameObject controllerPivot;
public float accelerometerUpdateInterval = 1f / 60f;
public float lowPassKernelWidthInSeconds = 1f;
public float shakeDetectionThreshold = 2f;
using UnityEngine;
using System.Collections;
public class MeshPixelTools : MonoBehaviour {
// Use this for initialization
void Start () {
}
@flarb
flarb / NaturalOrientation.cs
Created August 4, 2012 00:03
How to detect the "natural" orientation of an Android device in Unity3D. Also can use to detect tablet and phone.
using UnityEngine;
using System.Collections;
public class NaturalOrientation : MonoBehaviour {
public static int ORIENTATION_UNDEFINED = 0x00000000;
public static int ORIENTATION_PORTRAIT = 0x00000001;
public static int ORIENTATION_LANDSCAPE = 0x00000002;
public static int ROTATION_0 = 0x00000000;
@flarb
flarb / .gitignore
Created July 3, 2016 08:19
Proper gitignore for HoloLens project (includes UWP folder)
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Uu]WP/
/Assets/AssetStoreTools*
# Autogenerated VS/MD solution and project files
ExportedObj/
@flarb
flarb / VRInputModule.cs
Created August 20, 2014 22:27
Lets you use a VR world space cursor with World Space Canvases in Unity3D 4.6. Add this to the EventSystem object. Put some box colliders on your buttons in the World Space Canvas. Then, do a trace to see if you're looking at a menu object--if the trace hits one of those buttons, pass it to SetTargetObject. See ralphbarbagallo.com for a longer e…
using UnityEngine;
using UnityEngine.EventSystems;
//by Ralph Barbagallo
//www.flarb.com
//www.ralphbarbagallo.com
//@flarb
public class VRInputModule : BaseInputModule {
@flarb
flarb / MapUtils.cs
Created February 18, 2013 20:50
A port of this PHP code: http://stackoverflow.com/questions/1763917/google-static-maps-move-maps-with-a-finger To C# in Unity3D to convert google maps lat/lng to pixel coordinates and vice versa.
using UnityEngine;
using System.Collections;
public class MapUtils {
static float GOOGLEOFFSET = 268435456f;
static float GOOGLEOFFSET_RADIUS = 85445659.44705395f;//GOOGLEOFFSET / Mathf.PI;
static float MATHPI_180 = Mathf.PI/180f;
static private float preLonToX1 = GOOGLEOFFSET_RADIUS * (Mathf.PI/180f);
@flarb
flarb / SDKSwap.cs
Created May 23, 2015 18:50
Swap between Unity3D Google Cardboard and Gear VR / OVR Mobile SDKs. It swaps out the Android manifest files when you switch platforms--pretty much all you need (aside from wrapping the APIs) to switch platforms.
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
public class SDKSwap : EditorWindow {
static string _cardboardPath;
static string _OVRPath;