- Home /
how to Reverse VR gaze fill image HandleOut exit?
I'm using VR sample button input for the image fill but what i'm trying to achieve is after on handle out the fill bar reverse back to 0 with animation instead of resetting to 0 immediately without animation. Any help on making it possible will do I'm kinda new to Unity As well. Cheers for the help
public IEnumerator WaitForBarToFill ()
{
// If the bar should disappear when it's filled, it needs to be visible now.
if (m_BarCanvas && m_DisappearOnBarFill)
m_BarCanvas.SetActive(true);
// Currently the bar is unfilled.
m_BarFilled = false;
// Reset the timer and set the slider value as such.
m_Timer = 0f;
SetSliderValue (0f);
// Keep coming back each frame until the bar is filled.
while (!m_BarFilled)
{
yield return null;
}
// If the bar should disappear once it's filled, turn it off.
if (m_BarCanvas && m_DisappearOnBarFill)
m_BarCanvas.SetActive(false);
}
private IEnumerator FillBar ()
{
// When the bar starts to fill, reset the timer.
m_Timer = 0f;
// The amount of time it takes to fill is either the duration set in the inspector, or the duration of the radial.
float fillTime = m_SelectionRadial != null ? m_SelectionRadial.SelectionDuration : m_Duration;
// Until the timer is greater than the fill time...
while (m_Timer < fillTime)
{
// ... add to the timer the difference between frames.
m_Timer += Time.deltaTime;
// Set the value of the slider or the UV based on the normalised time.
SetSliderValue(m_Timer / fillTime);
// Wait until next frame.
yield return null;
// If the user is still looking at the bar, go on to the next iteration of the loop.
if (m_GazeOver)
continue;
// If the user is no longer looking at the bar, reset the timer and bar and leave the function.
m_Timer = 0f;
SetSliderValue (0f);
yield break;
}
// If the loop has finished the bar is now full.
m_BarFilled = true;
// If anything has subscribed to OnBarFilled call it now.
if (OnBarFilled != null)
OnBarFilled ();
// Play the clip for when the bar is filled.
m_Audio.clip = m_OnFilledClip;
m_Audio.Play();
// Wait for the screen to fade out.
StartCoroutine (FadeToMenu ());
// If the bar should be disabled once it is filled, do so now.
if (m_DisableOnBarFill)
enabled = false;
}
private IEnumerator FadeToMenu ()
{
// Wait for the screen to fade out.
yield return StartCoroutine (m_VRCameraFade.BeginFadeOut (true));
// Load the main menu by itself.
Application.LoadLevel ("exterior");
}
private void SetSliderValue (float sliderValue)
{
// If there is a slider component set it's value to the given slider value.
if (m_Slider)
m_Slider.value = sliderValue;
// If there is a renderer set the shader's property to the given slider value.
if(m_Renderer)
m_Renderer.sharedMaterial.SetFloat (k_SliderMaterialPropertyName, sliderValue);
}
private void HandleDown ()
{
// If the user is looking at the bar start the FillBar coroutine and store a reference to it.
if (m_GazeOver)
m_FillBarRoutine = StartCoroutine(FillBar());
m_Timer = 2f;
}
private void HandleUp ()
{
// If the coroutine has been started (and thus we have a reference to it) stop it.
if(m_FillBarRoutine != null)
StopCoroutine (m_FillBarRoutine);
// Reset the timer and bar values.
m_Timer = 0f;
SetSliderValue(0f);
}
private void HandleOver ()
{
// The user is now looking at the bar.
m_GazeOver = true;
// Play the clip appropriate for when the user starts looking at the bar.
m_Audio.clip = m_OnOverClip;
m_Audio.Play();
//m_text.SetActive(true);
m_FillBarRoutine = StartCoroutine(FillBar());
//HandleDown(); // Here autoclick
}
private void HandleOut ()
{
// The user is no longer looking at the bar.
m_GazeOver = false;
//m_text.SetActive(false);
// If the coroutine has been started (and thus we have a reference to it) stop it.
if (m_FillBarRoutine != null)
StopCoroutine(m_FillBarRoutine);
// Reset the timer and bar values.
m_Timer = 0f;
SetSliderValue(0f);
}
}
Comment