Skip to content

Commit

Permalink
Merge pull request #2530 from Microsoft/june18_dev
Browse files Browse the repository at this point in the history
2017.4.1 Stabilization and Merge PR
  • Loading branch information
StephenHodgson committed Aug 1, 2018
2 parents 05d004f + 90355dd commit 3cb2b0e
Show file tree
Hide file tree
Showing 184 changed files with 25,164 additions and 7,495 deletions.
1,630 changes: 1,496 additions & 134 deletions Assets/HoloToolkit-Examples/Boundary/Scenes/BoundaryTest.unity

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Assets/HoloToolkit-Examples/Boundary/Scripts/BoundaryTest.cs
Expand Up @@ -7,7 +7,7 @@ namespace HoloToolkit.Unity.Boundary.Tests
{
public class BoundaryTest : MonoBehaviour
{
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
#if UNITY_2017_2_OR_NEWER
private Material[] defaultMaterials = null;

private void Start()
Expand All @@ -16,15 +16,17 @@ private void Start()
BoundaryManager.Instance.RenderFloor = true;

defaultMaterials = GetComponent<Renderer>().materials;

if (BoundaryManager.Instance.ContainsObject(gameObject.transform.position))

int colorPropertyId = Shader.PropertyToID("_Color");

if (BoundaryManager.Instance.ContainsObject(gameObject.transform.position, UnityEngine.Experimental.XR.Boundary.Type.TrackedArea))
{
Debug.LogFormat("Object {0} is within established boundary. Position: {1}", name, gameObject.transform.position);

for (int i = 0; i < defaultMaterials.Length; i++)
{
// Color the cube green if object is within specified boundary.
defaultMaterials[i].SetColor("_Color", Color.green);
defaultMaterials[i].SetColor(colorPropertyId, Color.green);
}
}
else
Expand All @@ -34,7 +36,7 @@ private void Start()
for (int i = 0; i < defaultMaterials.Length; i++)
{
// Color the cube red if object is outside specified boundary.
defaultMaterials[i].SetColor("_Color", Color.red);
defaultMaterials[i].SetColor(colorPropertyId, Color.red);
}
}
}
Expand Down
116 changes: 116 additions & 0 deletions Assets/HoloToolkit-Examples/Boundary/Scripts/BoundaryVisualizer.cs
@@ -0,0 +1,116 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;

