Skip to content

Instantly share code, notes, and snippets.

View flarb's full-sized avatar

Ralph Barbagallo flarb

View GitHub Profile
@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 / AssetGPULoader.cs
Created July 22, 2012 19:06
Unity3d GPU Pre-loader
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class AssetGPULoader : MonoBehaviour {
public Camera activeCamera;
RenderTexture _rt;
@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 / 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 / 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 / .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 / 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;
using UnityEngine;
using System.Collections;
public class MeshPixelTools : MonoBehaviour {
// Use this for initialization
void Start () {
}
@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;