Skip to content

Commit de87370

Browse files
Minor formatting and organization
1 parent 295aa30 commit de87370

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

Assets/HoloToolkit/Sharing/Scripts/SharingStage.cs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public string UserName
150150
}
151151

152152
private NetworkConnectionAdapter networkConnectionAdapter;
153+
153154
public NetworkConnection Connection
154155
{
155156
get { return Manager != null ? Manager.GetServerConnection() : null; }
@@ -194,7 +195,7 @@ private void LateUpdate()
194195

195196
if (Manager != null)
196197
{
197-
// Update the XToolsManager to processes any network messages that have arrived
198+
// Update the Sharing Manager to processes any network messages that have arrived.
198199
Manager.Update();
199200
}
200201
}
@@ -219,14 +220,6 @@ protected override void OnDestroy()
219220
}
220221
}
221222

222-
if (Manager != null)
223-
{
224-
// Force a disconnection so that we can stop and start Unity without connections hanging around
225-
Manager.GetPairedConnection().Disconnect();
226-
Manager.GetServerConnection().Disconnect();
227-
}
228-
229-
// Release the Sharing resources
230223
if (SessionUsersTracker != null)
231224
{
232225
SessionUsersTracker.Dispose();
@@ -253,11 +246,14 @@ protected override void OnDestroy()
253246

254247
if (Manager != null)
255248
{
249+
// Force a disconnection so that we can stop and start Unity without connections hanging around.
250+
Manager.GetPairedConnection().Disconnect();
251+
Manager.GetServerConnection().Disconnect();
256252
Manager.Dispose();
257253
Manager = null;
258254
}
259255

260-
// Forces a garbage collection to try to clean up any additional reference to SWIG-wrapped objects
256+
// Forces a garbage collection to try to clean up any additional reference to SWIG-wrapped objects.
261257
GC.Collect();
262258

263259
base.OnDestroy();
@@ -278,7 +274,7 @@ private void Connect()
278274

279275
Manager = SharingManager.Create(config);
280276

281-
//set up callbacks so that we know when we've connected successfully
277+
// Set up callbacks so that we know when we've connected successfully.
282278
networkConnectionAdapter = new NetworkConnectionAdapter();
283279
networkConnectionAdapter.ConnectedCallback += NetworkConnectionAdapter_ConnectedCallback;
284280
networkConnectionAdapter.DisconnectedCallback += NetworkConnectionAdapter_ConnectedCallback;
@@ -319,13 +315,12 @@ private void SendConnectedNotification()
319315
{
320316
if (IsConnected)
321317
{
322-
//Send notification that we're connected
323318
if (SharingManagerConnected != null)
324319
{
325320
SharingManagerConnected(this, EventArgs.Empty);
326321
}
327322
}
328-
else if (!IsConnected)
323+
else
329324
{
330325
if (SharingManagerDisconnected != null)
331326
{
@@ -346,42 +341,46 @@ private void AutoDiscoverInit()
346341
discoveryClient = DiscoveryClient.Create();
347342
discoveryClient.AddListener(discoveryClientAdapter);
348343

349-
//Start Finding Server
344+
// Start Finding Server.
350345
isTryingToFindServer = true;
351346
}
352347

353348
private void AutoDiscoverUpdate()
354349
{
355-
//Searching Enabled-> Update DiscoveryClient to check results, Wait Interval then Ping network.
350+
// Searching Enabled-> Update DiscoveryClient to check results, Wait Interval then Ping network.
356351
pingIntervalCurrent += Time.deltaTime;
357352
if (pingIntervalCurrent > PingIntervalSec)
358353
{
359354
if (ShowDetailedLogs)
360355
{
361356
Debug.Log("Looking for servers...");
362357
}
358+
363359
pingIntervalCurrent = 0;
364360
discoveryClient.Ping();
365361
}
362+
366363
discoveryClient.Update();
367364
}
368365

369366
private void OnSystemDiscovered(DiscoveredSystem obj)
370367
{
371-
if (obj.GetRole() == SystemRole.SessionDiscoveryServerRole)
368+
if (obj.GetRole() != SystemRole.SessionDiscoveryServerRole) { return; }
369+
370+
// Found a server. Stop pinging the network and connect.
371+
isTryingToFindServer = false;
372+
ServerAddress = obj.GetAddress();
373+
374+
if (ShowDetailedLogs)
372375
{
373-
//Found a server. Stop pinging the network and connect
374-
isTryingToFindServer = false;
375-
ServerAddress = obj.GetAddress();
376-
if (ShowDetailedLogs)
377-
{
378-
Debug.Log("Server discovered at: " + ServerAddress);
379-
}
380-
Connect();
381-
if (ShowDetailedLogs)
382-
{
383-
Debug.LogFormat("Connected to: {0}:{1}", ServerAddress, ServerPort.ToString());
384-
}
376+
Debug.Log("Server discovered at: " + ServerAddress);
377+
}
378+
379+
Connect();
380+
381+
if (ShowDetailedLogs)
382+
{
383+
Debug.LogFormat("Connected to: {0}:{1}", ServerAddress, ServerPort.ToString());
385384
}
386385
}
387386

@@ -412,12 +411,13 @@ private void HandleLog(string logString, string stackTrace, LogType type)
412411
break;
413412

414413
case LogType.Log:
415-
default:
416414
if (ShowDetailedLogs)
417415
{
418416
Log.Info(logString);
419417
}
420418
break;
419+
default:
420+
throw new ArgumentOutOfRangeException("type", type, "Invalid Message Type");
421421
}
422422
}
423423
}

0 commit comments

Comments
 (0)