07-15-2016 10:45 AM
Solved! Go to Solution.
07-15-2016 01:25 PM
using UnityEngine;
using System.Collections;
public class OVRVolumeControl : MonoBehaviour
{
private const float showPopupTime = 3;
private const float popupOffsetY = 64.0f / 500.0f;
private const float popupDepth = 1.8f;
private const int maxVolume = 15;
private const int numVolumeImages = maxVolume + 1;
private Transform myTransform = null;
private float LastVolumeInput;
private float TempVolumeInput;
private float TimeToCheck = 0.0f;
void Start()
{
DontDestroyOnLoad( gameObject );
myTransform = transform;
GetComponent<Renderer>().enabled = false;
LastVolumeInput = OVRManager.volumeLevel;
}
void Update()
{
UpdatePosition(Camera.main.transform);
}
/// <summary>
/// Updates the position of the volume popup.
/// </summary>
public void UpdatePosition(Transform cameraTransform)
{
// OVRManager.volumeLevel returns a negative value in GearVR/Unity until the button is hit at least once.
float check = OVRManager.volumeLevel;
if ((check < 0f) || (check == LastVolumeInput)) // we haven't gotten a volume button check yet.
{
TimeToCheck = 0f;
}
else
{
LastVolumeInput = -10; // there was a change, let this play out.
if (TempVolumeInput != check)
TimeToCheck = 0.0f;
TempVolumeInput = check;
// Volume has changed...
TimeToCheck += Time.deltaTime;
if ((TimeToCheck < showPopupTime)) // for the next three seconds ....
{
GetComponent<Renderer>().enabled = true;
GetComponent<Renderer>().material.mainTextureOffset = new Vector2(0.0f, (float)(maxVolume - (OVRManager.volumeLevel*maxVolume) ) / (float)numVolumeImages);
if (myTransform != null && cameraTransform != null)
{
// place in front of camera
myTransform.rotation = cameraTransform.rotation;
myTransform.position = cameraTransform.position + (myTransform.forward * popupDepth) + (myTransform.up * popupOffsetY);
}
}
else
{
// 3 seconds have passed...
TimeToCheck = 0.0f;
LastVolumeInput = check;
GetComponent<Renderer>().enabled = false;
}
}
}
}
07-15-2016 01:29 PM
if (volumeController != null)became
{
if (volumeControllerTransform == null)
{
if (gameObject.GetComponent<OVRCameraRig>() != null)
{
volumeControllerTransform = gameObject.GetComponent<OVRCameraRig>().centerEyeAnchor;
}
}
volumeController.UpdatePosition(volumeControllerTransform);
}
if (volumeController != null)
{
if (volumeControllerTransform == null)
{
volumeControllerTransform = gameObject.transform;
}
volumeController.UpdatePosition(volumeControllerTransform);
}
And now it's working.
07-15-2016 03:00 PM
07-15-2016 10:47 AM
07-15-2016 12:03 PM
07-15-2016 12:05 PM
07-15-2016 12:07 PM
ProfessorTroy said:Do you have a volume slider bar functional in your project?
07-15-2016 12:09 PM
07-15-2016 12:16 PM
07-15-2016 12:27 PM
ProfessorTroy said:
When you say "The Volume Buttons" work, do you mean ones you added yourself, or the ones you access via the settings menu by holding the back button??
07-15-2016 12:28 PM
07-15-2016 12:55 PM