86 lines
2.9 KiB
C#
86 lines
2.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.XR;
|
|
|
|
namespace Omni
|
|
{
|
|
public class OmniSetupComponent
|
|
{
|
|
protected bool hasFullyInitialized = false;
|
|
protected bool hasCalibrated = false;
|
|
|
|
OmniManager omniManager;
|
|
OmniConnectionComponent omniConnectionComponent;
|
|
OmniDataComponent omniDataComponent;
|
|
|
|
public void Setup(OmniManager manager, OmniConnectionComponent connectionComponent, OmniDataComponent dataComponent)
|
|
{
|
|
Debug.Log(System.DateTime.Now.ToLongTimeString() + ": OmniSetupComponent- Omni/SecureOmni SDK Version 2.3");
|
|
|
|
omniManager = manager;
|
|
omniConnectionComponent = connectionComponent;
|
|
omniDataComponent = dataComponent;
|
|
}
|
|
|
|
public void StopOmni()
|
|
{
|
|
if (omniManager != null)
|
|
{
|
|
omniManager.Cleanup();
|
|
omniManager = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calibration Function. Sets up proper alignment between Omni and HMD based on Omni input data and HMD orientation.
|
|
/// </summary>
|
|
public virtual void CalibrateOmni(Transform cameraReference)
|
|
{
|
|
if (hasCalibrated || omniDataComponent.IsMotionDataUnknown()) return;
|
|
|
|
//set offset to be current ring angle
|
|
if ((cameraReference.transform.position.x != 0) && (cameraReference.transform.position.y != 0) && (cameraReference.transform.position.z != 0) &&
|
|
(cameraReference.rotation.eulerAngles.x != 0) && (cameraReference.rotation.eulerAngles.y != 0) && (cameraReference.rotation.eulerAngles.z != 0))
|
|
{
|
|
if (omniConnectionComponent.GetSAPStatus() == SecureAuthenticationProtocolState.SAPEnabled)
|
|
{
|
|
omniDataComponent.omniOffset = OmniMovementCalibration.GetCalibrationValue();
|
|
}
|
|
else
|
|
{
|
|
omniDataComponent.omniOffset = OmniMovementCalibration.GetCalibrationValue();
|
|
}
|
|
hasCalibrated = true;
|
|
Debug.Log(System.DateTime.Now.ToLongTimeString() + ": OmniSetupComponent(CalibrateOmni) - Successfully calibrated Omni.");
|
|
}
|
|
if (!hasFullyInitialized)
|
|
{
|
|
//grab initial step count here
|
|
omniDataComponent.ResetStepCount();
|
|
hasFullyInitialized = true;
|
|
}
|
|
|
|
}
|
|
|
|
public bool IsPresent()
|
|
{
|
|
var xrDisplay = new List<XRDisplaySubsystem>();
|
|
SubsystemManager.GetInstances<XRDisplaySubsystem>(xrDisplay);
|
|
foreach (var xrD in xrDisplay)
|
|
{
|
|
if (xrD.running)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool IsInitialized()
|
|
{
|
|
return hasFullyInitialized;
|
|
}
|
|
}
|
|
}
|