Skip to content

Commit 8d4af16

Browse files
fixed some members not being renamed properly in last pr
1 parent e491011 commit 8d4af16

File tree

2 files changed

+62
-63
lines changed

2 files changed

+62
-63
lines changed

Assets/HoloToolkit-Examples/SharingWithUNET/Scripts/GenericNetworkTransmitter.cs

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
using System;
54
using UnityEngine;
65
using HoloToolkit.Unity;
76

@@ -46,6 +45,23 @@ public class GenericNetworkTransmitter : Singleton<GenericNetworkTransmitter>
4645
/// </summary>
4746
private byte[] mostRecentDataBuffer;
4847

48+
#if !UNITY_EDITOR && UNITY_WSA
49+
/// <summary>
50+
/// Tracks the network connection to the remote machine we are sending meshes to.
51+
/// </summary>
52+
private StreamSocket networkConnection;
53+
54+
/// <summary>
55+
/// If we are running as the server, this is the listener the server will use.
56+
/// </summary>
57+
private StreamSocketListener networkListener;
58+
59+
/// <summary>
60+
/// If we cannot connect to the server, this is how long we will wait before retrying.
61+
/// </summary>
62+
private float timeToDeferFailedConnections = 10.0f;
63+
#endif
64+
4965
/// <summary>
5066
/// If someone connects to us, this is the data we will send them.
5167
/// </summary>
@@ -58,10 +74,10 @@ public void SetData(byte[] data)
5874
/// <summary>
5975
/// Tells us who to contact if we need data.
6076
/// </summary>
61-
/// <param name="_serverIp"></param>
62-
public void SetServerIp(string _serverIp)
77+
/// <param name="newServerIp"></param>
78+
public void SetServerIp(string newServerIp)
6379
{
64-
serverIp = _serverIp.Trim();
80+
serverIp = newServerIp.Trim();
6581
}
6682

6783
/// <summary>
@@ -73,28 +89,12 @@ public void RequestAndGetData()
7389
ConnectListener();
7490
}
7591

76-
// A lot of the work done in this class can only be done in UWP. The editor is not a UWP app.
77-
#if !UNITY_EDITOR && UNITY_WSA
78-
/// <summary>
79-
/// Tracks the network connection to the remote machine we are sending meshes to.
80-
/// </summary>
81-
private StreamSocket networkConnection;
82-
83-
/// <summary>
84-
/// If we are running as the server, this is the listener the server will use.
85-
/// </summary>
86-
private StreamSocketListener networkListener;
87-
88-
/// <summary>
89-
/// If we cannot connect to the server, this is how long we will wait before retrying.
90-
/// </summary>
91-
private float timeToDeferFailedConnections = 10.0f;
92-
9392
/// <summary>
9493
/// Configures the network transmitter as the source.
9594
/// </summary>
9695
public void ConfigureAsServer()
9796
{
97+
#if !UNITY_EDITOR && UNITY_WSA
9898
Task t = new Task(() =>
9999
{
100100
networkListener = new StreamSocketListener();
@@ -103,8 +103,36 @@ public void ConfigureAsServer()
103103
}
104104
);
105105
t.Start();
106+
#else
107+
Debug.Log("This script is not intended to be run from the Unity Editor");
108+
// In order to avoid compiler warnings in the Unity Editor we have to access a few of our fields.
109+
Debug.Log(string.Format("serverIP = {0} waitingForConnection = {1} mostRecentDataBuffer = {2}", serverIp, waitingForConnection, mostRecentDataBuffer == null ? "No there" : "there"));
110+
#endif
106111
}
107112

113+
/// <summary>
114+
/// Connects to the server and requests data.
115+
/// </summary>
116+
private void ConnectListener()
117+
{
118+
#if !UNITY_EDITOR && UNITY_WSA
119+
if (waitingForConnection)
120+
{
121+
return;
122+
}
123+
124+
waitingForConnection = true;
125+
Debug.Log("Connecting to " + serverIp);
126+
HostName networkHost = new HostName(serverIp);
127+
networkConnection = new StreamSocket();
128+
129+
IAsyncAction outstandingAction = networkConnection.ConnectAsync(networkHost, SendConnectionPort.ToString());
130+
AsyncActionCompletedHandler aach = new AsyncActionCompletedHandler(RcvNetworkConnectedHandler);
131+
outstandingAction.Completed = aach;
132+
#endif
133+
}
134+
135+
#if !UNITY_EDITOR && UNITY_WSA
108136
/// <summary>
109137
/// When a connection is made to us, this call back gets called and
110138
/// we send our data.
@@ -131,26 +159,6 @@ private void NetworkListener_ConnectionReceived(StreamSocketListener sender, Str
131159
}
132160
}
133161

