AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SharedAnchorDebugText.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 using UnityEngine;
4 
5 namespace HoloToolkit.Unity.SharingWithUNET
6 {
10  public class SharedAnchorDebugText : MonoBehaviour
11  {
12 
18 
22  private TextMesh textMesh;
23 
29  private bool wasClient = false;
30  private bool wasServer = false;
31  private string ServerIp = "";
32  private bool anchorEstablished = false;
33  private bool wasImporting = false;
34  private bool wasDownloading = false;
35  private string anchorName = "";
36 
40  private UNetAnchorManager anchorManager;
41 
42  private void Start()
43  {
44  textMesh = GetComponent<TextMesh>();
45  anchorManager = UNetAnchorManager.Instance;
46  UpdateText();
47  }
48 
49  private void Update()
50  {
51  if (anchorManager == null)
52  {
53  anchorManager = UNetAnchorManager.Instance;
54  }
55 
56  bool dirty = false;
57  if (wasClient != NetworkDiscoveryObject.isClient)
58  {
59  Debug.Log("Was client changed to " + NetworkDiscoveryObject.isClient);
60  wasClient = NetworkDiscoveryObject.isClient;
61  dirty = true;
62  }
63 
64  if (wasServer != NetworkDiscoveryObject.isServer)
65  {
66  wasServer = NetworkDiscoveryObject.isServer;
67  dirty = true;
68  }
69 
70  if (ServerIp != NetworkDiscoveryObject.ServerIp)
71  {
72  ServerIp = NetworkDiscoveryObject.ServerIp;
73  dirty = true;
74  }
75 
76  // Anchor manger doesn't come online until we connect
77  if (anchorManager != null)
78  {
79 
80  if (anchorEstablished != anchorManager.AnchorEstablished)
81  {
82  anchorEstablished = anchorManager.AnchorEstablished;
83  dirty = true;
84  }
85 
86  if (anchorName != anchorManager.AnchorName)
87  {
88  anchorName = anchorManager.AnchorName;
89  dirty = true;
90  }
91 
92  if (wasImporting != anchorManager.ImportInProgress)
93  {
94  wasImporting = anchorManager.ImportInProgress;
95  dirty = true;
96  }
97 
98  if (wasDownloading != anchorManager.DownloadingAnchor)
99  {
100  wasDownloading = anchorManager.DownloadingAnchor;
101  dirty = true;
102  }
103  }
104 
105  if (dirty)
106  {
107  UpdateText();
108  }
109  }
110 
111  private void UpdateText()
112  {
113  textMesh.text = string.Format(
114  "{0}{1}{2}\n{3}{4}\n",
115  wasClient ? "Client\n" : "",
116  wasServer ? "Server\n" : "",
117  ServerIp,
118  anchorEstablished ? "Anchored Here\n" : (wasImporting ? "Importing\n" : (wasDownloading ? "Downloading\n" : "Not Anchored\n")),
119  anchorName);
120  }
121  }
122 }
Inherits from UNet&#39;s NetworkDiscovery script. Adds automatic anchor management on discovery...
bool AnchorEstablished
Tracks if we have a shared anchor established
Creates, exports, and imports anchors as required.
bool ImportInProgress
Tracks if an import is in flight.
string ServerIp
Keeps track of the IP address of the system that sent the broadcast. We will use this IP address to c...
NetworkDiscoveryWithAnchors NetworkDiscoveryObject
Set in the editor with the network discovery object since we query that object for much of our text...
bool DownloadingAnchor
Tracks if a download is in flight.
It is nice to know what is going on with the networking scene sometimes.
string AnchorName
Keeps track of the name of the world anchor to use.