AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
BoundaryTest.cs
Go to the documentation of this file.
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  public class BoundaryTest : MonoBehaviour
9  {
10 #if UNITY_2017_2_OR_NEWER
11  private Material[] defaultMaterials = null;
12 
13  private void Start()
14  {
15  BoundaryManager.Instance.RenderBoundary = true;
16  BoundaryManager.Instance.RenderFloor = true;
17 
18  defaultMaterials = GetComponent<Renderer>().materials;
19 
20  int colorPropertyId = Shader.PropertyToID("_Color");
21 
22  if (BoundaryManager.Instance.ContainsObject(gameObject.transform.position, UnityEngine.Experimental.XR.Boundary.Type.TrackedArea))
23  {
24  Debug.LogFormat("Object {0} is within established boundary. Position: {1}", name, gameObject.transform.position);
25 
26  for (int i = 0; i < defaultMaterials.Length; i++)
27  {
28  // Color the cube green if object is within specified boundary.
29  defaultMaterials[i].SetColor(colorPropertyId, Color.green);
30  }
31  }
32  else
33  {
34  Debug.LogFormat("Object {0} is outside established boundary. Position: {1}", name, gameObject.transform.position);
35 
36  for (int i = 0; i < defaultMaterials.Length; i++)
37  {
38  // Color the cube red if object is outside specified boundary.
39  defaultMaterials[i].SetColor(colorPropertyId, Color.red);
40  }
41  }
42  }
43 
44  private void OnDestroy()
45  {
46  for (int i = 0; i < defaultMaterials.Length; i++)
47  {
48  Destroy(defaultMaterials[i]);
49  }
50  }
51 #endif
52  }
53 }
Places a floor quad to ground the scene. Allows you to check if your GameObject is within setup bound...
static T Instance
Returns the Singleton instance of the classes type. If no instance is found, then we search for an in...
Definition: Singleton.cs:26