Exemplo n.º 1
0
        public void Initialize(string userName = "", Dictionary <string, object> userProperties = null)
        {
            Util.logDebug("CognitiveVR_Manager Initialize");
            if (instance != null && instance != this)
            {
                Util.logDebug("CognitiveVR_Manager Initialize instance is not null and not this! Destroy");
                Destroy(gameObject);
                return;
            } //destroy if there's already another manager
            if (instance == this && Core.Initialized)
            {
                Util.logDebug("CognitiveVR_Manager Initialize instance is this! <color=red>Skip Initialize</color>");
                return;
            } //skip if this manage has already been initialized

            if (!CognitiveVR_Preferences.Instance.IsAPIKeyValid)
            {
                Util.logDebug("CognitiveVR_Manager Initialize does not have valid apikey");
                return;
            }
            if (OutstandingInitRequest)
            {
                Util.logDebug("CognitiveVR_Manager Initialize already called. Waiting for response");
                return;
            }

            OutstandingInitRequest = true;

            //string sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;

            //Core.SetTrackingScene(sceneName);

            Instrumentation.SetMaxTransactions(CognitiveVR_Preferences.S_TransactionSnapshotCount);

            playerSnapshotInverval = new WaitForSeconds(CognitiveVR.CognitiveVR_Preferences.S_SnapshotInterval);
            GPSUpdateInverval      = new WaitForSeconds(CognitiveVR_Preferences.Instance.GPSInterval);
            StartCoroutine(Tick());

#if CVR_STEAMVR
            SteamVR_Events.NewPoses.AddListener(OnPoseUpdate); //steamvr 1.2
            //SteamVR_Utils.Event.Listen("new_poses", OnPoseUpdate); //steamvr 1.1
#endif

            UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneManager_SceneLoaded;
            SceneManager_SceneLoaded(UnityEngine.SceneManagement.SceneManager.GetActiveScene(), UnityEngine.SceneManagement.LoadSceneMode.Single);

            Core.UserId = userName;

            CognitiveVR.Core.init(OnInit); //TODO return errors from init method, not callback since there isn't a delay on startup
            UpdateSessionState(Util.GetDeviceProperties() as Dictionary <string, object>);

#if UNITY_2017_2_OR_NEWER
            UpdateSessionState("cvr.vr.enabled", UnityEngine.XR.XRSettings.enabled);
            UpdateSessionState("cvr.vr.display.model", UnityEngine.XR.XRSettings.enabled && UnityEngine.XR.XRDevice.isPresent ? UnityEngine.XR.XRDevice.model : "Not Found");               //vive mvt, vive. mv, oculus rift cv1, acer ah100
            UpdateSessionState("cvr.vr.display.family", UnityEngine.XR.XRSettings.enabled && UnityEngine.XR.XRDevice.isPresent ? UnityEngine.XR.XRSettings.loadedDeviceName : "Not Found"); //openvr, oculus, windowsmr
#else
            UpdateSessionState("cvr.vr.enabled", UnityEngine.VR.VRSettings.enabled);
            UpdateSessionState("cvr.vr.display.model", UnityEngine.VR.VRSettings.enabled && UnityEngine.VR.VRDevice.isPresent ? UnityEngine.VR.VRDevice.model : "Not Found");
            UpdateSessionState("cvr.vr.display.family", UnityEngine.VR.VRSettings.enabled && UnityEngine.VR.VRDevice.isPresent ? UnityEngine.VR.VRSettings.loadedDeviceName : "Not Found");
#endif


            UpdateSessionState("cvr.deviceId", Core.DeviceId);
            UpdateSessionState(userProperties);
            UpdateSessionState("cvr.name", userName);

            CognitiveVR.NetworkManager.InitLocalStorage(System.Environment.NewLine);
        }