AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
PositionDebugButton.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 HoloToolkit.Unity;
5 using System.Collections;
6 using System.Collections.Generic;
7 using UnityEngine;
8 
9 namespace HoloToolkit.Unity.SharingWithUNET
10 {
11  public class PositionDebugButton : SingleInstance<PositionDebugButton>
12  {
13 
14  public GameObject DisconnectedPosition { get; set; }
15  public GameObject ConnectedPosition { get; set; }
16 
17  NetworkDiscoveryWithAnchors networkDisco;
18 
19  // Use this for initialization
20  void Start()
21  {
22  transform.SetParent(DisconnectedPosition.transform, false);
24  networkDisco.ConnectionStatusChanged += NetworkDisco_ConnectionStatusChanged;
25  }
26 
27  private void NetworkDisco_ConnectionStatusChanged(object sender, System.EventArgs e)
28  {
29  MoveToRightSpot();
30  }
31 
32  void MoveToRightSpot()
33  {
34  GameObject parent = networkDisco.Connected ? ConnectedPosition : DisconnectedPosition;
35  if (parent == null)
36  {
37  Invoke("MoveToRightSpot", 0.1f);
38  return;
39  }
40 
41  transform.SetParent(parent.transform, false);
42  // this is a little hack because our parent might have disabled our renderers/colliders.
43  SetChildren(true);
44  }
45 
46  void SetChildren(bool Enabled)
47  {
48  foreach (Renderer mr in GetComponentsInChildren<Renderer>())
49  {
50  mr.enabled = Enabled;
51  }
52 
53  foreach (BoxCollider bc in GetComponentsInChildren<BoxCollider>())
54  {
55  bc.enabled = Enabled;
56  }
57  }
58  }
59 }
Inherits from UNet&#39;s NetworkDiscovery script. Adds automatic anchor management on discovery...
EventHandler< EventArgs > ConnectionStatusChanged
Event raised when connected or disconnected.
A simplified version of the Singleton class which doesn&#39;t depend on the Instance being set in Awake ...
bool Connected
Tracks if we are currently connected to a session.