void OnDestroy()
        {
            if (!Application.isPlaying)
            {
                return;
            }
            if (!Core.Initialized)
            {
                return;
            }
#if CVR_STEAMVR
            SteamVR_TrackedController controller;
            for (int i = 0; i < 2; i++)
            {
                bool right = i == 0 ? true : false;
                if (CognitiveVR_Manager.GetController(right) == null)
                {
                    continue;
                }
                controller = CognitiveVR_Manager.GetController(right).GetComponent <SteamVR_TrackedController>();

                if (controller == null)
                {
                    continue;
                }

                controller.TriggerClicked   -= new ClickedEventHandler(OnTriggerClicked);
                controller.TriggerUnclicked -= new ClickedEventHandler(OnTriggerUnclicked);
                controller.Gripped          -= new ClickedEventHandler(OnGripped);
                controller.Ungripped        -= new ClickedEventHandler(OnUngripped);
                controller.PadClicked       -= new ClickedEventHandler(OnPadClicked);
            }
#endif
        }
        public override void CognitiveVR_Init(Error initError)
        {
            base.CognitiveVR_Init(initError);

            SteamVR_TrackedController controller;

            for (int i = 0; i < 2; i++)
            {
                bool right = i == 0 ? true : false;
                if (CognitiveVR_Manager.GetController(right) == null)
                {
                    continue;
                }
                controller = CognitiveVR_Manager.GetController(right).GetComponent <SteamVR_TrackedController>();

                if (controller == null)
                {
                    controller = CognitiveVR_Manager.GetController(right).gameObject.AddComponent <SteamVR_TrackedController>();
                }

                controller.TriggerClicked   += new ClickedEventHandler(OnTriggerClicked);
                controller.TriggerUnclicked += new ClickedEventHandler(OnTriggerUnclicked);
                controller.Gripped          += new ClickedEventHandler(OnGripped);
                controller.Ungripped        += new ClickedEventHandler(OnUngripped);
                controller.PadClicked       += new ClickedEventHandler(OnPadClicked);
            }
        }
Ejemplo n.º 3
0
        private void CognitiveVR_Manager_OnTick()
        {
            bool hit;

#if CVR_STEAMVR
            if (CognitiveVR_Manager.GetController(false) != null)
#endif
            {
                Vector3 pos = CognitiveVR_Manager.GetControllerPosition(false);

                hit = Physics.CheckSphere(pos, 0.1f, CollisionLayerMask);
                if (hit && string.IsNullOrEmpty(controller0GUID))
                {
                    Util.logDebug("controller collision");
                    controller0GUID = Util.GetUniqueId();
                    new CustomEvent("cvr.collision").SetProperty("device", "left controller").SetProperty("state", "begin").Send();
                }
                else if (!hit && !string.IsNullOrEmpty(controller0GUID))
                {
                    new CustomEvent("cvr.collision").SetProperty("device", "left controller").SetProperty("state", "end").Send();
                    controller0GUID = string.Empty;
                }
            }


#if CVR_STEAMVR
            if (CognitiveVR_Manager.GetController(true) != null)
#endif
            {
                Vector3 pos = CognitiveVR_Manager.GetControllerPosition(true);

                hit = Physics.CheckSphere(pos, 0.1f, CollisionLayerMask);
                if (hit && string.IsNullOrEmpty(controller1GUID))
                {
                    Util.logDebug("controller collision");
                    controller1GUID = Util.GetUniqueId();
                    new CustomEvent("cvr.collision").SetProperty("device", "right controller").SetProperty("state", "begin").Send();
                }
                else if (!hit && !string.IsNullOrEmpty(controller1GUID))
                {
                    new CustomEvent("cvr.collision").SetProperty("device", "right controller").SetProperty("state", "end").Send();
                    controller1GUID = string.Empty;
                }
            }
        }
Ejemplo n.º 4
0
        private void CognitiveVR_Manager_OnTick()
        {
            if (CognitiveVR_Manager.GetController(0) == null)
            {
                return;
            }

            if (samples < SampleCount)
            {
                maxSqrDistance = Mathf.Max(Vector3.SqrMagnitude(CognitiveVR_Manager.GetController(0).position - CognitiveVR_Manager.HMD.position));

                samples++;
                if (samples >= SampleCount)
                {
                    Util.logDebug("arm length " + maxSqrDistance);
                    CognitiveVR_Manager.UpdateSessionState(new Dictionary <string, object> {
                        { "cvr.armlength", Mathf.Sqrt(maxSqrDistance) }
                    });
                    //Instrumentation.updateUserState(new Dictionary<string, object> { { "armlength", Mathf.Sqrt(maxSqrDistance) } });
                    CognitiveVR_Manager.TickEvent -= CognitiveVR_Manager_OnTick;
                }
            }
        }