Added VR libraries
This commit is contained in:
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:
|
||||
Reference in New Issue
Block a user