Ejemplo n.º 1
0
    protected override void OnEnable()
    {
        base.OnEnable();

        EnableGaze = true;

        if (gazePointer == null)
        {
            // Set gazePointer only when null, or it will got null when WaveVR_Reticle gameObject is SetActive(false).
            if (Head == null)
            {
                Head = WaveVR_Render.Instance.gameObject;
            }
            if (Head != null)
            {
                gazePointer = Head.GetComponentInChildren <WaveVR_Reticle> ();
            }
        }

        if (gazePointer != null)
        {
            gazePointer.gameObject.SetActive(true);
            percentCanvas = gazePointer.transform.Find("PercentCanvas").gameObject;
            counterCanvas = gazePointer.transform.Find("CounterCanvas").gameObject;
        }

        sceneCanvases = GameObject.FindObjectsOfType <Canvas> ();
    }
    protected override void OnEnable()
    {
        base.OnEnable();

        EnableGaze = true;

        if (Head == null)
        {
            if (WaveVR_InputModuleManager.Instance != null)
            {
                Head = WaveVR_InputModuleManager.Instance.gameObject;
            }
            else
            {
                Head = WaveVR_Render.Instance.gameObject;
            }
        }

        if (gazePointer == null)
        {
            // Set gazePointer only when null, or it will got null when WaveVR_Reticle gameObject is SetActive(false).
            if (Head != null)
            {
                gazePointer = Head.GetComponentInChildren <WaveVR_Reticle> ();
            }
        }

        if (gazePointer != null)
        {
            if (this.UseWaveVRReticle)
            {
                PrintDebugLog("OnEnable() Head: " + Head.name + ", enable pointer, percent and counter canvas.");
                percentCanvas = gazePointer.transform.Find("PercentCanvas").gameObject;
                counterCanvas = gazePointer.transform.Find("CounterCanvas").gameObject;
                ActivateGazePointerCanvas(true);
            }
            else
            {
                ActivateGazePointerCanvas(false);
            }
        }

        sceneCanvases            = GameObject.FindObjectsOfType <Canvas> ();
        this.timerControlDefault = this.TimerControl;

        if (ringMesh == null)
        {
            if (this.Head != null)
            {
                ringMesh = this.Head.GetComponentInChildren <RingMeshDrawer> ();
                PrintDebugLog("OnEnable() found ringMesh " + (ringMesh != null ? ringMesh.gameObject.name : "null"));
            }
        }

        if (ringMesh != null)
        {
            ActivateMeshDrawer(!this.UseWaveVRReticle);
        }
    }
    private void ActivateGazePointer(bool active)
    {
        if (Gaze.Head == null)
        {
            gazePointer = null;
            gazeRing    = null;
            return;
        }
        if (gazePointer == null)
        {
            WaveVR_Reticle _wvr_reticle = Gaze.Head.GetComponentInChildren <WaveVR_Reticle> ();
            if (_wvr_reticle != null)
            {
                gazePointer = _wvr_reticle.gameObject;
            }
        }
        if (gazeRing == null)
        {
            RingMeshDrawer _ring_md = Gaze.Head.GetComponentInChildren <RingMeshDrawer> ();
            if (_ring_md != null)
            {
                gazeRing = _ring_md.gameObject;
            }
        }

        if (active)
        {
            if (Gaze.UseWaveVRReticle)
            {
                if (gazePointer != null)
                {
                    gazePointer.SetActive(true);
                }
            }
            else
            {
                if (gazeRing != null)
                {
                    gazeRing.SetActive(true);
                }
            }
        }
        else
        {
            if (gazePointer != null)
            {
                gazePointer.SetActive(false);
            }
            if (gazeRing != null)
            {
                gazeRing.SetActive(false);
            }
        }
    }
Ejemplo n.º 4
0
 private void ActivateGazePointer(bool active)
 {
     if (gazePointer == null)
     {
         gazePointer = Gaze.Head.GetComponentInChildren <WaveVR_Reticle> ();
     }
     if (gazePointer != null)
     {
         gazePointer.gameObject.SetActive(active);
     }
 }
    protected override void OnEnable()
    {
        if (!mEnabled)
        {
            base.OnEnable();

            mEnableGaze = true;

            if (this.Head == null)
            {
                if (WaveVR_InputModuleManager.Instance != null)
                {
                    // Reticle Pointer & Ring are put under InputModuleManager
                    Head = WaveVR_InputModuleManager.Instance.gameObject;
                }
                else
                {
                    Head = WaveVR_Render.Instance.gameObject;
                }
            }

            if (gazePointer == null)
            {
                // Set gazePointer only when null, or it will got null when WaveVR_Reticle gameObject is SetActive(false).
                if (Head != null)
                {
                    gazePointer = Head.GetComponentInChildren <WaveVR_Reticle> ();
                }
            }

            if (gazePointer != null)
            {
                DEBUG("OnEnable() Head: " + Head.name + ", enable pointer, percent and counter canvas.");
                percentCanvas = gazePointer.transform.Find("PercentCanvas").gameObject;
                counterCanvas = gazePointer.transform.Find("CounterCanvas").gameObject;
            }

            this.timerControlDefault = this.TimerControl;

            if (ringMesh == null)
            {
                if (this.Head != null)
                {
                    ringMesh = this.Head.GetComponentInChildren <RingMeshDrawer> ();
                    DEBUG("OnEnable() found ringMesh " + (ringMesh != null ? ringMesh.gameObject.name : "null"));
                }
            }

            mEnabled = true;
        }
    }
Ejemplo n.º 6
0
    private void UpdateReticle(GameObject preGazedObject, PointerEventData pointerEvent)
    {
        WaveVR_Reticle gazePointer = Object.FindObjectOfType <WaveVR_Reticle>();

        if (gazePointer == null)
        {
            return;
        }

        GameObject curGazeObject        = GetCurrentGameObject(pointerEvent);
        Vector3    intersectionPosition = GetIntersectionPosition(pointerEvent);
        //Ray reticle_ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        bool isInteractive = pointerEvent.pointerPress != null || ExecuteEvents.GetEventHandler <IPointerClickHandler>(curGazeObject) != null;

        if (curGazeObject == preGazedObject)
        {
            if (curGazeObject != null)
            {
                gazePointer.OnGazeStay(pointerEvent.enterEventCamera, curGazeObject, intersectionPosition, isInteractive);
            }
            else
            {
                gazePointer.OnGazeExit(pointerEvent.enterEventCamera, preGazedObject);
                return;
            }
        }
        else
        {
            if (preGazedObject != null)
            {
                gazePointer.OnGazeExit(pointerEvent.enterEventCamera, preGazedObject);
            }
            if (curGazeObject != null)
            {
                gazePointer.OnGazeEnter(pointerEvent.enterEventCamera, curGazeObject, intersectionPosition, isInteractive);
            }
        }
    }
    protected override void OnEnable()
    {
        base.OnEnable();

        EnableGaze = true;

        if (gazePointer == null)
        {
            // Set gazePointer only when null, or it will got null when WaveVR_Reticle gameObject is SetActive(false).
            if (Head == null)
            {
                if (WaveVR_InputModuleManager.Instance != null)
                {
                    Head = WaveVR_InputModuleManager.Instance.gameObject;
                }
                else
                {
                    Head = WaveVR_Render.Instance.gameObject;
                }
            }
            if (Head != null)
            {
                gazePointer = Head.GetComponentInChildren <WaveVR_Reticle> ();
            }
        }

        if (gazePointer != null)
        {
            PrintDebugLog("OnEnable() Head: " + Head.name + ", enable pointer, percent and counter canvas.");
            percentCanvas = gazePointer.transform.Find("PercentCanvas").gameObject;
            counterCanvas = gazePointer.transform.Find("CounterCanvas").gameObject;
            ActivaeGazePointerCanvas(true);
        }

        sceneCanvases        = GameObject.FindObjectsOfType <Canvas> ();
        this.defWithTimeGaze = this.WithTimeGaze;
    }
    void Start()
    {
        if (EventSystem.current == null)
        {
            EventSystem _es = FindObjectOfType <EventSystem> ();
            if (_es != null)
            {
                eventSystem = _es.gameObject;
                DEBUG("Start() find current EventSystem: " + eventSystem.name);
            }

            if (eventSystem == null)
            {
                DEBUG("Start() could not find EventSystem, create new one.");
                eventSystem = new GameObject("EventSystem", typeof(EventSystem));
            }
        }
        else
        {
            eventSystem = EventSystem.current.gameObject;
        }

        // Standalone Input Module
        StandaloneInputModule _sim = eventSystem.GetComponent <StandaloneInputModule> ();

        if (_sim != null)
        {
            _sim.enabled = false;
        }

        // Old GazeInputModule
        GazeInputModule _gim = eventSystem.GetComponent <GazeInputModule>();

        if (_gim != null)
        {
            Destroy(_gim);
        }

        // Gaze Input Module
        gazeInputModule = eventSystem.GetComponent <WaveVR_GazeInputModule> ();
        WaveVR_Reticle gazePointer = gameObject.GetComponentInChildren <WaveVR_Reticle> ();

        if (gazePointer != null)
        {
            gazePointerRenderer = gazePointer.gameObject.GetComponent <MeshRenderer> ();
            DEBUG("Start() found " + gazePointer.gameObject.name);
        }
        RingMeshDrawer ringMesh = gameObject.GetComponentInChildren <RingMeshDrawer> ();

        if (ringMesh != null)
        {
            gazeRingRenderer = ringMesh.gameObject.GetComponent <MeshRenderer> ();
            DEBUG("Start() found " + gazePointer.gameObject.name);
        }
        ActivateGazePointer(false);             // disable reticle

        // Controller Input Module
        controllerInputModule = eventSystem.GetComponent <WaveVR_ControllerInputModule> ();

        initInteractionModeAndGazeTriggerType();

        if (!this.EnableInputModule)
        {
            disableAllInputModules();
        }
    }
