// Base Headset|SDK_Base|005
namespace VRTK
{
using UnityEngine;
using System.Collections.Generic;
#if UNITY_2017_2_OR_NEWER
using UnityEngine.XR;
#else
using XRDevice = UnityEngine.VR.VRDevice;
using XRSettings = UnityEngine.VR.VRSettings;
#endif
///
/// The Base Headset SDK script provides a bridge to SDK methods that deal with the VR Headset.
///
///
/// This is an abstract class to implement the interface required by all implemented SDKs.
///
public abstract class SDK_BaseHeadset : SDK_Base
{
///
/// The connected headset type
///
public enum HeadsetType
{
///
/// The headset connected is unknown.
///
Undefined,
///
/// The headset associated with the simulator.
///
Simulator,
///
/// The HTC Vive headset.
///
HTCVive,
///
/// The Oculus Rift DK1 headset.
///
OculusRiftDK1,
///
/// The Oculus Rift DK2 headset.
///
OculusRiftDK2,
///
/// The Oculus Rift headset.
///
OculusRift,
///
/// The Oculus GearVR headset.
///
OculusGearVR,
///
/// The Google Daydream headset.
///
GoogleDaydream,
///
/// The Google Cardboard headset.
///
GoogleCardboard,
///
/// The HyperealVR headset.
///
HyperealVR,
///
/// The Windows Mixed Reality headset.
///
WindowsMixedReality
}
protected Transform cachedHeadset;
protected Transform cachedHeadsetCamera;
///
/// The ProcessUpdate method enables an SDK to run logic for every Unity Update
///
/// A dictionary of generic options that can be used to within the update.
public abstract void ProcessUpdate(Dictionary options);
///
/// The ProcessFixedUpdate method enables an SDK to run logic for every Unity FixedUpdate
///
/// A dictionary of generic options that can be used to within the fixed update.
public abstract void ProcessFixedUpdate(Dictionary options);
///
/// The GetHeadset method returns the Transform of the object that is used to represent the headset in the scene.
///
/// A transform of the object representing the headset in the scene.
public abstract Transform GetHeadset();
///
/// The GetHeadsetCamera method returns the Transform of the object that is used to hold the headset camera in the scene.
///
/// A transform of the object holding the headset camera in the scene.
public abstract Transform GetHeadsetCamera();
///
/// The GetHeadsetType method returns a string representing the type of headset connected.
///
/// The string of the headset connected.
public abstract string GetHeadsetType();
///
/// The GetHeadsetVelocity method is used to determine the current velocity of the headset.
///
/// A Vector3 containing the current velocity of the headset.
public abstract Vector3 GetHeadsetVelocity();
///
/// The GetHeadsetAngularVelocity method is used to determine the current angular velocity of the headset.
///
/// A Vector3 containing the current angular velocity of the headset.
public abstract Vector3 GetHeadsetAngularVelocity();
///
/// The HeadsetFade method is used to apply a fade to the headset camera to progressively change the colour.
///
/// The colour to fade to.
/// The amount of time the fade should take to reach the given colour.
/// Determines whether to use an overlay on the fade.
public abstract void HeadsetFade(Color color, float duration, bool fadeOverlay = false);
///
/// The HasHeadsetFade method checks to see if the given game object (usually the camera) has the ability to fade the viewpoint.
///
/// The Transform to check to see if a camera fade is available on.
/// Returns true if the headset has fade functionality on it.
public abstract bool HasHeadsetFade(Transform obj);
///
/// The AddHeadsetFade method attempts to add the fade functionality to the game object with the camera on it.
///
/// The Transform to with the camera on to add the fade functionality to.
public abstract void AddHeadsetFade(Transform camera);
protected Transform GetSDKManagerHeadset()
{
VRTK_SDKManager sdkManager = VRTK_SDKManager.instance;
if (sdkManager != null && sdkManager.loadedSetup != null && sdkManager.loadedSetup.actualHeadset != null)
{
cachedHeadset = (sdkManager.loadedSetup.actualHeadset ? sdkManager.loadedSetup.actualHeadset.transform : null);
return cachedHeadset;
}
return null;
}
protected virtual string ScrapeHeadsetType()
{
string model = CleanPropertyString(XRDevice.model);
string deviceName = CleanPropertyString(XRSettings.loadedDeviceName);
switch (model)
{
case "oculusriftcv1":
case "oculusriftes07":
return CleanPropertyString("oculusrift");
case "vivemv":
case "vivedvt":
return CleanPropertyString("htcvive");
case "googleinc-daydreamview":
return "googledaydream";
case "googleinc-defaultcardboard":
return "googlecardboard";
case "galaxynote5":
case "galaxys6":
case "galaxys6edge":
case "galaxys7":
case "galaxys7edge":
case "galaxys8":
case "galaxys8+":
if (deviceName == "oculus")
{
return "oculusgearvr";
}
break;
case "oculusriftdk1":
return CleanPropertyString("oculusriftdk1");
case "oculusriftdk2":
return CleanPropertyString("oculusriftdk2");
case "acermixedreality":
return CleanPropertyString("windowsmixedreality");
}
return "";
}
protected string CleanPropertyString(string inputString)
{
return inputString.Replace(" ", "").Replace(".", "").Replace(",", "").ToLowerInvariant();
}
}
}