AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SessionListButton.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 {
12  public class SessionListButton : MonoBehaviour, IInputClickHandler
13  {
17  private NetworkDiscoveryWithAnchors.SessionInfo SessionInfo;
18 
22  private int textColorId;
23 
27  private TextMesh textMesh;
28 
32  private Material textMaterial;
33 
37  private ScrollingSessionListUIController scrollingUIController;
38 
42  private void Awake()
43  {
44  textMesh = gameObject.GetComponentInChildren<TextMesh>();
45  textMaterial = textMesh.GetComponent<MeshRenderer>().material;
46  textColorId = Shader.PropertyToID("_Color");
47  scrollingUIController = ScrollingSessionListUIController.Instance;
48  if (scrollingUIController == null)
49  {
50  Debug.Log("without a scrolling UI control, this button can't work");
51  Destroy(this);
52  }
53  }
54 
58  private void OnDestroy()
59  {
60  if (textMaterial != null)
61  {
62  Destroy(textMaterial);
63  textMaterial = null;
64  }
65  }
66 
72  {
73  SessionInfo = sessionInfo;
74  if (SessionInfo != null)
75  {
76  textMesh.text = string.Format("{0}\n{1}", SessionInfo.SessionName, SessionInfo.SessionIp);
77  if (SessionInfo == scrollingUIController.SelectedSession)
78  {
79  textMaterial.SetColor(textColorId, Color.blue);
80 
81  textMesh.color = Color.blue;
82  }
83  else
84  {
85  textMaterial.SetColor(textColorId, Color.yellow);
86  textMesh.color = Color.yellow;
87  }
88  }
89  }
90 
96  public void OnInputClicked(InputClickedEventData eventData)
97  {
98  scrollingUIController.SetSelectedSession(SessionInfo);
99  eventData.Use();
100  }
101  }
102 }
void SetSessionInfo(NetworkDiscoveryWithAnchors.SessionInfo sessionInfo)
Sets the session information associated with this button
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.
Interface to implement to react to simple click input.
void OnInputClicked(InputClickedEventData eventData)
When the user clicks a session this will route that information to the scrolling UI control so it kno...
Represents a button on a list of sessions. Tapping the button indicates the selected session ...
Describes an input event that involves a tap.
void SetSelectedSession(NetworkDiscoveryWithAnchors.SessionInfo sessionInfo)
Sets the selected session