namespace HoloToolkit.Unity.Boundary.Tests
{
/// <summary>
/// Demo class to show different ways of using the boundary API.
/// </summary>
public class BoundaryVisualizer : MonoBehaviour
{
#if UNITY_2017_2_OR_NEWER
[SerializeField]
[Tooltip("Material used to draw the inscribed rectangle bounds.")]
private Material boundsMaterial = null;

[SerializeField]
[Tooltip("Material used to draw items in the tracked area bounds.")]
private Material trackedAreaBoundsMaterial = null;

private void Start()
{
AddQuad();
AddIndicators();
}

/// <summary>
/// Displays the boundary as a quad primitive.
/// </summary>
private void AddQuad()
{
Vector3 center;
float angle;
float width;
float height;
BoundaryManager.Instance.TryGetBoundaryRectangleParams(out center, out angle, out width, out height);

var quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
quad.transform.SetParent(transform);
quad.transform.Translate(center + new Vector3(0.0f, 0.005f, 0.0f)); // Add fudge factor to avoid z-fighting
quad.transform.Rotate(new Vector3(90, -angle, 0));
quad.transform.localScale = new Vector3(width, height, 1.0f);
}

/// <summary>
/// Displays the boundary as a rectangle using a LineRenderer.
/// </summary>
private void AddRectangleBounds()
{
var points = BoundaryManager.Instance.TryGetBoundaryRectanglePoints();
if (points == null)
{
return;
}

LineRenderer lr = gameObject.AddComponent<LineRenderer>();
lr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
lr.useWorldSpace = false;
lr.loop = true;
lr.sharedMaterial = boundsMaterial;
lr.startWidth = 0.05f;
lr.endWidth = 0.05f;
lr.positionCount = points.Length;
lr.SetPositions(points);
}

/// <summary>
/// Displays the boundary as an array of spheres where spheres in the
/// bounds are a different color.
/// </summary>
private void AddIndicators()
{
const int indicatorCount = 15;
const float indicatorDistance = 0.2f;
const float dimension = indicatorCount * indicatorDistance;

Vector3 center;
float angle;
float width;
float height;
if (!BoundaryManager.Instance.TryGetBoundaryRectangleParams(out center, out angle, out width, out height))
{
return;
}

Vector3 corner = center - (new Vector3(dimension, 0.0f, dimension) / 2.0f);
corner.y += 0.05f;
for (int xIndex = 0; xIndex < indicatorCount; ++xIndex)
{
for (int yIndex = 0; yIndex < indicatorCount; ++yIndex)
{
var offset = new Vector3(xIndex * indicatorDistance, 0.0f, yIndex * indicatorDistance);
var position = corner + offset;
var marker = GameObject.CreatePrimitive(PrimitiveType.Sphere);
marker.transform.SetParent(transform);
marker.transform.position = position;
marker.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

var markerRenderer = marker.GetComponent<MeshRenderer>();

if (BoundaryManager.Instance.ContainsObject(position, UnityEngine.Experimental.XR.Boundary.Type.TrackedArea))
{
markerRenderer.sharedMaterial = trackedAreaBoundsMaterial;
}

if (BoundaryManager.Instance.ContainsObject(position, UnityEngine.Experimental.XR.Boundary.Type.PlayArea))
{
markerRenderer.sharedMaterial = boundsMaterial;
}
}
}
}
#endif
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Assets/HoloToolkit-Examples/Input/Scenes/InputManagerTest.unity
Expand Up @@ -1811,9 +1811,9 @@ MeshCollider:
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
serializedVersion: 3
m_Convex: 0
m_InflateMesh: 0
m_CookingOptions: 14
m_SkinWidth: 0.01
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!33 &481840526
Expand Down Expand Up @@ -2716,9 +2716,9 @@ MeshCollider:
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
serializedVersion: 3
m_Convex: 0
m_InflateMesh: 0
m_CookingOptions: 14
m_SkinWidth: 0.01
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &718516062
Expand Down Expand Up @@ -4259,7 +4259,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Activating this button, creates a popup that disables all other input until
m_Text: Activating this button, creates a popup that disables all other clicks until
the popup is dismissed.
--- !u!222 &1309489392
CanvasRenderer:
Expand Down Expand Up @@ -5915,7 +5915,7 @@ TextMesh:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1906609830}
m_Text: 'All other input is disabled
m_Text: 'All other clicks are disabled
until this popup is closed!'
m_OffsetZ: 0
Expand Down
54 changes: 22 additions & 32 deletions Assets/HoloToolkit-Examples/Input/Scripts/PopupMenu.cs
Expand Up @@ -6,7 +6,7 @@

namespace HoloToolkit.Unity.InputModule.Tests
{
public class PopupMenu : MonoBehaviour, IInputHandler
public class PopupMenu : MonoBehaviour
{
[SerializeField]
private TestButton cancelButton = null;
Expand All @@ -21,27 +21,34 @@ public class PopupMenu : MonoBehaviour, IInputHandler
private bool closeOnNonTargetedTap = false;

/// <summary>
/// Called when 'place' is selected
/// Called when 'place' is selected.
/// </summary>
private Action activatedCallback;

/// <summary>
/// Called when 'back' or 'hide' is selected
/// Called when 'back' or 'hide' is selected.
/// </summary>
private Action cancelledCallback;

/// <summary>
/// Called when the user clicks outside of the menu
/// Called when the user clicks outside of the menu.
/// </summary>
private Action deactivatedCallback;

private int dehydrateButtonId;

public PopupState CurrentPopupState = PopupState.Closed;

public enum PopupState { Open, Closed }

private void Awake()
{
gameObject.SetActive(false);

if (dehydrateButtonId == 0)
{
dehydrateButtonId = Animator.StringToHash("Dehydrate");
}
}

private void OnEnable()
Expand Down Expand Up @@ -71,23 +78,23 @@ public void Show(Action _activatedCallback = null, Action _cancelledCallback = n

if (isModal)
{
InputManager.Instance.PushModalInputHandler(gameObject);
InputManager.Instance.PushModalInputHandler(cancelButton.gameObject);
}

if (closeOnNonTargetedTap)
{
InputManager.Instance.PushFallbackInputHandler(gameObject);
InputManager.Instance.PushFallbackInputHandler(cancelButton.gameObject);
}

// the visual was activated via an interaction outside of the menu, let anyone who cares know
// The visual was activated via an interaction outside of the menu. Let anyone who cares know.
if (activatedCallback != null)
{
activatedCallback();
}
}

/// <summary>
/// Dismiss the details pane
/// Dismiss the details pane.
/// </summary>
public void Dismiss()
{
Expand Down Expand Up @@ -118,9 +125,9 @@ public void Dismiss()
}

// Deactivates the game object
if (rootAnimator.isInitialized)
if (rootAnimator != null && rootAnimator.isInitialized)
{
rootAnimator.SetTrigger("Dehydrate");
rootAnimator.SetTrigger(dehydrateButtonId);
}
else
{
Expand All @@ -130,32 +137,15 @@ public void Dismiss()

private void OnCancelPressed(TestButton source)
{
if (cancelledCallback != null)
if (cancelButton.Focused || closeOnNonTargetedTap)
{
cancelledCallback();
}
if (cancelledCallback != null)
{
cancelledCallback();
}

Dismiss();
}

void IInputHandler.OnInputDown(InputEventData eventData)
{
if (closeOnNonTargetedTap)
{
Dismiss();
}

eventData.Use(); // Mark the event as used, so it doesn't fall through to other handlers.
}

void IInputHandler.OnInputUp(InputEventData eventData)
{
if (closeOnNonTargetedTap)
{
Dismiss();
}

eventData.Use(); // Mark the event as used, so it doesn't fall through to other handlers.
}
}
}

0 comments on commit 3cb2b0e

Please sign in to comment.