Ejemplo n.º 1
0
        //if the player is looking at the button, updates the fill image and calls ActivateAction if filled
        void Update()
        {
            if (GameplayReferences.HMD == null)
            {
                return;
            }
            //if (ExitPoll.CurrentExitPollSet.CurrentExitPollPanel.NextResponseTimeValid == false) { return; }
            if (_finishedRecording)
            {
                return;
            }
            //if (ExitPoll.CurrentExitPollSet.CurrentExitPollPanel.IsClosing) { return; }

            if (_recording)
            {
                _currentRecordTime -= Time.deltaTime;
                UpdateFillAmount();
                float   volumeLevel = MicrophoneUtility.LevelMax(clip);
                Vector3 newScale    = new Vector3(0.8f, 0.1f + Mathf.Clamp(volumeLevel, 0, 0.7f), 0.8f);
                MicrophoneImage.transform.localScale = Vector3.Lerp(MicrophoneImage.transform.localScale, newScale, 0.1f);

                if (_currentRecordTime <= 0)
                {
                    Microphone.End(null);
                    byte[] bytes;
                    CognitiveVR.MicrophoneUtility.Save(clip, out bytes);
                    string encodedWav = MicrophoneUtility.EncodeWav(bytes);
                    questionSet.CurrentExitPollPanel.AnswerMicrophone(encodedWav); //TODO need some method of accessing question set on this component - probably pass in at start
                    _finishedRecording = true;
                }
            }
        }
Ejemplo n.º 2
0
        //if the player is looking at the button, updates the fill image and calls ActivateAction if filled
        void Update()
        {
            if (CognitiveVR_Manager.HMD == null)
            {
                return;
            }
            if (ExitPoll.CurrentExitPollSet.CurrentExitPollPanel.NextResponseTimeValid == false)
            {
                return;
            }
            if (_finishedRecording)
            {
                return;
            }
            if (ExitPoll.CurrentExitPollSet.CurrentExitPollPanel.IsClosing)
            {
                return;
            }

            if (_recording)
            {
                _currentRecordTime -= Time.deltaTime;
                UpdateFillAmount();
                float   volumeLevel = MicrophoneUtility.LevelMax(clip);
                Vector3 newScale    = new Vector3(0.8f, 0.1f + Mathf.Clamp(volumeLevel, 0, 0.7f), 0.8f);
                MicrophoneImage.transform.localScale = Vector3.Lerp(MicrophoneImage.transform.localScale, newScale, 0.1f);

                if (_currentRecordTime <= 0)
                {
                    Microphone.End(null);
                    byte[] bytes;
                    CognitiveVR.MicrophoneUtility.Save(clip, out bytes);
                    string encodedWav = MicrophoneUtility.EncodeWav(bytes);
                    ExitPoll.CurrentExitPollSet.CurrentExitPollPanel.AnswerMicrophone(encodedWav);
                    _finishedRecording = true;
                }
            }
            else
            {
                if (pointer == null)
                {
                    //use hmd
                    if (CognitiveVR_Manager.HMD == null)
                    {
                        return;
                    }

                    if (Vector3.Dot(GetHMDForward(), (_transform.position - CognitiveVR_Manager.HMD.position).normalized) > _theta)
                    {
                        _currentLookTime += Time.deltaTime;
                        UpdateFillAmount();

                        //maybe also scale button slightly if it has focus

                        if (_currentLookTime >= LookTime)
                        {
                            RecorderActivate();
                        }
                    }
                    else if (_currentLookTime > 0)
                    {
                        _currentLookTime = 0;
                        UpdateFillAmount();
                    }
                }
                else //use pointer
                {
                    var tt = Vector3.Dot(pointer.transform.forward, (_transform.position - pointer.transform.position).normalized);
                    if (tt > _theta) //pointing at the button
                    {
                        pointer.Target    = transform;
                        _currentLookTime += Time.deltaTime;
                        UpdateFillAmount();

                        if (_currentLookTime >= LookTime)
                        {
                            RecorderActivate();
                        }
                    }
                    else if (tt < _theta * pointer.Stiffness && pointer.Target == transform) //bendy line pointing too far away from button
                    {
                        pointer.Target = null;
                    }
                    else if (pointer.Target != transform) //selection is not this
                    {
                        if (_currentLookTime > 0)
                        {
                            _currentLookTime = 0;
                            UpdateFillAmount();
                        }
                    }
                    else //pointing nearby button
                    {
                        _currentLookTime += Time.deltaTime;
                        UpdateFillAmount();

                        if (_currentLookTime >= LookTime)
                        {
                            RecorderActivate();
                        }
                    }
                }
            }
        }