AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
JoinSelectedSessionButton.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;
6 
7 namespace HoloToolkit.Unity.SharingWithUNET
8 {
9 
10  public class JoinSelectedSessionButton : MonoBehaviour, IInputClickHandler
11  {
15  private int textColorId;
16 
20  private TextMesh textMesh;
21 
25  private Material textMaterial;
26 
30  private ScrollingSessionListUIController scrollingUIControl;
31 
35  private NetworkDiscoveryWithAnchors networkDiscovery;
36 
37  private void Start()
38  {
39  scrollingUIControl = ScrollingSessionListUIController.Instance;
40  textMesh = transform.parent.GetComponentInChildren<TextMesh>();
41  textMaterial = textMesh.GetComponent<MeshRenderer>().material;
42  textColorId = Shader.PropertyToID("_Color");
43  textMaterial.SetColor(textColorId, Color.grey);
44  networkDiscovery = NetworkDiscoveryWithAnchors.Instance;
45  }
46 
47  private void Update()
48  {
49  // If we are the client and have a selected session make the button text blue,
50  // otherwise make the button text grey to indicate that the button is inactive.
51  if (networkDiscovery.running && networkDiscovery.isClient)
52  {
53  if (scrollingUIControl.SelectedSession != null)
54  {
55  textMaterial.SetColor(textColorId, Color.blue);
56  }
57  else
58  {
59  textMaterial.SetColor(textColorId, Color.grey);
60  }
61  }
62  else
63  {
64  textMaterial.SetColor(textColorId, Color.grey);
65  }
66  }
67 
71  private void OnDestroy()
72  {
73  if (textMaterial != null)
74  {
75  Destroy(textMaterial);
76  textMaterial = null;
77  }
78  }
79 
84  public void OnInputClicked(InputClickedEventData eventData)
85  {
86  ScrollingSessionListUIController.Instance.JoinSelectedSession();
87  eventData.Use();
88  }
89  }
90 }
Inherits from UNet&#39;s NetworkDiscovery script. Adds automatic anchor management on discovery...
NetworkDiscoveryWithAnchors.SessionInfo SelectedSession
Keeps track of the session the user has currently selected.
void OnInputClicked(InputClickedEventData eventData)
When the button is clicked try to join the selected session
Interface to implement to react to simple click input.
Describes an input event that involves a tap.