Added VR libraries

This commit is contained in:
Chris Midkiff
2018-10-08 23:54:11 -04:00
parent d9eb2a9763
commit 7ce1036e39
1037 changed files with 195630 additions and 348 deletions

View File

@@ -0,0 +1,141 @@
// 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.
using UnityEngine;
using UnityEditor;
using System.Collections;
/// Custom editor for GvrControllerVisual.
/// Enhances the visualization of the displayState and ensures that it can only be edited
/// if the application isn't playing or if readControllerState is turned off.
[CustomEditor(typeof(GvrControllerVisual)), CanEditMultipleObjects]
public class GvrControllerVisualEditor : Editor {
private SerializedProperty attachmentPrefabs;
private SerializedProperty touchPadColor;
private SerializedProperty appButtonColor;
private SerializedProperty systemButtonColor;
private SerializedProperty readControllerState;
private SerializedProperty displayState;
private SerializedProperty maximumAlpha;
private GUIStyle displayStateHeaderStyle;
private GUIContent displayStateHeaderContent;
private float displayStateHeaderHeight;
private const string DISPLAY_STATE_HEADER_TEXT = "DisplayState:";
private const string DISPLAY_STATE_ITEM_PREFIX = "• ";
private const int DISPLAY_STATE_HEADER_FONT_SIZE_OFFSET = 2;
private const string ATTACHMENT_PREFABS_PROP_NAME = "attachmentPrefabs";
private const string TOUCH_PAD_COLOR_PROP_NAME = "touchPadColor";
private const string APP_BUTTON_COLOR_PROP_NAME = "appButtonColor";
private const string SYSTEM_BUTTON_COLOR_PROP_NAME = "systemButtonColor";
private const string READ_CONTROLLER_STATE_PROP_NAME = "readControllerState";
private const string DISPLAY_STATE_PROP_NAME = "displayState";
private const string MAXIMUM_ALPHA_PROP_NAME = "maximumAlpha";
void OnEnable() {
attachmentPrefabs = serializedObject.FindProperty(ATTACHMENT_PREFABS_PROP_NAME);
touchPadColor = serializedObject.FindProperty(TOUCH_PAD_COLOR_PROP_NAME);
appButtonColor = serializedObject.FindProperty(APP_BUTTON_COLOR_PROP_NAME);
systemButtonColor = serializedObject.FindProperty(SYSTEM_BUTTON_COLOR_PROP_NAME);
readControllerState = serializedObject.FindProperty(READ_CONTROLLER_STATE_PROP_NAME);
displayState = serializedObject.FindProperty(DISPLAY_STATE_PROP_NAME);
maximumAlpha = serializedObject.FindProperty(MAXIMUM_ALPHA_PROP_NAME);
}
public override void OnInspectorGUI() {
serializedObject.Update();
// Add clickable script field, as would have been provided by DrawDefaultInspector()
MonoScript script = MonoScript.FromMonoBehaviour (target as MonoBehaviour);
EditorGUI.BeginDisabledGroup (true);
EditorGUILayout.ObjectField ("Script", script, typeof(MonoScript), false);
EditorGUI.EndDisabledGroup ();
CreateStylesAndContent();
// Show all properties except for display state.
EditorGUILayout.PropertyField(attachmentPrefabs, true);
EditorGUILayout.PropertyField(touchPadColor);
EditorGUILayout.PropertyField(appButtonColor);
EditorGUILayout.PropertyField(systemButtonColor);
EditorGUILayout.PropertyField(readControllerState);
// Determine if the display state can currently be edited in the inspector.
bool allowEditDisplayState = !readControllerState.boolValue || !Application.isPlaying;
if (!allowEditDisplayState) {
// Prevents editing the display state in the inspector.
GUI.enabled = false;
}
Rect displayStateRect = EditorGUILayout.BeginVertical();
GUI.Box(displayStateRect, "");
// Show the display state header.
EditorGUILayout.LabelField(displayStateHeaderContent,
displayStateHeaderStyle,
GUILayout.Height(displayStateHeaderHeight));
// Indent the display state properties.
EditorGUI.indentLevel++;
// Iterate through the child properties of the displayState property.
SerializedProperty iter = displayState.Copy();
SerializedProperty nextElement = displayState.Copy();
bool hasNextElement = nextElement.Next(false);
iter.NextVisible(true);
do {
// It iter is the same as nextElement, then the iter has moved beyond the children of the
// display state which means it has finished showing the display state.
if (hasNextElement && SerializedProperty.EqualContents(nextElement, iter)) {
break;
}
GUIContent content = new GUIContent(DISPLAY_STATE_ITEM_PREFIX + iter.displayName);
EditorGUILayout.PropertyField(iter, content);
} while (iter.NextVisible(false));
// End the vertical region and draw the box.
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.EndVertical();
// Reset GUI.enabled.
if (!allowEditDisplayState) {
GUI.enabled = true;
}
EditorGUILayout.PropertyField(maximumAlpha);
serializedObject.ApplyModifiedProperties();
}
private void CreateStylesAndContent() {
if (displayStateHeaderContent == null) {
displayStateHeaderContent = new GUIContent(DISPLAY_STATE_HEADER_TEXT);
}
if (displayStateHeaderStyle == null) {
displayStateHeaderStyle = new GUIStyle(EditorStyles.boldLabel);
displayStateHeaderStyle.fontSize =
displayStateHeaderStyle.font.fontSize + DISPLAY_STATE_HEADER_FONT_SIZE_OFFSET;
displayStateHeaderHeight = displayStateHeaderStyle.CalcSize(displayStateHeaderContent).y;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 05d7d64713447433b86cb9a4e3d48560
timeCreated: 1498249337
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,143 @@
// 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.
using UnityEngine;
using UnityEditor;
/// Custom editor for GvrLaserPointer.
/// Adds buttons that allows user's to set the recommended default values for the different
/// raycast modes.
[CustomEditor(typeof(GvrLaserPointer)), CanEditMultipleObjects]
public class GvrLaserPointerEditor : Editor {
private SerializedProperty mode;
private SerializedProperty overridePointerCamera;
private SerializedProperty maxPointerDistance;
private SerializedProperty defaultReticleDistance;
private SerializedProperty rayIntersection;
private SerializedProperty drawDebugRays;
public const string RAYCAST_MODE_PROP_NAME = "raycastMode";
public const string OVERRIDE_POINTER_CAMERA_PROP_NAME = "overridePointerCamera";
public const string MAX_POINTER_DISTANCE_PROP_NAME = "maxPointerDistance";
public const string DEFAULT_RETICLE_DISTANCE_PROP_NAME = "defaultReticleDistance";
public const string RAY_INTERSECTION_PROP_NAME = "overrideCameraRayIntersectionDistance";
public const string DRAW_DEBUG_RAYS_PROP_NAME = "drawDebugRays";
void OnEnable() {
mode = serializedObject.FindProperty(RAYCAST_MODE_PROP_NAME);
overridePointerCamera = serializedObject.FindProperty(OVERRIDE_POINTER_CAMERA_PROP_NAME);
maxPointerDistance = serializedObject.FindProperty(MAX_POINTER_DISTANCE_PROP_NAME);
defaultReticleDistance = serializedObject.FindProperty(DEFAULT_RETICLE_DISTANCE_PROP_NAME);
rayIntersection = serializedObject.FindProperty(RAY_INTERSECTION_PROP_NAME);
drawDebugRays = serializedObject.FindProperty(DRAW_DEBUG_RAYS_PROP_NAME);
}
public override void OnInspectorGUI() {
serializedObject.Update();
// Add clickable script field, as would have been provided by DrawDefaultInspector()
MonoScript script = MonoScript.FromMonoBehaviour(target as MonoBehaviour);
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false);
EditorGUI.EndDisabledGroup();
Rect defaultsRect = EditorGUILayout.BeginVertical();
GUI.Box(defaultsRect, /* No label. */ "");
GUILayout.Space(3.0f);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Hybrid")) {
SetDefaultsForRaycastMode(GvrBasePointer.RaycastMode.Hybrid);
}
if (GUILayout.Button("Camera")) {
SetDefaultsForRaycastMode(GvrBasePointer.RaycastMode.Camera);
}
if (GUILayout.Button("Direct")) {
SetDefaultsForRaycastMode(GvrBasePointer.RaycastMode.Direct);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.HelpBox("Use the above Raycast Mode buttons to reset the following properties to their recommended values.\n\n" +
"GvrLaserPointer:\n" +
" • " + mode.displayName + "\n" +
" • " + rayIntersection.displayName + "\n\n" +
"GvrLaserVisual:\n" +
" • Max Laser Distance\n" +
" • Shrink Laser\n", MessageType.Info);
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
EditorGUILayout.PropertyField(maxPointerDistance);
EditorGUILayout.PropertyField(defaultReticleDistance);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Advanced:", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(mode);
EditorGUILayout.PropertyField(overridePointerCamera);
EditorGUILayout.PropertyField(rayIntersection);
EditorGUILayout.PropertyField(drawDebugRays);
serializedObject.ApplyModifiedProperties();
}
private void SetDefaultsForRaycastMode(GvrBasePointer.RaycastMode raycastMode) {
switch (raycastMode) {
case GvrBasePointer.RaycastMode.Hybrid:
mode.intValue = (int)raycastMode;
rayIntersection.floatValue = GvrVRHelpers.GetRayIntersection(raycastMode);
SetPropertiesForVisual(GvrVRHelpers.GetShrinkLaser(raycastMode), GvrVRHelpers.GetRecommendedMaxLaserDistance(raycastMode));
break;
case GvrBasePointer.RaycastMode.Camera:
mode.intValue = (int)raycastMode;
rayIntersection.floatValue = GvrVRHelpers.GetRayIntersection(raycastMode);
SetPropertiesForVisual(GvrVRHelpers.GetShrinkLaser(raycastMode), GvrVRHelpers.GetRecommendedMaxLaserDistance(raycastMode));
break;
case GvrBasePointer.RaycastMode.Direct:
mode.intValue = (int)raycastMode;
rayIntersection.floatValue = GvrVRHelpers.GetRayIntersection(raycastMode);
SetPropertiesForVisual(GvrVRHelpers.GetShrinkLaser(raycastMode), GvrVRHelpers.GetRecommendedMaxLaserDistance(raycastMode));
break;
default:
Debug.LogError("Trying to set defaults for invalid Raycast Mode: " + raycastMode);
return;
}
}
private void SetPropertiesForVisual(bool shrinkLaser, float maxLaserDistance) {
foreach (Object obj in serializedObject.targetObjects) {
GvrLaserVisual laserVisual = (obj as MonoBehaviour).GetComponent<GvrLaserVisual>();
if (laserVisual != null) {
SerializedObject serializedLaserVisual = new SerializedObject(laserVisual);
SerializedProperty serializedShrinkLaser =
serializedLaserVisual.FindProperty(GvrLaserVisualEditor.SHRINK_LASER_PROP_NAME);
serializedShrinkLaser.boolValue = shrinkLaser;
SerializedProperty serializedMaxLaserDistance =
serializedLaserVisual.FindProperty(GvrLaserVisualEditor.MAX_LASER_DISTANCE_PROP_NAME);
serializedMaxLaserDistance.floatValue = maxLaserDistance;
serializedLaserVisual.ApplyModifiedProperties();
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cc6e38fe705a640ba9cc80555465b13e
timeCreated: 1498249337
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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.
using UnityEngine;
using UnityEditor;
using System.Collections;
/// Custom editor for GvrLaserVisual.
/// Shows the relationship between the shrinkLaser property and other related properties.
[CustomEditor(typeof(GvrLaserVisual)), CanEditMultipleObjects]
public class GvrLaserVisualEditor : Editor {
private SerializedProperty laserColor;
private SerializedProperty laserColorEnd;
private SerializedProperty maxLaserDistance;
private SerializedProperty shrinkLaser;
private SerializedProperty shrunkScale;
private SerializedProperty beginShrinkAngleDegrees;
private SerializedProperty endShrinkAngleDegrees;
private SerializedProperty lerpSpeed;
private SerializedProperty lerpThreshold;
private SerializedProperty reticle;
private SerializedProperty controller;
public const string LASER_COLOR_PROP_NAME = "laserColor";
public const string LASER_COLOR_END_PROP_NAME = "laserColorEnd";
public const string MAX_LASER_DISTANCE_PROP_NAME = "maxLaserDistance";
public const string SHRINK_LASER_PROP_NAME = "shrinkLaser";
public const string SHURNK_SCALE_PROP_NAME = "shrunkScale";
public const string BEGIN_SHRINKING_ANGLE_DEGREES_PROP_NAME = "beginShrinkAngleDegrees";
public const string END_SHRINKING_ANGLE_DEGREES_PROP_NAME = "endShrinkAngleDegrees";
public const string LERP_SPEED_PROP_NAME = "lerpSpeed";
public const string LERP_THRESHOLD_PROP_NAME = "lerpThreshold";
public const string RETICLE_PROP_NAME = "reticle";
public const string CONTROLLER_PROP_NAME = "controller";
private const string ITEM_PREFIX = "• ";
void OnEnable() {
laserColor = serializedObject.FindProperty(LASER_COLOR_PROP_NAME);
laserColorEnd = serializedObject.FindProperty(LASER_COLOR_END_PROP_NAME);
maxLaserDistance = serializedObject.FindProperty(MAX_LASER_DISTANCE_PROP_NAME);
shrinkLaser = serializedObject.FindProperty(SHRINK_LASER_PROP_NAME);
shrunkScale = serializedObject.FindProperty(SHURNK_SCALE_PROP_NAME);
beginShrinkAngleDegrees = serializedObject.FindProperty(BEGIN_SHRINKING_ANGLE_DEGREES_PROP_NAME);
endShrinkAngleDegrees = serializedObject.FindProperty(END_SHRINKING_ANGLE_DEGREES_PROP_NAME);
lerpSpeed = serializedObject.FindProperty(LERP_SPEED_PROP_NAME);
lerpThreshold = serializedObject.FindProperty(LERP_THRESHOLD_PROP_NAME);
reticle = serializedObject.FindProperty(RETICLE_PROP_NAME);
controller = serializedObject.FindProperty(CONTROLLER_PROP_NAME);
}
public override void OnInspectorGUI() {
serializedObject.Update();
// Add clickable script field, as would have been provided by DrawDefaultInspector()
MonoScript script = MonoScript.FromMonoBehaviour(target as MonoBehaviour);
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false);
EditorGUI.EndDisabledGroup();
// Show properties for the laser visual.
EditorGUILayout.PropertyField(reticle);
EditorGUILayout.PropertyField(controller);
EditorGUILayout.PropertyField(laserColor);
EditorGUILayout.PropertyField(laserColorEnd);
EditorGUILayout.PropertyField(maxLaserDistance);
EditorGUILayout.PropertyField(lerpSpeed);
EditorGUILayout.PropertyField(lerpThreshold);
EditorGUILayout.PropertyField(shrinkLaser);
// Show properties for shrinking animation. Only enabled if shrinkLaser is enabled.
if (!shrinkLaser.boolValue) {
GUI.enabled = false;
}
EditorGUI.indentLevel++;
Rect shrinkLaserRect = EditorGUILayout.BeginVertical();
shrinkLaserRect = EditorGUI.IndentedRect(shrinkLaserRect);
GUI.Box(shrinkLaserRect, "");
EditorGUILayout.Space();
EditorGUILayout.PropertyField(shrunkScale,
new GUIContent(ITEM_PREFIX + shrunkScale.displayName));
EditorGUILayout.PropertyField(beginShrinkAngleDegrees,
new GUIContent(ITEM_PREFIX + beginShrinkAngleDegrees.displayName));
EditorGUILayout.PropertyField(endShrinkAngleDegrees,
new GUIContent(ITEM_PREFIX + endShrinkAngleDegrees.displayName));
EditorGUILayout.Space();
EditorGUILayout.EndVertical();
EditorGUI.indentLevel--;
if (!shrinkLaser.boolValue) {
GUI.enabled = true;
}
EditorGUILayout.Space();
serializedObject.ApplyModifiedProperties();
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 66fe40e11a2514648906e6825b026b85
timeCreated: 1498249337
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
// 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.
using UnityEngine;
using UnityEditor;
/// A custom editor for the GvrTooltip script. It exists to surface to the user that the tooltip
/// changes based on handedness, and to make it easy to preview the handedness settings.
[CustomEditor(typeof(GvrTooltip)), CanEditMultipleObjects]
public class GvrTooltipEditor : Editor {
public override void OnInspectorGUI() {
DrawDefaultInspector();
EditorGUILayout.LabelField("Current Handedness", GvrSettings.Handedness.ToString(), EditorStyles.boldLabel);
if (GUILayout.Button("Change Handedness")) {
EditorWindow.GetWindow(typeof(GvrEditorSettings));
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 23485e28fa60c463f8235998a0e76e6a
timeCreated: 1482187746
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: