Skip to content

Instantly share code, notes, and snippets.

View flarb's full-sized avatar

Ralph Barbagallo flarb

View GitHub Profile
@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;
@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 / StareButton.cs
Created May 23, 2015 22:48
This is a 'stare button' for Google Cardboard apps where you just want to stare at a button over time to select it.
using System;
using System.Reflection;
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
public class StareButton : MonoBehaviour, IEventSystemHandler, IPointerExitHandler, IPointerEnterHandler, ISelectHandler {
@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;
@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 {
syntax: glob
Build
Temp
obj
*.suo
*.sln
*.sln.docstates
*.csproj
*.unityproj
*.pidb
@flarb
flarb / Pixel2UV
Created February 18, 2013 20:53
Converts pixel coordinates in a texture to UV coordinates in Unity3D.
Vector2 uv = new Vector2((float)myMarker.pixelCoords.x / (float)renderer.material.mainTexture.width, 1f - (float)myMarker.pixelCoords.y / (float)renderer.material.mainTexture.height);
@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);
using UnityEngine;
using System.Collections;
public class MeshPixelTools : MonoBehaviour {
// Use this for initialization
void Start () {
}
@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.