Added VR libraries
This commit is contained in:
34
Assets/GoogleVR/Demos/Scripts/VideoDemo/AppButtonInput.cs
Normal file
34
Assets/GoogleVR/Demos/Scripts/VideoDemo/AppButtonInput.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2016 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
namespace GoogleVR.VideoDemo {
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Provides controller app button input through UnityEvents.
|
||||
/// </summary>
|
||||
public class AppButtonInput : MonoBehaviour {
|
||||
public ButtonEvent OnAppUp;
|
||||
public ButtonEvent OnAppDown;
|
||||
|
||||
void Update() {
|
||||
if (Gvr.Internal.ControllerUtils.AnyButtonUp(GvrControllerButton.App))
|
||||
OnAppUp.Invoke();
|
||||
|
||||
if (Gvr.Internal.ControllerUtils.AnyButtonDown(GvrControllerButton.App))
|
||||
OnAppDown.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e216f327e132794b8e02093522ae84c
|
||||
timeCreated: 1460403137
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
67
Assets/GoogleVR/Demos/Scripts/VideoDemo/AutoPlayVideo.cs
Normal file
67
Assets/GoogleVR/Demos/Scripts/VideoDemo/AutoPlayVideo.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
// <copyright file="AutoPlayVideo.cs" company="Google Inc.">
|
||||
// Copyright (C) 2016 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
namespace GoogleVR.VideoDemo {
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Auto play video.
|
||||
/// </summary>
|
||||
/// <remarks>This script exposes a delay value in seconds to start playing the TexturePlayer
|
||||
/// component on the same object.
|
||||
/// </remarks>
|
||||
|
||||
[RequireComponent(typeof(GvrVideoPlayerTexture))]
|
||||
public class AutoPlayVideo : MonoBehaviour {
|
||||
private bool done;
|
||||
private float t;
|
||||
private GvrVideoPlayerTexture player;
|
||||
|
||||
public float delay = 2f;
|
||||
public bool loop = false;
|
||||
|
||||
void Start() {
|
||||
t = 0;
|
||||
done = false;
|
||||
player = GetComponent<GvrVideoPlayerTexture>();
|
||||
if (player != null) {
|
||||
player.Init();
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if (player == null) {
|
||||
return;
|
||||
} else if (player.PlayerState == GvrVideoPlayerTexture.VideoPlayerState.Ended && done && loop) {
|
||||
player.Pause();
|
||||
player.CurrentPosition = 0;
|
||||
done = false;
|
||||
t = 0f;
|
||||
return;
|
||||
}
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
|
||||
t += Time.deltaTime;
|
||||
if (t >= delay && player != null) {
|
||||
player.Play();
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e71f5afb881f443bbce909fe451d8fe
|
||||
timeCreated: 1471303020
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/GoogleVR/Demos/Scripts/VideoDemo/InputEvents.cs
Normal file
43
Assets/GoogleVR/Demos/Scripts/VideoDemo/InputEvents.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2016 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace GoogleVR.VideoDemo {
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[Serializable]
|
||||
public class Vector3Event : UnityEvent<Vector3> { }
|
||||
|
||||
[Serializable]
|
||||
public class Vector2Event : UnityEvent<Vector2> { }
|
||||
|
||||
[Serializable]
|
||||
public class FloatEvent : UnityEvent<float> { }
|
||||
|
||||
[Serializable]
|
||||
public class BoolEvent : UnityEvent<bool> { }
|
||||
|
||||
[Serializable]
|
||||
public class ButtonEvent : UnityEvent { }
|
||||
|
||||
[Serializable]
|
||||
public class TouchPadEvent : UnityEvent { }
|
||||
|
||||
[Serializable]
|
||||
public class TransformEvent : UnityEvent<Transform> { }
|
||||
|
||||
[Serializable]
|
||||
public class GameObjectEvent : UnityEvent<GameObject> { }
|
||||
}
|
||||
12
Assets/GoogleVR/Demos/Scripts/VideoDemo/InputEvents.cs.meta
Normal file
12
Assets/GoogleVR/Demos/Scripts/VideoDemo/InputEvents.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efe7e44b35e61314983888468dcb5686
|
||||
timeCreated: 1460124774
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
66
Assets/GoogleVR/Demos/Scripts/VideoDemo/MenuHandler.cs
Normal file
66
Assets/GoogleVR/Demos/Scripts/VideoDemo/MenuHandler.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright 2016 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace GoogleVR.VideoDemo {
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class MenuHandler : MonoBehaviour {
|
||||
public GameObject[] menuObjects;
|
||||
|
||||
public void HideMenu() {
|
||||
foreach (GameObject m in menuObjects) {
|
||||
Renderer r = m.GetComponent<Renderer>();
|
||||
if (r != null) {
|
||||
r.enabled = false;
|
||||
} else {
|
||||
m.SetActive(false);
|
||||
}
|
||||
StartCoroutine(DoFade());
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowMenu() {
|
||||
foreach (GameObject m in menuObjects) {
|
||||
Renderer r = m.GetComponent<Renderer>();
|
||||
if (r != null) {
|
||||
r.enabled = true;
|
||||
} else {
|
||||
m.SetActive(true);
|
||||
}
|
||||
}
|
||||
StartCoroutine(DoAppear());
|
||||
}
|
||||
|
||||
IEnumerator DoAppear() {
|
||||
CanvasGroup cg = GetComponent<CanvasGroup>();
|
||||
while (cg.alpha < 1.0) {
|
||||
cg.alpha += Time.deltaTime * 2;
|
||||
yield return null;
|
||||
}
|
||||
cg.interactable = true;
|
||||
yield break;
|
||||
}
|
||||
|
||||
IEnumerator DoFade() {
|
||||
CanvasGroup cg = GetComponent<CanvasGroup>();
|
||||
while (cg.alpha > 0) {
|
||||
cg.alpha -= Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
cg.interactable = false;
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/GoogleVR/Demos/Scripts/VideoDemo/MenuHandler.cs.meta
Normal file
12
Assets/GoogleVR/Demos/Scripts/VideoDemo/MenuHandler.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7304a3fe3b19a4eb8ba4e4b21008b2f0
|
||||
timeCreated: 1475106364
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
88
Assets/GoogleVR/Demos/Scripts/VideoDemo/PositionSwapper.cs
Normal file
88
Assets/GoogleVR/Demos/Scripts/VideoDemo/PositionSwapper.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright 2016 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace GoogleVR.VideoDemo {
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the position of the transform to a position specifed in a list.
|
||||
/// </summary>
|
||||
public class PositionSwapper : MonoBehaviour {
|
||||
private int currentIndex = -1;
|
||||
|
||||
public Vector3[] Positions = new Vector3[0];
|
||||
|
||||
public void SetConstraint(int index) { }
|
||||
|
||||
public void SetPosition(int index) {
|
||||
currentIndex = index % Positions.Length;
|
||||
transform.localPosition = Positions[currentIndex];
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private static void SaveToIndex(UnityEditor.MenuCommand mc, int index) {
|
||||
PositionSwapper ps = mc.context as PositionSwapper;
|
||||
while (ps.Positions.Length <= index) {
|
||||
UnityEditor.ArrayUtility.Add<Vector3>(ref ps.Positions, Vector3.zero);
|
||||
}
|
||||
ps.Positions[index] = ps.transform.localPosition;
|
||||
}
|
||||
|
||||
private static void LoadIndex(UnityEditor.MenuCommand mc, int index) {
|
||||
PositionSwapper ps = mc.context as PositionSwapper;
|
||||
ps.SetPosition(index);
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/PositionSwapper/SavePositionToIndex0")]
|
||||
private static void SaveToIndex0(UnityEditor.MenuCommand mc) {
|
||||
SaveToIndex(mc, 0);
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/PositionSwapper/SavePositionToIndex1")]
|
||||
private static void SaveToIndex1(UnityEditor.MenuCommand mc) {
|
||||
SaveToIndex(mc, 1);
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/PositionSwapper/SavePositionToIndex2")]
|
||||
private static void SaveToIndex2(UnityEditor.MenuCommand mc) {
|
||||
SaveToIndex(mc, 2);
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/PositionSwapper/SavePositionToIndex3")]
|
||||
private static void SaveToIndex3(UnityEditor.MenuCommand mc) {
|
||||
SaveToIndex(mc, 3);
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/PositionSwapper/LoadPosition0")]
|
||||
private static void LoadPosition0(UnityEditor.MenuCommand mc) {
|
||||
LoadIndex(mc, 0);
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/PositionSwapper/LoadPosition1")]
|
||||
private static void LoadPosition1(UnityEditor.MenuCommand mc) {
|
||||
LoadIndex(mc, 1);
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/PositionSwapper/LoadPosition2")]
|
||||
private static void LoadPosition2(UnityEditor.MenuCommand mc) {
|
||||
LoadIndex(mc, 2);
|
||||
}
|
||||
|
||||
[UnityEditor.MenuItem("CONTEXT/PositionSwapper/LoadPosition3")]
|
||||
private static void LoadPosition3(UnityEditor.MenuCommand mc) {
|
||||
LoadIndex(mc, 3);
|
||||
}
|
||||
#endif // UNITY_EDITOR
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 680140f42b355d442a0a57a1d8fcc4b1
|
||||
timeCreated: 1463151666
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
93
Assets/GoogleVR/Demos/Scripts/VideoDemo/ScrubberEvents.cs
Normal file
93
Assets/GoogleVR/Demos/Scripts/VideoDemo/ScrubberEvents.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright 2016 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace GoogleVR.VideoDemo {
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ScrubberEvents : MonoBehaviour {
|
||||
private GameObject newPositionHandle;
|
||||
|
||||
private Vector3[] corners;
|
||||
private Slider slider;
|
||||
|
||||
private VideoControlsManager mgr;
|
||||
|
||||
public VideoControlsManager ControlManager {
|
||||
set {
|
||||
mgr = value;
|
||||
}
|
||||
}
|
||||
|
||||
void Start() {
|
||||
foreach (Image im in GetComponentsInChildren<Image>(true)) {
|
||||
if (im.gameObject.name == "newPositionHandle") {
|
||||
newPositionHandle = im.gameObject;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
corners = new Vector3[4];
|
||||
GetComponent<Image>().rectTransform.GetWorldCorners(corners);
|
||||
slider = GetComponentInParent<Slider>();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
bool setPos = false;
|
||||
if (GvrPointerInputModule.Pointer != null) {
|
||||
RaycastResult r = GvrPointerInputModule.Pointer.CurrentRaycastResult;
|
||||
if (r.gameObject != null) {
|
||||
newPositionHandle.transform.position = new Vector3(
|
||||
r.worldPosition.x,
|
||||
newPositionHandle.transform.position.y,
|
||||
newPositionHandle.transform.position.z);
|
||||
setPos = true;
|
||||
}
|
||||
}
|
||||
if (!setPos) {
|
||||
newPositionHandle.transform.position = slider.handleRect.transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(BaseEventData data) {
|
||||
if (GvrPointerInputModule.Pointer != null) {
|
||||
RaycastResult r = GvrPointerInputModule.Pointer.CurrentRaycastResult;
|
||||
if (r.gameObject != null) {
|
||||
newPositionHandle.transform.position = new Vector3(
|
||||
r.worldPosition.x,
|
||||
newPositionHandle.transform.position.y,
|
||||
newPositionHandle.transform.position.z);
|
||||
}
|
||||
}
|
||||
newPositionHandle.SetActive(true);
|
||||
}
|
||||
|
||||
public void OnPointerExit(BaseEventData data) {
|
||||
newPositionHandle.SetActive(false);
|
||||
}
|
||||
|
||||
public void OnPointerClick(BaseEventData data) {
|
||||
float minX = corners[0].x;
|
||||
float maxX = corners[3].x;
|
||||
|
||||
float pct = (newPositionHandle.transform.position.x - minX) / (maxX - minX);
|
||||
|
||||
if (mgr != null) {
|
||||
long p = (long)(slider.maxValue * pct);
|
||||
mgr.Player.CurrentPosition = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cc7f51d6c6b140f79f7afded8b84284
|
||||
timeCreated: 1472155348
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
94
Assets/GoogleVR/Demos/Scripts/VideoDemo/SwitchVideos.cs
Normal file
94
Assets/GoogleVR/Demos/Scripts/VideoDemo/SwitchVideos.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright (C) 2016 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace GoogleVR.VideoDemo {
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SwitchVideos : MonoBehaviour {
|
||||
public GameObject localVideoSample;
|
||||
public GameObject dashVideoSample;
|
||||
public GameObject panoVideoSample;
|
||||
|
||||
private GameObject[] videoSamples;
|
||||
|
||||
public Text missingLibText;
|
||||
|
||||
public void Awake() {
|
||||
videoSamples = new GameObject[3];
|
||||
videoSamples[0] = localVideoSample;
|
||||
videoSamples[1] = dashVideoSample;
|
||||
videoSamples[2] = panoVideoSample;
|
||||
|
||||
string NATIVE_LIBS_MISSING_MESSAGE = "Video Support libraries not found or could not be loaded!\n" +
|
||||
"Please add the <b>GVRVideoPlayer.unitypackage</b>\n to this project";
|
||||
|
||||
if (missingLibText != null) {
|
||||
try {
|
||||
IntPtr ptr = GvrVideoPlayerTexture.CreateVideoPlayer();
|
||||
if (ptr != IntPtr.Zero) {
|
||||
GvrVideoPlayerTexture.DestroyVideoPlayer(ptr);
|
||||
missingLibText.enabled = false;
|
||||
} else {
|
||||
missingLibText.text = NATIVE_LIBS_MISSING_MESSAGE;
|
||||
missingLibText.enabled = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debug.LogError(e);
|
||||
missingLibText.text = NATIVE_LIBS_MISSING_MESSAGE;
|
||||
missingLibText.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowMainMenu() {
|
||||
ShowSample(-1);
|
||||
}
|
||||
|
||||
public void OnFlatLocal() {
|
||||
ShowSample(0);
|
||||
}
|
||||
|
||||
public void OnDash() {
|
||||
ShowSample(1);
|
||||
}
|
||||
|
||||
public void On360Video() {
|
||||
ShowSample(2);
|
||||
}
|
||||
|
||||
private void ShowSample(int index) {
|
||||
// If the libs are missing, always show the main menu.
|
||||
if (missingLibText != null && missingLibText.enabled) {
|
||||
index = -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < videoSamples.Length; i++) {
|
||||
if (videoSamples[i] != null) {
|
||||
|
||||
if (i != index) {
|
||||
if (videoSamples[i].activeSelf) {
|
||||
videoSamples[i].GetComponentInChildren<GvrVideoPlayerTexture>().CleanupVideo();
|
||||
}
|
||||
} else {
|
||||
videoSamples[i].GetComponentInChildren<GvrVideoPlayerTexture>().ReInitializeVideo();
|
||||
}
|
||||
videoSamples[i].SetActive(i == index);
|
||||
}
|
||||
}
|
||||
GetComponent<Canvas>().enabled = index == -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/GoogleVR/Demos/Scripts/VideoDemo/SwitchVideos.cs.meta
Normal file
12
Assets/GoogleVR/Demos/Scripts/VideoDemo/SwitchVideos.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 114ed7f3f1d114a2988b1f93a233b40e
|
||||
timeCreated: 1472683809
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
76
Assets/GoogleVR/Demos/Scripts/VideoDemo/ToggleAction.cs
Normal file
76
Assets/GoogleVR/Demos/Scripts/VideoDemo/ToggleAction.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright 2016 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace GoogleVR.VideoDemo {
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Throws a Unity event when the internal state is changed. This
|
||||
/// component can be used by other components the fire Unity Events in
|
||||
/// order to do some lightweight state tracking.
|
||||
/// </summary>
|
||||
public class ToggleAction : MonoBehaviour {
|
||||
private float lastUsage;
|
||||
private bool on;
|
||||
|
||||
[Tooltip("Event to raise when this is toggled on.")]
|
||||
public UnityEvent OnToggleOn;
|
||||
|
||||
[Tooltip("Event to raise when this is toggled off.")]
|
||||
public UnityEvent OnToggleOff;
|
||||
|
||||
[Tooltip("Should this initial state be on or off?")]
|
||||
public bool InitialState;
|
||||
|
||||
[Tooltip("Should an event be raised for the initial state on Start?")]
|
||||
public bool RaiseEventForInitialState;
|
||||
|
||||
[Tooltip("Time required between toggle operations. Operations Toggles within this window " +
|
||||
"will be ignored.")]
|
||||
public float Cooldown;
|
||||
|
||||
void Start() {
|
||||
on = InitialState;
|
||||
if (RaiseEventForInitialState) {
|
||||
RaiseToggleEvent(on);
|
||||
}
|
||||
}
|
||||
|
||||
public void Toggle() {
|
||||
if (Time.time - lastUsage < Cooldown) {
|
||||
return;
|
||||
}
|
||||
lastUsage = Time.time;
|
||||
on = !on;
|
||||
RaiseToggleEvent(on);
|
||||
}
|
||||
|
||||
public void Set(bool on) {
|
||||
if (this.on == on) {
|
||||
return;
|
||||
}
|
||||
this.on = on;
|
||||
RaiseToggleEvent(on);
|
||||
}
|
||||
|
||||
private void RaiseToggleEvent(bool on) {
|
||||
if (on) {
|
||||
OnToggleOn.Invoke();
|
||||
} else {
|
||||
OnToggleOff.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/GoogleVR/Demos/Scripts/VideoDemo/ToggleAction.cs.meta
Normal file
12
Assets/GoogleVR/Demos/Scripts/VideoDemo/ToggleAction.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1b8f07442700094898145567ef1f203
|
||||
timeCreated: 1460408320
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
218
Assets/GoogleVR/Demos/Scripts/VideoDemo/VideoControlsManager.cs
Normal file
218
Assets/GoogleVR/Demos/Scripts/VideoDemo/VideoControlsManager.cs
Normal file
@@ -0,0 +1,218 @@
|
||||
// Copyright 2016 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace GoogleVR.VideoDemo {
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class VideoControlsManager : MonoBehaviour {
|
||||
private GameObject pauseSprite;
|
||||
private GameObject playSprite;
|
||||
|
||||
private Slider videoScrubber;
|
||||
private Slider volumeSlider;
|
||||
private GameObject volumeWidget;
|
||||
private GameObject settingsPanel;
|
||||
private GameObject bufferedBackground;
|
||||
private Vector3 basePosition;
|
||||
private Text videoPosition;
|
||||
private Text videoDuration;
|
||||
|
||||
public GvrVideoPlayerTexture Player
|
||||
{
|
||||
set;
|
||||
get;
|
||||
}
|
||||
|
||||
void Awake() {
|
||||
foreach (Text t in GetComponentsInChildren<Text>()) {
|
||||
if (t.gameObject.name == "curpos_text") {
|
||||
videoPosition = t;
|
||||
} else if (t.gameObject.name == "duration_text") {
|
||||
videoDuration = t;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (RawImage raw in GetComponentsInChildren<RawImage>(true)) {
|
||||
if (raw.gameObject.name == "playImage") {
|
||||
playSprite = raw.gameObject;
|
||||
} else if (raw.gameObject.name == "pauseImage") {
|
||||
pauseSprite = raw.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Slider s in GetComponentsInChildren<Slider>(true)) {
|
||||
if (s.gameObject.name == "video_slider") {
|
||||
videoScrubber = s;
|
||||
videoScrubber.maxValue = 100;
|
||||
videoScrubber.minValue = 0;
|
||||
foreach (Image i in videoScrubber.GetComponentsInChildren<Image>()) {
|
||||
if (i.gameObject.name == "BufferedBackground") {
|
||||
bufferedBackground = i.gameObject;
|
||||
}
|
||||
}
|
||||
} else if (s.gameObject.name == "volume_slider") {
|
||||
volumeSlider = s;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (RectTransform obj in GetComponentsInChildren<RectTransform>(true)) {
|
||||
if (obj.gameObject.name == "volume_widget") {
|
||||
volumeWidget = obj.gameObject;
|
||||
} else if (obj.gameObject.name == "settings_panel") {
|
||||
settingsPanel = obj.gameObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Start() {
|
||||
foreach (ScrubberEvents s in GetComponentsInChildren<ScrubberEvents>(true)) {
|
||||
s.ControlManager = this;
|
||||
}
|
||||
|
||||
if (Player != null) {
|
||||
Player.Init();
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
if ((!Player.VideoReady || Player.IsPaused)) {
|
||||
pauseSprite.SetActive(false);
|
||||
playSprite.SetActive(true);
|
||||
} else if (Player.VideoReady && !Player.IsPaused) {
|
||||
pauseSprite.SetActive(true);
|
||||
playSprite.SetActive(false);
|
||||
}
|
||||
|
||||
if (Player.VideoReady) {
|
||||
if (basePosition == Vector3.zero) {
|
||||
basePosition = videoScrubber.handleRect.localPosition;
|
||||
}
|
||||
videoScrubber.maxValue = Player.VideoDuration;
|
||||
videoScrubber.value = Player.CurrentPosition;
|
||||
|
||||
float pct = Player.BufferedPercentage / 100.0f;
|
||||
float sx = Mathf.Clamp(pct, 0, 1f);
|
||||
bufferedBackground.transform.localScale = new Vector3(sx, 1, 1);
|
||||
bufferedBackground.transform.localPosition =
|
||||
new Vector3(basePosition.x - (basePosition.x * sx), 0, 0);
|
||||
|
||||
videoPosition.text = FormatTime(Player.CurrentPosition);
|
||||
videoDuration.text = FormatTime(Player.VideoDuration);
|
||||
|
||||
if (volumeSlider != null) {
|
||||
volumeSlider.minValue = 0;
|
||||
volumeSlider.maxValue = Player.MaxVolume;
|
||||
volumeSlider.value = Player.CurrentVolume;
|
||||
}
|
||||
} else {
|
||||
videoScrubber.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnVolumeUp() {
|
||||
if (Player.CurrentVolume < Player.MaxVolume) {
|
||||
Player.CurrentVolume += 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnVolumeDown() {
|
||||
if (Player.CurrentVolume > 0) {
|
||||
Player.CurrentVolume -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnToggleVolume() {
|
||||
bool visible = !volumeWidget.activeSelf;
|
||||
volumeWidget.SetActive(visible);
|
||||
|
||||
// close settings if volume opens.
|
||||
settingsPanel.SetActive(settingsPanel.activeSelf && !visible);
|
||||
}
|
||||
|
||||
public void OnToggleSettings() {
|
||||
bool visible = !settingsPanel.activeSelf;
|
||||
settingsPanel.SetActive(visible);
|
||||
|
||||
// close settings if volume opens.
|
||||
volumeWidget.SetActive(volumeWidget.activeSelf && !visible);
|
||||
}
|
||||
|
||||
public void OnPlayPause() {
|
||||
bool isPaused = Player.IsPaused;
|
||||
if (isPaused) {
|
||||
Player.Play();
|
||||
} else {
|
||||
Player.Pause();
|
||||
}
|
||||
pauseSprite.SetActive(isPaused);
|
||||
playSprite.SetActive(!isPaused);
|
||||
CloseSubPanels();
|
||||
}
|
||||
|
||||
public void OnVolumePositionChanged(float val) {
|
||||
if (Player.VideoReady) {
|
||||
Debug.Log("Setting current volume to " + val);
|
||||
Player.CurrentVolume = (int)val;
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseSubPanels() {
|
||||
volumeWidget.SetActive(false);
|
||||
settingsPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void Fade(bool show) {
|
||||
if (show) {
|
||||
StartCoroutine(DoAppear());
|
||||
} else {
|
||||
StartCoroutine(DoFade());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator DoAppear() {
|
||||
CanvasGroup cg = GetComponent<CanvasGroup>();
|
||||
while (cg.alpha < 1.0) {
|
||||
cg.alpha += Time.deltaTime * 2;
|
||||
yield return null;
|
||||
}
|
||||
cg.interactable = true;
|
||||
yield break;
|
||||
}
|
||||
|
||||
IEnumerator DoFade() {
|
||||
CanvasGroup cg = GetComponent<CanvasGroup>();
|
||||
while (cg.alpha > 0) {
|
||||
cg.alpha -= Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
cg.interactable = false;
|
||||
CloseSubPanels();
|
||||
yield break;
|
||||
}
|
||||
|
||||
private string FormatTime(long ms) {
|
||||
int sec = ((int)(ms / 1000L));
|
||||
int mn = sec / 60;
|
||||
sec = sec % 60;
|
||||
int hr = mn / 60;
|
||||
mn = mn % 60;
|
||||
if (hr > 0) {
|
||||
return string.Format("{0:00}:{1:00}:{2:00}", hr, mn, sec);
|
||||
}
|
||||
return string.Format("{0:00}:{1:00}", mn, sec);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11ce60bdf78924133940a4a64555e784
|
||||
timeCreated: 1471470978
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2016 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace GoogleVR.VideoDemo {
|
||||
using UnityEngine;
|
||||
|
||||
public class VideoPlayerReference : MonoBehaviour {
|
||||
|
||||
public GvrVideoPlayerTexture player;
|
||||
|
||||
void Awake() {
|
||||
#if !UNITY_5_2
|
||||
GetComponentInChildren<VideoControlsManager>(true).Player = player;
|
||||
#else
|
||||
GetComponentInChildren<VideoControlsManager>().Player = player;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 70f36fab7a81646eeb5c083264db5be0
|
||||
timeCreated: 1471625726
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user