Ejemplo n.º 9
0
    // --------- Reticle -------- }

    private void OnTriggeGaze()
    {
        bool sendEvent = false;
        // The gameobject to which raycast positions
        var currentOverGO = pointerData.pointerCurrentRaycast.gameObject;

        // { ------- Reticle --------
        if (progressText == null)
        {
            GameObject pt = GameObject.Find("ProgressText");
            if (pt != null)
            {
                progressText = pt.GetComponent <Text>();
            }
        }
        if (counterText == null)
        {
            GameObject ct = GameObject.Find("CounterText");
            if (ct != null)
            {
                counterText = ct.GetComponent <Text>();
            }
        }
        if (gazePointer == null)
        {
            GameObject head = WaveVR_Render.Instance.gameObject;
            if (head != null)
            {
                gazePointer = head.GetComponentInChildren <WaveVR_Reticle> ();
            }
        }

        if (pointerData.pointerEnter == null && currentOverGO == null)
        {
            UpdateReticle(currentOverGO, pointerData);
            progressflag = true;
            if (progressText != null)
            {
                progressText.text = "";
            }
            if (counterText != null)
            {
                counterText.text = "";
            }
            if (gazePointer != null)
            {
                gazePointer.triggerProgressBar(false);
            }
            return;
        }

        if (!progressRate && !progressCounter)    //  if no counting, reset trigger flag
        {
            progressflag = true;
        }

        if (!progressRate || !progressCounter)    //  clear counting content
        {
            if (progressText != null && progressText.text != "")
            {
                progressText.text = "";
            }
            if (counterText != null && counterText.text != "")
            {
                counterText.text = "";
            }
        }
        // --------- Reticle -------- }

        if (pointerData.pointerEnter != currentOverGO)
        {
            #if UNITY_EDITOR
            Debug.Log("pointerEnter: " + pointerData.pointerEnter + ", currentOverGO: " + currentOverGO);
            #endif
            //HandlePointerExitAndEnter (pointerData, currentOverGO);
            if (pointerData.pointerEnter != null)
            {
                ExecuteEvents.ExecuteHierarchy(pointerData.pointerEnter, pointerData, ExecuteEvents.pointerExitHandler);
                pointerData.pointerEnter = null;
            }
            ExecuteEvents.ExecuteHierarchy(currentOverGO, pointerData, ExecuteEvents.pointerEnterHandler);
            pointerData.pointerEnter = currentOverGO;

            gazeTime = Time.unscaledTime;

            // { ------- Reticle --------
            countingTime = Time.unscaledTime;
            UpdateReticle(currentOverGO, pointerData);
            // --------- Reticle -------- }
        }
        else
        {
            // { ------- Reticle --------
            if (progressflag)     // begin to count, do initialization
            {
                if (gazePointer != null)
                {
                    gazePointer.triggerProgressBar(true);
                }
                if (progressRate && progressText != null)
                {
                    progressText.text = "0%";
                }
                if (progressCounter && counterText != null)
                {
                    counterText.text = TimeToGaze.ToString();
                }
                countingTime = Time.unscaledTime;
                progressflag = false;  // counting the rate of waiting for clicking event
            }
            // --------- Reticle -------- }

            float elapsedTime = Time.unscaledTime;
            if (elapsedTime - gazeTime > TimeToGaze)
            {
                #if UNITY_EDITOR
                //Debug.Log ("Selected: {" + currentOverGO.name + "} over " + TimeToGaze + " seconds.");
                #endif
                sendEvent = true;
                gazeTime  = Time.unscaledTime;

                // { ------- Reticle --------
                if (progressRate)
                {
                    if (progressText != null)
                    {
                        progressText.text = "";
                    }
                }
                if (progressCounter)
                {
                    if (counterText != null)
                    {
                        counterText.text = "";
                    }
                }
                if (gazePointer != null)
                {
                    gazePointer.triggerProgressBar(false);
                }
                progressflag = true;   // reset trigger flag after each counting is done
            }
            else
            {
                float rate = ((Time.unscaledTime - gazeTime) / TimeToGaze) * 100;
                if (gazePointer != null)
                {
                    gazePointer.setProgressBarTime(rate);
                }
                if (progressRate)
                {
                    if (progressText != null)
                    {
                        progressText.text = Mathf.Floor(rate) + "%";
                    }
                }
                if (progressCounter)
                {
                    if (counterText != null)
                    {
                        counterText.text = System.Math.Round(TimeToGaze - (Time.unscaledTime - countingTime), 2).ToString();
                    }
                }
                // --------- Reticle -------- }
            }
        }

        // Standalone Input Module information
        pointerData.delta    = Vector2.zero;
        pointerData.dragging = false;

        DeselectIfSelectionChanged(currentOverGO, pointerData);

        if (sendEvent)
        {
            if (InputEvent == EGazeInputEvent.PointerClick)
            {
                ExecuteEvents.ExecuteHierarchy(currentOverGO, pointerData, ExecuteEvents.pointerClickHandler);
                pointerData.clickTime = Time.unscaledTime;
            }
            else if (InputEvent == EGazeInputEvent.PointerDown)
            {
                // like "mouse" action, press->release soon, do NOT keep the pointerPressRaycast cause do NOT need to controll "down" object while not gazing.
                pointerData.pressPosition       = pointerData.position;
                pointerData.pointerPressRaycast = pointerData.pointerCurrentRaycast;

                var _pointerDownGO = ExecuteEvents.ExecuteHierarchy(currentOverGO, pointerData, ExecuteEvents.pointerDownHandler);
                ExecuteEvents.ExecuteHierarchy(_pointerDownGO, pointerData, ExecuteEvents.pointerUpHandler);
            }
            else if (InputEvent == EGazeInputEvent.PointerSubmit)
            {
                ExecuteEvents.ExecuteHierarchy(currentOverGO, pointerData, ExecuteEvents.submitHandler);
            }
        }
    }