Exemplo n.º 1
0
        public static void Stop()
        {
            if (!IsRunning)
            {
                return;
            }

            Internal.G2OM.Destroy();
            Internal.Provider.Destroy();

            if (_updaterGameObject != null)
            {
#if UNITY_EDITOR
                if (Application.isPlaying)
                {
                    Object.Destroy(_updaterGameObject.gameObject);
                }
                else
                {
                    Object.DestroyImmediate(_updaterGameObject.gameObject);
                }
#else
                Object.Destroy(_updaterGameObject.gameObject);
#endif
            }


            _updaterGameObject = null;
            _advanced          = null;
            Internal.G2OM      = null;
            Internal.Provider  = null;
        }
Exemplo n.º 2
0
        public static bool Start(TobiiXR_Settings settings = null)
        {
            if (IsRunning)
            {
                Stop();
            }

            if (!TobiiEula.IsEulaAccepted())
            {
                Debug.LogWarning(
                    "You need to accept Tobii Software Development License Agreement to use Tobii XR Unity SDK.");
            }

            // Create default settings if none were provided
            if (settings == null)
            {
                settings = new TobiiXR_Settings();
            }
            Internal.Settings = settings;

            // Setup eye tracking provider
            if (settings.AdvancedEnabled)
            {
                Debug.Log("Advanced eye tracking enabled so TobiiXR will use Tobii provider for eye tracking.");
                var licenseKey = settings.OcumenLicense;
                if (string.IsNullOrEmpty(licenseKey))
                {
                    var licenseResource = Resources.Load("TobiiOcumenLicense") as TextAsset;
                    if (licenseResource != null)
                    {
                        licenseKey = Encoding.Unicode.GetString(licenseResource.bytes);
                    }
                    else
                    {
                        throw new System.Exception("An Ocumen license is required to use the advanced API. Read more about Ocumen here: https://vr.tobii.com/sdk//technology/tobii-ocumen/");
                    }
                }

                var provider = new TobiiProvider();
                if (!provider.InitializeAdvanced(licenseKey))
                {
                    Debug.LogError("Failed to connect to a supported eye tracker. TobiiXR will NOT be available.");
                    return(false);
                }

                if (provider.HasValidOcumenLicense)
                {
                    Debug.Log("Ocumen license valid");
                    _advanced = new TobiiXRAdvanced(provider);
                }
                else
                {
                    Debug.LogError("Ocumen license INVALID. Advanced API will NOT be available.");
                }

                Internal.Provider = provider;
            }
            else
            {
                Internal.Provider = settings.EyeTrackingProvider;

                if (Internal.Provider == null)
                {
                    Internal.Provider = new NoseDirectionProvider();
                    Debug.LogWarning(string.Format("All configured providers failed. Using ({0}) as fallback.",
                                                   Internal.Provider.GetType().Name));
                }

                Debug.Log(string.Format("Starting TobiiXR with ({0}) as provider for eye tracking.",
                                        Internal.Provider));
            }

            // Setup G2OM
            if (settings.G2OM != null)
            {
                Internal.G2OM = settings.G2OM;
            }
            else
            {
                Internal.G2OM = G2OM.Create(new G2OM_Description
                {
                    LayerMask = settings.LayerMask,
                    HowLongToKeepCandidatesInSeconds = settings.HowLongToKeepCandidatesInSeconds
                });
            }

            // Create GameObject with TobiiXR_Lifecycle to give us Unity events
            _updaterGameObject = new GameObject("TobiiXR Updater");
            var updater = _updaterGameObject.AddComponent <TobiiXR_Lifecycle>();

            updater.OnUpdateAction          += Tick;
            updater.OnDisableAction         += Internal.G2OM.Clear;
            updater.OnApplicationQuitAction += Stop;

            return(true);
        }