134-
/// <summary>
135-
/// Connects to the server and requests data.
136-
/// </summary>
137-
private void ConnectListener()
138-
{
139-
if (waitingForConnection)
140-
{
141-
return;
142-
}
143-
144-
Debug.Log("Connecting to " + serverIP);
145-
waitingForConnection = true;
146-
HostName networkHost = new HostName(serverIP);
147-
networkConnection = new StreamSocket();
148-
149-
IAsyncAction outstandingAction = networkConnection.ConnectAsync(networkHost, SendConnectionPort.ToString());
150-
AsyncActionCompletedHandler aach = new AsyncActionCompletedHandler(RcvNetworkConnectedHandler);
151-
outstandingAction.Completed = aach;
152-
}
153-
154162
/// <summary>
155163
/// When a connection to the server is established and we can start reading the data, this will be called.
156164
/// </summary>
@@ -187,7 +195,7 @@ private async void RcvNetworkConnectedHandler(IAsyncAction asyncInfo, AsyncStatu
187195
networkDataReader.ReadBytes(mostRecentDataBuffer);
188196

189197
// And fire our data ready event.
190-
dataReadyEvent?.Invoke(mostRecentDataBuffer);
198+
DataReadyEvent?.Invoke(mostRecentDataBuffer);
191199
}
192200
}
193201
else
@@ -198,15 +206,6 @@ private async void RcvNetworkConnectedHandler(IAsyncAction asyncInfo, AsyncStatu
198206
networkConnection.Dispose();
199207
waitingForConnection = false;
200208
}
201-
202-
#else
203-
public void ConfigureAsServer()
204-
{
205-
Debug.Log("This script is not intended to be run from the Unity Editor");
206-
// In order to avoid compiler warnings in the Unity Editor we have to access a few of our fields.
207-
Debug.Log(string.Format("serverIP = {0} waitingForConnection = {1} mostRecentDataBuffer = {2}", serverIp, waitingForConnection, mostRecentDataBuffer == null ? "No there" : "there"));
208-
}
209-
private void ConnectListener() {}
210209
#endif
211210
}
212211
}

Assets/HoloToolkit-Examples/SharingWithUNET/Scripts/NetworkDiscoveryWithAnchors.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace HoloToolkit.Examples.SharingWithUNET
1818
public class NetworkDiscoveryWithAnchors : NetworkDiscovery
1919
{
2020
/// <summary>
21-
/// This flag gets set when we recieve a broadcast.
21+
/// This flag gets set when we receive a broadcast.
2222
/// if this flag is set then we should not create a server.
2323
/// </summary>
24-
public bool receivedBroadcast { get; private set; }
24+
public bool ReceivedBroadcast { get; private set; }
2525

2626
/// <summary>
2727
/// Controls how often a broadcast should be sent to clients
@@ -79,8 +79,8 @@ private void Start()
7979
// We randomize how long we wait so that we reduce the chances that everyone joins at
8080
// once and decides that they are the server.
8181
// An alternative would be to create UI for managing who hosts.
82-
float InvokeWaitTime = 3 * BroadcastInterval + Random.value * 3 * BroadcastInterval;
83-
Invoke("MaybeInitAsServer", InvokeWaitTime * 0.001f);
82+
float invokeWaitTime = 3 * BroadcastInterval + Random.value * 3 * BroadcastInterval;
83+
Invoke("MaybeInitAsServer", invokeWaitTime * 0.001f);
8484
}
8585

8686
/// <summary>
@@ -89,8 +89,8 @@ private void Start()
8989
/// </summary>
9090
private void MaybeInitAsServer()
9191
{
92-
// If we Recieved a broadcast then we should not start as a server.
93-
if (receivedBroadcast)
92+
// If we receive a broadcast then we should not start as a server.
93+
if (ReceivedBroadcast)
9494
{
9595
return;
9696
}
@@ -134,18 +134,18 @@ private IEnumerator InitAsServer()
134134
/// </summary>
135135
/// <param name="fromAddress">When the broadcast came from</param>
136136
/// <param name="data">The data in the broad cast. Not currently used, but could
137-
/// be used for differntiating rooms or similar.</param>
137+
/// be used for differentiating rooms or similar.</param>
138138
public override void OnReceivedBroadcast(string fromAddress, string data)
139139
{
140-
// If we've already recieved a broadcast then we've already set everything up.
141-
if (receivedBroadcast)
140+
// If we've already received a broadcast then we've already set everything up.
141+
if (ReceivedBroadcast)
142142
{
143143
return;
144144
}
145145

146146
Debug.Log("Acting as client");
147147

148-
receivedBroadcast = true;
148+
ReceivedBroadcast = true;
149149

150150
// Stop listening for more broadcasts.
151151
StopBroadcast();
@@ -158,9 +158,9 @@ public override void OnReceivedBroadcast(string fromAddress, string data)
158158

159159
#if !UNITY_EDITOR
160160
// Tell the network transmitter the IP to request anchor data from if needed.
161-
GenericNetworkTransmitter.Instance.SetServerIP(ServerIp);
161+
GenericNetworkTransmitter.Instance.SetServerIp(ServerIp);
162162
#else
163-
Debug.LogWarning("This script will need modification to work in the Unity Editor");
163+
Debug.LogWarning("This script will need modification to work in the Unity Editor");
164164
#endif
165165
// And join the networked experience as a client.
166166
NetworkManager.singleton.StartClient();

0 commit comments

Comments
 (0)