AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
StartSessionButton.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;
5 
6 namespace HoloToolkit.Unity.SharingWithUNET
7 {
11  public class StartSessionButton : MonoBehaviour, IInputClickHandler
12  {
16  private NetworkDiscoveryWithAnchors networkDiscovery;
17 
18  private void Start()
19  {
20  networkDiscovery = NetworkDiscoveryWithAnchors.Instance;
21 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
22  if (UnityEngine.XR.WSA.HolographicSettings.IsDisplayOpaque && !Application.isEditor)
23  {
24  Debug.Log("Only HoloLens can host for now");
25  Destroy(gameObject);
26  }
27 #else
28  if (Application.isEditor)
29  {
30  Debug.Log("Only HoloLens can host for now");
31  Destroy(gameObject);
32  }
33 #endif
34  }
35 
40  public void OnInputClicked(InputClickedEventData eventData)
41  {
42  if (networkDiscovery.running)
43  {
44  // Only let HoloLens host
45  // We are also allowing the editor to host for testing purposes, but shared anchors
46  // will currently not work in this mode.
47 
48  if (
49 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
50  !UnityEngine.XR.WSA.HolographicSettings.IsDisplayOpaque ||
51 #endif
52  Application.isEditor)
53  {
54  if (Application.isEditor)
55  {
56  Debug.Log("Unity editor can host, but World Anchors will not be shared");
57  }
58 
59  networkDiscovery.StartHosting("DefaultName");
60  eventData.Use();
61  }
62  }
63  }
64  }
65 }
Inherits from UNet's NetworkDiscovery script. Adds automatic anchor management on discovery...
Starts a session when the user taps the control this script is attached to.
Interface to implement to react to simple click input.
void StartHosting(string SessionName)
Call to create a session
Describes an input event that involves a tap.
void OnInputClicked(InputClickedEventData eventData)
Called when a click event is detected