Added VR libraries
This commit is contained in:
350
Assets/GoogleVR/Demos/Scripts/DemoInputManager.cs
Normal file
350
Assets/GoogleVR/Demos/Scripts/DemoInputManager.cs
Normal file
@@ -0,0 +1,350 @@
|
||||
// Copyright 2017 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.
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
#define RUNNING_ON_ANDROID_DEVICE
|
||||
#endif // UNITY_ANDROID && !UNITY_EDITOR
|
||||
|
||||
namespace GoogleVR.Demos {
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
using UnityEngine.XR;
|
||||
#else
|
||||
using XRSettings = UnityEngine.VR.VRSettings;
|
||||
#endif // UNITY_2017_2_OR_NEWER
|
||||
|
||||
public class DemoInputManager : MonoBehaviour {
|
||||
private const string MESSAGE_CANVAS_NAME = "MessageCanvas";
|
||||
private const string MESSAGE_TEXT_NAME = "MessageText";
|
||||
private const string LASER_GAMEOBJECT_NAME = "Laser";
|
||||
|
||||
private const string CONTROLLER_CONNECTING_MESSAGE = "Controller connecting...";
|
||||
private const string CONTROLLER_DISCONNECTED_MESSAGE = "Controller disconnected";
|
||||
private const string CONTROLLER_SCANNING_MESSAGE = "Controller scanning...";
|
||||
private const string NON_GVR_PLATFORM =
|
||||
"Please select a supported Google VR platform via 'Build Settings > Android | iOS > Switch Platform'\n";
|
||||
private const string VR_SUPPORT_NOT_CHECKED =
|
||||
"Please make sure 'Player Settings > Virtual Reality Supported' is checked\n";
|
||||
private const string EMPTY_VR_SDK_WARNING_MESSAGE =
|
||||
"Please add 'Daydream' or 'Cardboard' under 'Player Settings > Virtual Reality SDKs'\n";
|
||||
|
||||
// Java class, method, and field constants.
|
||||
private const int ANDROID_MIN_DAYDREAM_API = 24;
|
||||
private const string FIELD_SDK_INT = "SDK_INT";
|
||||
private const string PACKAGE_BUILD_VERSION = "android.os.Build$VERSION";
|
||||
private const string PACKAGE_DAYDREAM_API_CLASS = "com.google.vr.ndk.base.DaydreamApi";
|
||||
private const string METHOD_IS_DAYDREAM_READY = "isDaydreamReadyPlatform";
|
||||
|
||||
private bool isDaydream = false;
|
||||
private int activeControllerPointer = 0;
|
||||
private static GvrControllerHand[] AllHands = {
|
||||
GvrControllerHand.Right,
|
||||
GvrControllerHand.Left,
|
||||
};
|
||||
|
||||
[Tooltip("Reference to GvrControllerMain")]
|
||||
public GameObject controllerMain;
|
||||
public static string CONTROLLER_MAIN_PROP_NAME = "controllerMain";
|
||||
|
||||
[Tooltip("Reference to GvrControllerPointers")]
|
||||
public GameObject[] controllerPointers;
|
||||
public static string CONTROLLER_POINTER_PROP_NAME = "controllerPointers";
|
||||
|
||||
[Tooltip("Reference to GvrReticlePointer")]
|
||||
public GameObject reticlePointer;
|
||||
public static string RETICLE_POINTER_PROP_NAME = "reticlePointer";
|
||||
|
||||
public GameObject messageCanvas;
|
||||
public Text messageText;
|
||||
|
||||
#if !RUNNING_ON_ANDROID_DEVICE
|
||||
public enum EmulatedPlatformType {
|
||||
Daydream,
|
||||
Cardboard
|
||||
}
|
||||
[Tooltip("Emulated GVR Platform")]
|
||||
public EmulatedPlatformType gvrEmulatedPlatformType = EmulatedPlatformType.Daydream;
|
||||
public static string EMULATED_PLATFORM_PROP_NAME = "gvrEmulatedPlatformType";
|
||||
#else
|
||||
// Running on an Android device.
|
||||
private GvrSettings.ViewerPlatformType viewerPlatform;
|
||||
#endif // !RUNNING_ON_ANDROID_DEVICE
|
||||
|
||||
void Start() {
|
||||
if (messageCanvas == null) {
|
||||
messageCanvas = transform.Find(MESSAGE_CANVAS_NAME).gameObject;
|
||||
if (messageCanvas != null) {
|
||||
messageText = messageCanvas.transform.Find(MESSAGE_TEXT_NAME).GetComponent<Text>();
|
||||
}
|
||||
}
|
||||
// Message canvas will be enabled later when there's a message to display.
|
||||
messageCanvas.SetActive(false);
|
||||
#if !RUNNING_ON_ANDROID_DEVICE
|
||||
if (playerSettingsHasDaydream() || playerSettingsHasCardboard()) {
|
||||
// The list is populated with valid VR SDK(s), pick the first one.
|
||||
gvrEmulatedPlatformType =
|
||||
(XRSettings.supportedDevices[0] == GvrSettings.VR_SDK_DAYDREAM) ?
|
||||
EmulatedPlatformType.Daydream :
|
||||
EmulatedPlatformType.Cardboard;
|
||||
}
|
||||
isDaydream = (gvrEmulatedPlatformType == EmulatedPlatformType.Daydream);
|
||||
#else
|
||||
// Running on an Android device.
|
||||
viewerPlatform = GvrSettings.ViewerPlatform;
|
||||
// First loaded device in Player Settings.
|
||||
string vrDeviceName = XRSettings.loadedDeviceName;
|
||||
if (vrDeviceName != GvrSettings.VR_SDK_CARDBOARD &&
|
||||
vrDeviceName != GvrSettings.VR_SDK_DAYDREAM) {
|
||||
Debug.LogErrorFormat("Loaded device was '{0}', must be one of '{1}' or '{2}'",
|
||||
vrDeviceName, GvrSettings.VR_SDK_DAYDREAM, GvrSettings.VR_SDK_CARDBOARD);
|
||||
return;
|
||||
}
|
||||
|
||||
// On a non-Daydream ready phone, fall back to Cardboard if it's present in the list of
|
||||
// enabled VR SDKs.
|
||||
// On a Daydream-ready phone, go into Cardboard mode if it's the currently-paired viewer.
|
||||
if ((!IsDeviceDaydreamReady() && playerSettingsHasCardboard()) ||
|
||||
(IsDeviceDaydreamReady() && playerSettingsHasCardboard() &&
|
||||
GvrSettings.ViewerPlatform == GvrSettings.ViewerPlatformType.Cardboard)) {
|
||||
vrDeviceName = GvrSettings.VR_SDK_CARDBOARD;
|
||||
}
|
||||
isDaydream = (vrDeviceName == GvrSettings.VR_SDK_DAYDREAM);
|
||||
#endif // !RUNNING_ON_ANDROID_DEVICE
|
||||
SetVRInputMechanism();
|
||||
}
|
||||
|
||||
// Runtime switching enabled only in-editor.
|
||||
void Update() {
|
||||
UpdateStatusMessage();
|
||||
|
||||
// Scan all devices' buttons for button down, and switch the singleton pointer
|
||||
// to the controller the user last clicked.
|
||||
int newPointer = activeControllerPointer;
|
||||
|
||||
if (controllerPointers.Length > 1 && controllerPointers[1] != null) {
|
||||
// Buttons that can trigger pointer switching.
|
||||
GvrControllerButton buttonMask = GvrControllerButton.App | GvrControllerButton.TouchPadButton;
|
||||
GvrTrackedController trackedController1 = controllerPointers[1].GetComponent<GvrTrackedController>();
|
||||
foreach (var hand in AllHands) {
|
||||
GvrControllerInputDevice device = GvrControllerInput.GetDevice(hand);
|
||||
if (device.GetButtonDown(buttonMask)) {
|
||||
// Match the button to our own controllerPointers list.
|
||||
if (device == trackedController1.ControllerInputDevice) {
|
||||
newPointer = 1;
|
||||
} else {
|
||||
newPointer = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newPointer != activeControllerPointer) {
|
||||
activeControllerPointer = newPointer;
|
||||
SetVRInputMechanism();
|
||||
}
|
||||
|
||||
#if !RUNNING_ON_ANDROID_DEVICE
|
||||
UpdateEmulatedPlatformIfPlayerSettingsChanged();
|
||||
if ((isDaydream && gvrEmulatedPlatformType == EmulatedPlatformType.Daydream) ||
|
||||
(!isDaydream && gvrEmulatedPlatformType == EmulatedPlatformType.Cardboard)) {
|
||||
return;
|
||||
}
|
||||
isDaydream = (gvrEmulatedPlatformType == EmulatedPlatformType.Daydream);
|
||||
SetVRInputMechanism();
|
||||
#else
|
||||
// Running on an Android device.
|
||||
// Viewer type switched at runtime.
|
||||
if (!IsDeviceDaydreamReady() || viewerPlatform == GvrSettings.ViewerPlatform) {
|
||||
return;
|
||||
}
|
||||
isDaydream = (GvrSettings.ViewerPlatform == GvrSettings.ViewerPlatformType.Daydream);
|
||||
viewerPlatform = GvrSettings.ViewerPlatform;
|
||||
SetVRInputMechanism();
|
||||
#endif // !RUNNING_ON_ANDROID_DEVICE
|
||||
}
|
||||
|
||||
public bool IsCurrentlyDaydream() {
|
||||
return isDaydream;
|
||||
}
|
||||
|
||||
public static bool playerSettingsHasDaydream() {
|
||||
string[] playerSettingsVrSdks = XRSettings.supportedDevices;
|
||||
return Array.Exists<string>(playerSettingsVrSdks,
|
||||
element => element.Equals(GvrSettings.VR_SDK_DAYDREAM));
|
||||
}
|
||||
|
||||
public static bool playerSettingsHasCardboard() {
|
||||
string[] playerSettingsVrSdks = XRSettings.supportedDevices;
|
||||
return Array.Exists<string>(playerSettingsVrSdks,
|
||||
element => element.Equals(GvrSettings.VR_SDK_CARDBOARD));
|
||||
}
|
||||
|
||||
#if !RUNNING_ON_ANDROID_DEVICE
|
||||
private void UpdateEmulatedPlatformIfPlayerSettingsChanged() {
|
||||
if (!playerSettingsHasDaydream() && !playerSettingsHasCardboard()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Player Settings > VR SDK list may have changed at runtime. The emulated platform
|
||||
// may not have been manually updated if that's the case.
|
||||
if (gvrEmulatedPlatformType == EmulatedPlatformType.Daydream &&
|
||||
!playerSettingsHasDaydream()) {
|
||||
gvrEmulatedPlatformType = EmulatedPlatformType.Cardboard;
|
||||
} else if (gvrEmulatedPlatformType == EmulatedPlatformType.Cardboard &&
|
||||
!playerSettingsHasCardboard()) {
|
||||
gvrEmulatedPlatformType = EmulatedPlatformType.Daydream;
|
||||
}
|
||||
}
|
||||
#endif // !RUNNING_ON_ANDROID_DEVICE
|
||||
|
||||
#if RUNNING_ON_ANDROID_DEVICE
|
||||
// Running on an Android device.
|
||||
private static bool IsDeviceDaydreamReady() {
|
||||
// Check API level.
|
||||
using (var version = new AndroidJavaClass(PACKAGE_BUILD_VERSION)) {
|
||||
if (version.GetStatic<int>(FIELD_SDK_INT) < ANDROID_MIN_DAYDREAM_API) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// API level > 24, check whether the device is Daydream-ready..
|
||||
AndroidJavaObject androidActivity = null;
|
||||
try {
|
||||
androidActivity = GvrActivityHelper.GetActivity();
|
||||
} catch (AndroidJavaException e) {
|
||||
Debug.LogError("Exception while connecting to the Activity: " + e);
|
||||
return false;
|
||||
}
|
||||
AndroidJavaClass daydreamApiClass = new AndroidJavaClass(PACKAGE_DAYDREAM_API_CLASS);
|
||||
if (daydreamApiClass == null || androidActivity == null) {
|
||||
return false;
|
||||
}
|
||||
return daydreamApiClass.CallStatic<bool>(METHOD_IS_DAYDREAM_READY, androidActivity);
|
||||
}
|
||||
#endif // RUNNING_ON_ANDROID_DEVICE
|
||||
|
||||
private void UpdateStatusMessage() {
|
||||
if (messageText == null || messageCanvas == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if !UNITY_ANDROID && !UNITY_IOS
|
||||
messageText.text = NON_GVR_PLATFORM;
|
||||
messageCanvas.SetActive(true);
|
||||
return;
|
||||
#else
|
||||
#if UNITY_EDITOR
|
||||
if (!UnityEditor.PlayerSettings.virtualRealitySupported) {
|
||||
messageText.text = VR_SUPPORT_NOT_CHECKED;
|
||||
messageCanvas.SetActive(true);
|
||||
return;
|
||||
}
|
||||
#endif // UNITY_EDITOR
|
||||
|
||||
bool isVrSdkListEmpty = !playerSettingsHasCardboard() && !playerSettingsHasDaydream();
|
||||
if (!isDaydream) {
|
||||
if (messageCanvas.activeSelf) {
|
||||
messageText.text = EMPTY_VR_SDK_WARNING_MESSAGE;
|
||||
messageCanvas.SetActive(isVrSdkListEmpty);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
string vrSdkWarningMessage = isVrSdkListEmpty ? EMPTY_VR_SDK_WARNING_MESSAGE : "";
|
||||
string controllerMessage = "";
|
||||
GvrPointerGraphicRaycaster graphicRaycaster =
|
||||
messageCanvas.GetComponent<GvrPointerGraphicRaycaster>();
|
||||
GvrControllerInputDevice dominantDevice = GvrControllerInput.GetDevice(GvrControllerHand.Dominant);
|
||||
GvrConnectionState connectionState = dominantDevice.State;
|
||||
// This is an example of how to process the controller's state to display a status message.
|
||||
switch (connectionState) {
|
||||
case GvrConnectionState.Connected:
|
||||
break;
|
||||
case GvrConnectionState.Disconnected:
|
||||
controllerMessage = CONTROLLER_DISCONNECTED_MESSAGE;
|
||||
messageText.color = Color.white;
|
||||
break;
|
||||
case GvrConnectionState.Scanning:
|
||||
controllerMessage = CONTROLLER_SCANNING_MESSAGE;
|
||||
messageText.color = Color.cyan;
|
||||
break;
|
||||
case GvrConnectionState.Connecting:
|
||||
controllerMessage = CONTROLLER_CONNECTING_MESSAGE;
|
||||
messageText.color = Color.yellow;
|
||||
break;
|
||||
case GvrConnectionState.Error:
|
||||
controllerMessage = "ERROR: " + dominantDevice.ErrorDetails;
|
||||
messageText.color = Color.red;
|
||||
break;
|
||||
default:
|
||||
// Shouldn't happen.
|
||||
Debug.LogError("Invalid controller state: " + connectionState);
|
||||
break;
|
||||
}
|
||||
messageText.text = string.Format("{0}\n{1}", vrSdkWarningMessage, controllerMessage);
|
||||
if (graphicRaycaster != null) {
|
||||
graphicRaycaster.enabled =
|
||||
!isVrSdkListEmpty || connectionState != GvrConnectionState.Connected;
|
||||
}
|
||||
messageCanvas.SetActive(isVrSdkListEmpty ||
|
||||
(connectionState != GvrConnectionState.Connected));
|
||||
#endif // !UNITY_ANDROID && !UNITY_IOS
|
||||
}
|
||||
|
||||
private void SetVRInputMechanism() {
|
||||
SetGazeInputActive(!isDaydream);
|
||||
SetControllerInputActive(isDaydream);
|
||||
}
|
||||
|
||||
private void SetGazeInputActive(bool active) {
|
||||
if (reticlePointer == null) {
|
||||
return;
|
||||
}
|
||||
reticlePointer.SetActive(active);
|
||||
|
||||
// Update the pointer type only if this is currently activated.
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
|
||||
GvrReticlePointer pointer =
|
||||
reticlePointer.GetComponent<GvrReticlePointer>();
|
||||
if (pointer != null) {
|
||||
GvrPointerInputModule.Pointer = pointer;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetControllerInputActive(bool active) {
|
||||
if (controllerMain != null) {
|
||||
controllerMain.SetActive(active);
|
||||
}
|
||||
if (controllerPointers == null || controllerPointers.Length <= activeControllerPointer) {
|
||||
return;
|
||||
}
|
||||
controllerPointers[activeControllerPointer].SetActive(active);
|
||||
|
||||
// Update the pointer type only if this is currently activated.
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
GvrLaserPointer pointer =
|
||||
controllerPointers[activeControllerPointer].GetComponentInChildren<GvrLaserPointer>(true);
|
||||
if (pointer != null) {
|
||||
GvrPointerInputModule.Pointer = pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/GoogleVR/Demos/Scripts/DemoInputManager.cs.meta
Normal file
12
Assets/GoogleVR/Demos/Scripts/DemoInputManager.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ddd25f1308577456cbaa207901961126
|
||||
timeCreated: 1479273440
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/GoogleVR/Demos/Scripts/DemoSceneManager.cs
Normal file
31
Assets/GoogleVR/Demos/Scripts/DemoSceneManager.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2017 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.Demos {
|
||||
using UnityEngine;
|
||||
|
||||
// Ensures correct app and scene setup.
|
||||
public class DemoSceneManager : MonoBehaviour {
|
||||
void Start() {
|
||||
Input.backButtonLeavesApp = true;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
// Exit when (X) is tapped.
|
||||
if (Input.GetKeyDown(KeyCode.Escape)) {
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/GoogleVR/Demos/Scripts/DemoSceneManager.cs.meta
Normal file
12
Assets/GoogleVR/Demos/Scripts/DemoSceneManager.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1bec9ea3efe7849ffae666549aca3cad
|
||||
timeCreated: 1485218787
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/GoogleVR/Demos/Scripts/HelloVR.meta
Normal file
8
Assets/GoogleVR/Demos/Scripts/HelloVR.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61dead4742ef5b6479ed6406cd6d8798
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
114
Assets/GoogleVR/Demos/Scripts/HelloVR/HeadsetDemoManager.cs
Normal file
114
Assets/GoogleVR/Demos/Scripts/HelloVR/HeadsetDemoManager.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
// Copyright 2017 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.HelloVR {
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
/// Demonstrates the use of GvrHeadset events and APIs.
|
||||
public class HeadsetDemoManager : MonoBehaviour {
|
||||
public GameObject safetyRing;
|
||||
public bool enableDebugLog = false;
|
||||
private WaitForSeconds waitFourSeconds = new WaitForSeconds(4);
|
||||
|
||||
#region STANDALONE_DELEGATES
|
||||
public void OnSafetyRegionEvent(bool enter) {
|
||||
Debug.Log("SafetyRegionEvent: " + (enter ? "enter" : "exit"));
|
||||
}
|
||||
|
||||
public void OnRecenterEvent(GvrRecenterEventType recenterType,
|
||||
GvrRecenterFlags recenterFlags,
|
||||
Vector3 recenteredPosition,
|
||||
Quaternion recenteredOrientation) {
|
||||
Debug.Log(string.Format("RecenterEvent: Type {0}, flags {1}\nPosition: {2}, " +
|
||||
"Rotation: {3}", recenterType, recenterFlags, recenteredPosition, recenteredOrientation));
|
||||
}
|
||||
#endregion // STANDALONE_DELEGATES
|
||||
|
||||
public void FindFloorHeight() {
|
||||
float floorHeight = 0.0f;
|
||||
bool success = GvrHeadset.TryGetFloorHeight(ref floorHeight);
|
||||
Debug.Log("Floor height success " + success + "; value " + floorHeight);
|
||||
}
|
||||
|
||||
public void FindRecenterTransform() {
|
||||
Vector3 position = Vector3.zero;
|
||||
Quaternion rotation = Quaternion.identity;
|
||||
bool success = GvrHeadset.TryGetRecenterTransform(ref position, ref rotation);
|
||||
Debug.Log("Recenter transform success " + success + "; value " + position + "; " + rotation);
|
||||
}
|
||||
|
||||
public void FindSafetyRegionType() {
|
||||
GvrSafetyRegionType safetyType = GvrSafetyRegionType.None;
|
||||
bool success = GvrHeadset.TryGetSafetyRegionType(ref safetyType);
|
||||
Debug.Log("Safety region type success " + success + "; value " + safetyType);
|
||||
}
|
||||
|
||||
public void FindSafetyInnerRadius() {
|
||||
float innerRadius = -1.0f;
|
||||
bool success = GvrHeadset.TryGetSafetyCylinderInnerRadius(ref innerRadius);
|
||||
Debug.Log("Safety region inner radius success " + success + "; value " + innerRadius);
|
||||
// Don't activate the safety cylinder visual until the radius is a reasonable value.
|
||||
if (innerRadius > 0.1f && safetyRing != null) {
|
||||
safetyRing.SetActive(true);
|
||||
safetyRing.transform.localScale = new Vector3(innerRadius, 1, innerRadius);
|
||||
}
|
||||
}
|
||||
|
||||
public void FindSafetyOuterRadius() {
|
||||
float outerRadius = -1.0f;
|
||||
bool success = GvrHeadset.TryGetSafetyCylinderOuterRadius(ref outerRadius);
|
||||
Debug.Log("Safety region outer radius success " + success + "; value " + outerRadius);
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
if (safetyRing != null) {
|
||||
safetyRing.SetActive(false);
|
||||
}
|
||||
if (!GvrHeadset.SupportsPositionalTracking) {
|
||||
return;
|
||||
}
|
||||
GvrHeadset.OnSafetyRegionChange += OnSafetyRegionEvent;
|
||||
GvrHeadset.OnRecenter += OnRecenterEvent;
|
||||
if (enableDebugLog) {
|
||||
StartCoroutine(StatusUpdateLoop());
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
if (!GvrHeadset.SupportsPositionalTracking) {
|
||||
return;
|
||||
}
|
||||
GvrHeadset.OnSafetyRegionChange -= OnSafetyRegionEvent;
|
||||
GvrHeadset.OnRecenter -= OnRecenterEvent;
|
||||
}
|
||||
|
||||
void Start() {
|
||||
if (GvrHeadset.SupportsPositionalTracking) {
|
||||
Debug.Log("Device supports positional tracking!");
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator StatusUpdateLoop() {
|
||||
while(true) {
|
||||
yield return waitFourSeconds;
|
||||
FindFloorHeight();
|
||||
FindRecenterTransform();
|
||||
FindSafetyOuterRadius();
|
||||
FindSafetyInnerRadius();
|
||||
FindSafetyRegionType();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94f5d450d1bd94c97b1dc8109b633ac0
|
||||
timeCreated: 1498438356
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
59
Assets/GoogleVR/Demos/Scripts/HelloVR/HelloVRManager.cs
Normal file
59
Assets/GoogleVR/Demos/Scripts/HelloVR/HelloVRManager.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2017 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.HelloVR {
|
||||
using UnityEngine;
|
||||
using GoogleVR.Demos;
|
||||
|
||||
public class HelloVRManager : MonoBehaviour {
|
||||
public GameObject m_launchVrHomeButton;
|
||||
public DemoInputManager m_demoInputManager;
|
||||
|
||||
void Start() {
|
||||
#if !UNITY_ANDROID || UNITY_EDITOR
|
||||
if (m_launchVrHomeButton == null) {
|
||||
return;
|
||||
}
|
||||
m_launchVrHomeButton.SetActive(false);
|
||||
#else
|
||||
GvrDaydreamApi.CreateAsync((success) => {
|
||||
if (!success) {
|
||||
// Unexpected. See GvrDaydreamApi log messages for details.
|
||||
Debug.LogError("GvrDaydreamApi.CreateAsync() failed");
|
||||
}
|
||||
});
|
||||
#endif // !UNITY_ANDROID || UNITY_EDITOR
|
||||
}
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
void Update() {
|
||||
if (m_launchVrHomeButton == null || m_demoInputManager == null) {
|
||||
return;
|
||||
}
|
||||
m_launchVrHomeButton.SetActive(m_demoInputManager.IsCurrentlyDaydream());
|
||||
}
|
||||
#endif // UNITY_ANDROID && !UNITY_EDITOR
|
||||
|
||||
public void LaunchVrHome() {
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
GvrDaydreamApi.LaunchVrHomeAsync((success) => {
|
||||
if (!success) {
|
||||
// Unexpected. See GvrDaydreamApi log messages for details.
|
||||
Debug.LogError("GvrDaydreamApi.LaunchVrHomeAsync() failed");
|
||||
}
|
||||
});
|
||||
#endif // UNITY_ANDROID && !UNITY_EDITOR
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/GoogleVR/Demos/Scripts/HelloVR/HelloVRManager.cs.meta
Normal file
12
Assets/GoogleVR/Demos/Scripts/HelloVR/HelloVRManager.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae2d286fc7c3e427bbde238c0ebb970b
|
||||
timeCreated: 1490659306
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
85
Assets/GoogleVR/Demos/Scripts/HelloVR/ObjectController.cs
Normal file
85
Assets/GoogleVR/Demos/Scripts/HelloVR/ObjectController.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
// Copyright 2014 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.HelloVR {
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class ObjectController : MonoBehaviour {
|
||||
private Vector3 startingPosition;
|
||||
private Renderer myRenderer;
|
||||
|
||||
public Material inactiveMaterial;
|
||||
public Material gazedAtMaterial;
|
||||
|
||||
void Start() {
|
||||
startingPosition = transform.localPosition;
|
||||
myRenderer = GetComponent<Renderer>();
|
||||
SetGazedAt(false);
|
||||
}
|
||||
|
||||
public void SetGazedAt(bool gazedAt) {
|
||||
if (inactiveMaterial != null && gazedAtMaterial != null) {
|
||||
myRenderer.material = gazedAt ? gazedAtMaterial : inactiveMaterial;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
int sibIdx = transform.GetSiblingIndex();
|
||||
int numSibs = transform.parent.childCount;
|
||||
for (int i=0; i<numSibs; i++) {
|
||||
GameObject sib = transform.parent.GetChild(i).gameObject;
|
||||
sib.transform.localPosition = startingPosition;
|
||||
sib.SetActive(i == sibIdx);
|
||||
}
|
||||
}
|
||||
|
||||
public void Recenter() {
|
||||
#if !UNITY_EDITOR
|
||||
GvrCardboardHelpers.Recenter();
|
||||
#else
|
||||
if (GvrEditorEmulator.Instance != null) {
|
||||
GvrEditorEmulator.Instance.Recenter();
|
||||
}
|
||||
#endif // !UNITY_EDITOR
|
||||
}
|
||||
|
||||
public void TeleportRandomly(BaseEventData eventData) {
|
||||
// Pick a random sibling, move them somewhere random, activate them,
|
||||
// deactivate ourself.
|
||||
int sibIdx = transform.GetSiblingIndex();
|
||||
int numSibs = transform.parent.childCount;
|
||||
sibIdx = (sibIdx + Random.Range(1, numSibs)) % numSibs;
|
||||
GameObject randomSib = transform.parent.GetChild(sibIdx).gameObject;
|
||||
|
||||
// Move to random new location ±100º horzontal.
|
||||
Vector3 direction = Quaternion.Euler(
|
||||
0,
|
||||
Random.Range(-90, 90),
|
||||
0) * Vector3.forward;
|
||||
// New location between 1.5m and 3.5m.
|
||||
float distance = 2 * Random.value + 1.5f;
|
||||
Vector3 newPos = direction * distance;
|
||||
// Limit vertical position to be fully in the room.
|
||||
newPos.y = Mathf.Clamp(newPos.y, -1.2f, 4f);
|
||||
randomSib.transform.localPosition = newPos;
|
||||
|
||||
randomSib.SetActive(true);
|
||||
gameObject.SetActive(false);
|
||||
SetGazedAt(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6d9412aff759420192d8dcf33f969bb
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
8
Assets/GoogleVR/Demos/Scripts/KeyboardDemo.meta
Normal file
8
Assets/GoogleVR/Demos/Scripts/KeyboardDemo.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: faa08253fd43f314c880375979c583e1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright 2017 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.KeyboardDemo {
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
|
||||
public class KeyboardDelegateExample : GvrKeyboardDelegateBase {
|
||||
|
||||
public Text KeyboardText;
|
||||
public Canvas UpdateCanvas;
|
||||
|
||||
public override event EventHandler KeyboardHidden;
|
||||
public override event EventHandler KeyboardShown;
|
||||
|
||||
private const string DD_KEYBOARD_NOT_INSTALLED_MSG = "Please update the Daydream Keyboard app from the Play Store.";
|
||||
|
||||
void Awake() {
|
||||
if (UpdateCanvas != null) {
|
||||
UpdateCanvas.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnKeyboardShow() {
|
||||
Debug.Log("Calling Keyboard Show Delegate!");
|
||||
EventHandler handler = KeyboardShown;
|
||||
if (handler != null) {
|
||||
handler(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnKeyboardHide() {
|
||||
Debug.Log("Calling Keyboard Hide Delegate!");
|
||||
EventHandler handler = KeyboardHidden;
|
||||
if (handler != null) {
|
||||
handler(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnKeyboardUpdate(string text) {
|
||||
if (KeyboardText != null) {
|
||||
KeyboardText.text = text;
|
||||
} else {
|
||||
Debug.Log("Keyboard text is null....");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnKeyboardEnterPressed(string text) {
|
||||
Debug.Log("Calling Keyboard Enter Pressed Delegate: " + text);
|
||||
}
|
||||
|
||||
public override void OnKeyboardError(GvrKeyboardError errCode) {
|
||||
Debug.Log("Calling Keyboard Error Delegate: ");
|
||||
switch(errCode) {
|
||||
case GvrKeyboardError.UNKNOWN:
|
||||
Debug.Log("Unknown Error");
|
||||
break;
|
||||
case GvrKeyboardError.SERVICE_NOT_CONNECTED:
|
||||
Debug.Log("Service not connected");
|
||||
break;
|
||||
case GvrKeyboardError.NO_LOCALES_FOUND:
|
||||
Debug.Log("No locales found");
|
||||
break;
|
||||
case GvrKeyboardError.SDK_LOAD_FAILED:
|
||||
Debug.LogWarning(DD_KEYBOARD_NOT_INSTALLED_MSG);
|
||||
if (KeyboardText != null) {
|
||||
KeyboardText.text = DD_KEYBOARD_NOT_INSTALLED_MSG;
|
||||
}
|
||||
if (UpdateCanvas != null) {
|
||||
UpdateCanvas.gameObject.SetActive(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void LaunchPlayStore() {
|
||||
if (UpdateCanvas != null) {
|
||||
UpdateCanvas.gameObject.SetActive(false);
|
||||
#if !UNITY_ANDROID
|
||||
Debug.LogError("GVR Keyboard available only on Android.");
|
||||
#else
|
||||
GvrKeyboardIntent.Instance.LaunchPlayStore();
|
||||
#endif // !UNITY_ANDROID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff12693eea0a446d0a2183f2ffe9c711
|
||||
timeCreated: 1478820263
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/GoogleVR/Demos/Scripts/PermissionsDemo.meta
Normal file
8
Assets/GoogleVR/Demos/Scripts/PermissionsDemo.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6c1e9ef957063b46a6802b121ad1a4a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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.PermissionsDemo {
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
|
||||
#if UNITY_ANDROID || UNITY_EDITOR
|
||||
// Manages the permission flow in PermissionsDemo.
|
||||
public class PermissionsFlowManager : MonoBehaviour {
|
||||
private static string[] permissionNames = { "android.permission.READ_EXTERNAL_STORAGE" };
|
||||
|
||||
public Text statusText;
|
||||
|
||||
private static List<GvrPermissionsRequester.PermissionStatus> permissionList =
|
||||
new List<GvrPermissionsRequester.PermissionStatus>();
|
||||
|
||||
public void CheckPermission() {
|
||||
statusText.text = "Checking permission....";
|
||||
GvrPermissionsRequester permissionRequester = GvrPermissionsRequester.Instance;
|
||||
if (permissionRequester != null) {
|
||||
bool granted = permissionRequester.IsPermissionGranted(permissionNames[0]);
|
||||
statusText.text = permissionNames[0] + ": " + (granted ? "Granted" : "Denied");
|
||||
} else {
|
||||
statusText.text = "Permission requester cannot be initialized.";
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestPermissions() {
|
||||
if (statusText != null) {
|
||||
statusText.text = "Requesting permission....";
|
||||
}
|
||||
GvrPermissionsRequester permissionRequester = GvrPermissionsRequester.Instance;
|
||||
if (permissionRequester == null) {
|
||||
statusText.text = "Permission requester cannot be initialized.";
|
||||
return;
|
||||
}
|
||||
Debug.Log("Permissions.RequestPermisions: Check if permission has been granted");
|
||||
if (!permissionRequester.IsPermissionGranted(permissionNames[0])) {
|
||||
Debug.Log("Permissions.RequestPermisions: Permission has not been previously granted");
|
||||
if (permissionRequester.ShouldShowRational(permissionNames[0])) {
|
||||
statusText.text = "This game needs to access external storage. Please grant permission when prompted.";
|
||||
statusText.color = Color.red;
|
||||
}
|
||||
permissionRequester.RequestPermissions(permissionNames,
|
||||
(GvrPermissionsRequester.PermissionStatus[] permissionResults) =>
|
||||
{
|
||||
statusText.color = Color.cyan;
|
||||
permissionList.Clear();
|
||||
permissionList.AddRange(permissionResults);
|
||||
string msg = "";
|
||||
foreach (GvrPermissionsRequester.PermissionStatus p in permissionList) {
|
||||
msg += p.Name + ": " + (p.Granted ? "Granted" : "Denied") + "\n";
|
||||
}
|
||||
statusText.text = msg;
|
||||
});
|
||||
}
|
||||
else {
|
||||
statusText.text = "ExternalStorage permission already granted!";
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // (UNITY_ANDROID || UNITY_EDITOR)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e8df902e7cb54f57bd1492b46fbe33d
|
||||
timeCreated: 1477353933
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/GoogleVR/Demos/Scripts/VideoDemo.meta
Normal file
8
Assets/GoogleVR/Demos/Scripts/VideoDemo.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77e0beb1a5b04964190423904685c545
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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