Skip to content

Instantly share code, notes, and snippets.

View corycorvus's full-sized avatar

Cory Corvus corycorvus

View GitHub Profile
@corycorvus
corycorvus / UnitySingleton.cs
Last active October 11, 2017 06:15
Unity Singleton Example
// Unity Singleton Example
// Call with "ClassName.instance.Example();"
public static ClassName instance = null; //Static instance of singleton which allows it to be accessed by any other script.
//Awake is always called before any Start functions
void Awake()
{
//Check if instance already exists
if (instance == null)
//if not, set instance to this
@corycorvus
corycorvus / UnityMonoBehaviour.cs
Last active October 11, 2017 06:15
Unity MonoBehaviour Example
using UnityEngine;
// Unity MonoBehaviour Example
// MonoBehaviour is the base class from which every Unity script derives.
public class ExampleScript : MonoBehaviour
{
// Awake is called when the script instance is being loaded.
void Awake(){}
// Start is called on the frame when a script is enabled just before any of the Update methods is called the first time.
void Start(){}
@corycorvus
corycorvus / WindowsNativeDialog.cs
Created October 11, 2017 06:14
Class for displaying native Windows modal dialogs in Unity
using System.Windows.Forms;
// Requires System.Windows.Forms added to a Plugins folder ( C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\2.0)
// Requires .NET 2.0 (setting Player Setting -> Configuration -> Api Compatibility Level set to .NET 2.0)
// Warning! May throw windows errors in editor but works fine in builds
// Example Usage:
// WindowsNativeDialog.SimpleMessage("Hello World!");
// WindowsNativeDialog.Message("Hello World!", "Title");
// WindowsNativeDialog.WarningMessage("Hello World!", "Title");
@corycorvus
corycorvus / OculusPlatformEntitlementCheck.cs
Created October 11, 2017 06:33
Oculus Platform Entitlement Check Example
using UnityEngine;
using UnityEngine.SceneManagement;
using Oculus.Platform;
#if UNITY_4 || UNITY_5
using UnityEngine.Events;
#endif
/*
Step 1: Download & Install Oculus Platform SDK
Step 2: Update your App ID in the Editor
using UnityEngine;
using Viveport;
public class QuitGoHome
{
const int SUCCESS = 0;
private static bool isSubscriber = false;
static void Quit()
{
@corycorvus
corycorvus / DetectVR.cs
Last active May 14, 2023 08:29
Detect VR HMD and controller
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using Valve.VR;
/// <summary>
/// These are a few different ways to detect the current VR HMD and controller type.
/// - Unity XR api
/// - Unity Input api
/// - SteamVR plugin
@corycorvus
corycorvus / vive_tracker_serial.cpp
Created May 15, 2020 05:52
Get the serial number of a VIVE tracker with C++
char serialNumber[1024];
vr::VRSystem()->GetStringTrackedDeviceProperty(deviceID, vr::Prop_SerialNumber_String, serialNumber, sizeof(serialNumber));
printf("Serial Number = %s \n", serialNumber);
@corycorvus
corycorvus / steamvr_device_poweroff.cs
Last active July 16, 2021 20:01
Power off SteamVR device
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\SteamVR\\tools\\lighthouse\\bin\\win64\\lighthouse_console.exe";
process.StartInfo.Arguments = "/serial 81F6B76702 poweroff";
process.StartInfo.UseShellExecute = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.Start();
@corycorvus
corycorvus / HapticPulse.cs
Created May 19, 2020 18:46
Haptic Vibrate Controller SteamVR and Oculus
using UnityEngine;
using UnityEngine.XR;
using Valve.VR;
// simple library and examples for XR haptics
// note: controllers must be tracking to use haptics
// other examples: https://vrtoolkit.readme.io/docs/vrtk_interacthaptics
public static class HapticPulse
void EyeCalibration()
{
Debug.Log("Start Calibration");
int result = ViveSR.anipal.Eye.SRanipal_Eye_API.LaunchEyeCalibration(System.IntPtr.Zero); // Ptr not implemented so using Zero
Debug.Log("Finish Calibration: " + result);
}