Hi there,
I’m hoping I can solve this myself, but on the off chance there’s somebody out there with the free time and patience to assist, I’m trying to drive a video playback seek bar by VRInput Swipe direction.
The basic idea is that, rather than using drag inputs (as this doesn’t work for Gear VR and cardboard) to update the position of the slider and therefore change the timestamp of the video, I’ll instead use swipe direction to change the position of playback by a predefined float value (m_fSwipeValue).
I began with a basic SeekBarCtrl script which comes with the Easy Movie Texture asset package, and added my own elements to this. I’m not receiving any errors in Unity, but swipe events just aren’t doing anything.
using System;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using VRStandardAssets.Utils;
#if !UNITY_WEBGL
public class VRSeekBarCtrl : MonoBehaviour ,IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, IDragHandler{
public VRInput m_VRInput;
public MediaPlayerCtrl m_srcVideo;
public Slider m_srcSlider;
public float m_fDragTime = 0.2f;
public float m_fSwipeValue = 0.05f;
bool m_bActiveDrag = true;
bool m_bUpdate = true;
float m_fDeltaTime = 0.0f;
float m_fLastValue = 0.0f;
float m_fLastSetValue = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (m_bActiveDrag == false) {
m_fDeltaTime += Time.deltaTime;
if (m_fDeltaTime > m_fDragTime) {
m_bActiveDrag = true;
m_fDeltaTime = 0.0f;
//if(m_fLastSetValue != m_fLastValue)
// m_srcVideo.SetSeekBarValue (m_fLastValue);
}
}
if (m_bUpdate == false)
return;
if (m_srcVideo != null) {
if (m_srcSlider != null) {
m_srcSlider.value = m_srcVideo.GetSeekBarValue();
}
}
m_VRInput.DetectSwipe ();
}
public void OnPointerEnter(PointerEventData eventData)
{
Debug.Log("OnPointerEnter:");
m_bUpdate = false;
}
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("OnPointerExit:");
m_bUpdate = true;
}
public void OnPointerDown(PointerEventData eventData)
{
}
public void OnPointerUp(PointerEventData eventData)
{
m_srcVideo.SetSeekBarValue (m_srcSlider.value);
}
public void OnDrag(PointerEventData eventData)
{
Debug.Log("OnDrag:"+ eventData);
if (m_bActiveDrag == false)
{
m_fLastValue = m_srcSlider.value;
return;
}
m_srcVideo.SetSeekBarValue (m_srcSlider.value);
m_fLastSetValue = m_srcSlider.value;
m_bActiveDrag = false;
}
public void DetectSwipe(){
//mouse moves left
if (m_VRInput.DetectSwipe() == VRInput.SwipeDirection.LEFT){
m_srcSlider.value = m_fLastValue - m_fSwipeValue;
m_srcVideo.SetSeekBarValue (m_srcSlider.value);
m_fLastSetValue = m_srcSlider.value;
}
if (m_VRInput.DetectSwipe () == VRInput.SwipeDirection.RIGHT) {
m_srcSlider.value = m_fLastValue + m_fSwipeValue;
m_srcVideo.SetSeekBarValue (m_srcSlider.value);
m_fLastSetValue = m_srcSlider.value;
}
}
}
#endif
And I expect I will get a response of ‘learn the basics’ first or ‘read documentation’, so just to clear that up, I’ve been referring to Google searches and documentation extensively for a couple days before posting this question, and unfortunately I’m the type of ‘learn by doing’ type of person, and there are no related walkthrough tutorials that I’ve found.
Thanks in advance
Laurence