Skip to content

Commit 3cb2b0e

Browse files
Merge pull request #2530 from Microsoft/june18_dev
2017.4.1 Stabilization and Merge PR
2 parents 05d004f + 90355dd commit 3cb2b0e

File tree

184 files changed

+25164
-7495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+25164
-7495
lines changed

Assets/HoloToolkit-Examples/Boundary/Scenes/BoundaryTest.unity

+1,496-134
Large diffs are not rendered by default.

Assets/HoloToolkit-Examples/Boundary/Scripts/BoundaryTest.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace HoloToolkit.Unity.Boundary.Tests
77
{
88
public class BoundaryTest : MonoBehaviour
99
{
10-
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
10+
#if UNITY_2017_2_OR_NEWER
1111
private Material[] defaultMaterials = null;
1212

1313
private void Start()
@@ -16,15 +16,17 @@ private void Start()
1616
BoundaryManager.Instance.RenderFloor = true;
1717

1818
defaultMaterials = GetComponent<Renderer>().materials;
19-
20-
if (BoundaryManager.Instance.ContainsObject(gameObject.transform.position))
19+
20+
int colorPropertyId = Shader.PropertyToID("_Color");
21+
22+
if (BoundaryManager.Instance.ContainsObject(gameObject.transform.position, UnityEngine.Experimental.XR.Boundary.Type.TrackedArea))
2123
{
2224
Debug.LogFormat("Object {0} is within established boundary. Position: {1}", name, gameObject.transform.position);
2325

2426
for (int i = 0; i < defaultMaterials.Length; i++)
2527
{
2628
// Color the cube green if object is within specified boundary.
27-
defaultMaterials[i].SetColor("_Color", Color.green);
29+
defaultMaterials[i].SetColor(colorPropertyId, Color.green);
2830
}
2931
}
3032
else
@@ -34,7 +36,7 @@ private void Start()
3436
for (int i = 0; i < defaultMaterials.Length; i++)
3537
{
3638
// Color the cube red if object is outside specified boundary.
37-
defaultMaterials[i].SetColor("_Color", Color.red);
39+
defaultMaterials[i].SetColor(colorPropertyId, Color.red);
3840
}
3941
}
4042
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using UnityEngine;
5+
6+
namespace HoloToolkit.Unity.Boundary.Tests
7+
{
8+
/// <summary>
9+
/// Demo class to show different ways of using the boundary API.
10+
/// </summary>
11+
public class BoundaryVisualizer : MonoBehaviour
12+
{
13+
#if UNITY_2017_2_OR_NEWER
14+
[SerializeField]
15+
[Tooltip("Material used to draw the inscribed rectangle bounds.")]
16+
private Material boundsMaterial = null;
17+
18+
[SerializeField]
19+
[Tooltip("Material used to draw items in the tracked area bounds.")]
20+
private Material trackedAreaBoundsMaterial = null;
21+
22+
private void Start()
23+
{
24+
AddQuad();
25+
AddIndicators();
26+
}
27+
28+
/// <summary>
29+
/// Displays the boundary as a quad primitive.
30+
/// </summary>
31+
private void AddQuad()
32+
{
33+
Vector3 center;
34+
float angle;
35+
float width;
36+
float height;
37+
BoundaryManager.Instance.TryGetBoundaryRectangleParams(out center, out angle, out width, out height);
38+
39+
var quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
40+
quad.transform.SetParent(transform);
41+
quad.transform.Translate(center + new Vector3(0.0f, 0.005f, 0.0f)); // Add fudge factor to avoid z-fighting
42+
quad.transform.Rotate(new Vector3(90, -angle, 0));
43+
quad.transform.localScale = new Vector3(width, height, 1.0f);
44+
}
45+
46+
/// <summary>
47+
/// Displays the boundary as a rectangle using a LineRenderer.
48+
/// </summary>
49+
private void AddRectangleBounds()
50+
{
51+
var points = BoundaryManager.Instance.TryGetBoundaryRectanglePoints();
52+
if (points == null)
53+
{
54+
return;
55+
}
56+
57+
LineRenderer lr = gameObject.AddComponent<LineRenderer>();
58+
lr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
59+
lr.useWorldSpace = false;
60+
lr.loop = true;
61+
lr.sharedMaterial = boundsMaterial;
62+
lr.startWidth = 0.05f;
63+
lr.endWidth = 0.05f;
64+
lr.positionCount = points.Length;
65+
lr.SetPositions(points);
66+
}
67+
68+
/// <summary>
69+
/// Displays the boundary as an array of spheres where spheres in the
70+
/// bounds are a different color.
71+
/// </summary>
72+
private void AddIndicators()
73+
{
74+
const int indicatorCount = 15;
75+
const float indicatorDistance = 0.2f;
76+
const float dimension = indicatorCount * indicatorDistance;
77+
78+
Vector3 center;
79+
float angle;
80+
float width;
81+
float height;
82+
if (!BoundaryManager.Instance.TryGetBoundaryRectangleParams(out center, out angle, out width, out height))
83+
{
84+
return;
85+
}
86+
87+
Vector3 corner = center - (new Vector3(dimension, 0.0f, dimension) / 2.0f);
88+
corner.y += 0.05f;
89+
for (int xIndex = 0; xIndex < indicatorCount; ++xIndex)
90+
{
91+
for (int yIndex = 0; yIndex < indicatorCount; ++yIndex)
92+
{
93+
var offset = new Vector3(xIndex * indicatorDistance, 0.0f, yIndex * indicatorDistance);
94+
var position = corner + offset;
95+
var marker = GameObject.CreatePrimitive(PrimitiveType.Sphere);
96+
marker.transform.SetParent(transform);
97+
marker.transform.position = position;
98+
marker.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
99+
100+
var markerRenderer = marker.GetComponent<MeshRenderer>();
101+
102+
if (BoundaryManager.Instance.ContainsObject(position, UnityEngine.Experimental.XR.Boundary.Type.TrackedArea))
103+
{
104+
markerRenderer.sharedMaterial = trackedAreaBoundsMaterial;
105+
}
106+
107+
if (BoundaryManager.Instance.ContainsObject(position, UnityEngine.Experimental.XR.Boundary.Type.PlayArea))
108+
{
109+
markerRenderer.sharedMaterial = boundsMaterial;
110+
}
111+
}
112+
}
113+
}
114+
#endif
115+
}
116+
}

Assets/HoloToolkit-Examples/Boundary/Scripts/BoundaryVisualizer.cs.meta

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/HoloToolkit-Examples/Input/Scenes/InputManagerTest.unity

+6-6
Original file line numberDiff line numberDiff line change
@@ -1811,9 +1811,9 @@ MeshCollider:
18111811
m_Material: {fileID: 0}
18121812
m_IsTrigger: 0
18131813
m_Enabled: 1
1814-
serializedVersion: 2
1814+
serializedVersion: 3
18151815
m_Convex: 0
1816-
m_InflateMesh: 0
1816+
m_CookingOptions: 14
18171817
m_SkinWidth: 0.01
18181818
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
18191819
--- !u!33 &481840526
@@ -2716,9 +2716,9 @@ MeshCollider:
27162716
m_Material: {fileID: 0}
27172717
m_IsTrigger: 0
27182718
m_Enabled: 1
2719-
serializedVersion: 2
2719+
serializedVersion: 3
27202720
m_Convex: 0
2721-
m_InflateMesh: 0
2721+
m_CookingOptions: 14
27222722
m_SkinWidth: 0.01
27232723
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
27242724
--- !u!23 &718516062
@@ -4259,7 +4259,7 @@ MonoBehaviour:
42594259
m_HorizontalOverflow: 0
42604260
m_VerticalOverflow: 0
42614261
m_LineSpacing: 1
4262-
m_Text: Activating this button, creates a popup that disables all other input until
4262+
m_Text: Activating this button, creates a popup that disables all other clicks until
42634263
the popup is dismissed.
42644264
--- !u!222 &1309489392
42654265
CanvasRenderer:
@@ -5915,7 +5915,7 @@ TextMesh:
59155915
m_PrefabParentObject: {fileID: 0}
59165916
m_PrefabInternal: {fileID: 0}
59175917
m_GameObject: {fileID: 1906609830}
5918-
m_Text: 'All other input is disabled
5918+
m_Text: 'All other clicks are disabled
59195919
59205920
until this popup is closed!'
59215921
m_OffsetZ: 0

Assets/HoloToolkit-Examples/Input/Scripts/PopupMenu.cs

+22-32
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace HoloToolkit.Unity.InputModule.Tests
88
{
9-
public class PopupMenu : MonoBehaviour, IInputHandler
9+
public class PopupMenu : MonoBehaviour
1010
{
1111
[SerializeField]
1212
private TestButton cancelButton = null;
@@ -21,27 +21,34 @@ public class PopupMenu : MonoBehaviour, IInputHandler
2121
private bool closeOnNonTargetedTap = false;
2222

2323
/// <summary>
24-
/// Called when 'place' is selected
24+
/// Called when 'place' is selected.
2525
/// </summary>
2626
private Action activatedCallback;
2727

2828
/// <summary>
29-
/// Called when 'back' or 'hide' is selected
29+
/// Called when 'back' or 'hide' is selected.
3030
/// </summary>
3131
private Action cancelledCallback;
3232

3333
/// <summary>
34-
/// Called when the user clicks outside of the menu
34+
/// Called when the user clicks outside of the menu.
3535
/// </summary>
3636
private Action deactivatedCallback;
3737

38+
private int dehydrateButtonId;
39+
3840
public PopupState CurrentPopupState = PopupState.Closed;
3941

4042
public enum PopupState { Open, Closed }
4143

4244
private void Awake()
4345
{
4446
gameObject.SetActive(false);
47+
48+
if (dehydrateButtonId == 0)
49+
{
50+
dehydrateButtonId = Animator.StringToHash("Dehydrate");
51+
}
4552
}
4653

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

7279
if (isModal)
7380
{
74-
InputManager.Instance.PushModalInputHandler(gameObject);
81+
InputManager.Instance.PushModalInputHandler(cancelButton.gameObject);
7582
}
7683

7784
if (closeOnNonTargetedTap)
7885
{
79-
InputManager.Instance.PushFallbackInputHandler(gameObject);
86+
InputManager.Instance.PushFallbackInputHandler(cancelButton.gameObject);
8087
}
8188

82-
// the visual was activated via an interaction outside of the menu, let anyone who cares know
89+
// The visual was activated via an interaction outside of the menu. Let anyone who cares know.
8390
if (activatedCallback != null)
8491
{
8592
activatedCallback();
8693
}
8794
}
8895

8996
/// <summary>
90-
/// Dismiss the details pane
97+
/// Dismiss the details pane.
9198
/// </summary>
9299
public void Dismiss()
93100
{
@@ -118,9 +125,9 @@ public void Dismiss()
118125
}
119126

120127
// Deactivates the game object
121-
if (rootAnimator.isInitialized)
128+
if (rootAnimator != null && rootAnimator.isInitialized)
122129
{
123-
rootAnimator.SetTrigger("Dehydrate");
130+
rootAnimator.SetTrigger(dehydrateButtonId);
124131
}
125132
else
126133
{
@@ -130,32 +137,15 @@ public void Dismiss()
130137

131138
private void OnCancelPressed(TestButton source)
132139
{
133-
if (cancelledCallback != null)
140+
if (cancelButton.Focused || closeOnNonTargetedTap)
134141
{
135-
cancelledCallback();
136-
}
142+
if (cancelledCallback != null)
143+
{
144+
cancelledCallback();
145+
}
137146

138-
Dismiss();
139-
}
140-
141-
void IInputHandler.OnInputDown(InputEventData eventData)
142-
{
143-
if (closeOnNonTargetedTap)
144-
{
145147
Dismiss();
146148
}
147-
148-
eventData.Use(); // Mark the event as used, so it doesn't fall through to other handlers.
149-
}
150-
151-
void IInputHandler.OnInputUp(InputEventData eventData)
152-
{
153-
if (closeOnNonTargetedTap)
154-
{
155-
Dismiss();
156-
}
157-
158-
eventData.Use(); // Mark the event as used, so it doesn't fall through to other handlers.
159149
}
160150
}
161151
}

0 commit comments

Comments
 (0)