@@ -26,13 +26,13 @@ public class SharingStage : Singleton<SharingStage>
2626 /// <summary>
2727 /// Default username to use when joining a session.
2828 /// </summary>
29- /// <remarks>User code should set the user name by setting the UserName property.</remarks>
29+ /// <remarks>Set the user name by setting <see cref=" UserName"/> property.</remarks>
3030 private const string DefaultUserName = "User " ;
3131
3232 /// <summary>
3333 /// Set whether this app should be a Primary or Secondary client.
34- /// Primary: Connects directly to the Session Server, can create/join/leave sessions
35- /// Secondary: Connects to a Primary client. Cannot do any session management
34+ /// <para> Primary: Connects directly to the Session Server, can create/join/leave sessions.</para>
35+ /// <para> Secondary: Connects to a Primary client. Cannot do any session management.</para>
3636 /// </summary>
3737 public ClientRole ClientRole = ClientRole . Primary ;
3838
@@ -68,7 +68,7 @@ public class SharingStage : Singleton<SharingStage>
6868 public bool IsAudioEndpoint = true ;
6969
7070 /// <summary>
71- /// Pipes XTools console output to Unity's output window for debugging
71+ /// Pipes sharing server console output to Unity's output window for debugging
7272 /// </summary>
7373 private ConsoleLogWriter logWriter ;
7474
@@ -80,6 +80,8 @@ public class SharingStage : Singleton<SharingStage>
8080 /// <summary>
8181 /// Server sessions tracker.
8282 /// </summary>
83+ /// <remarks>Note that if this processes takes the role of a secondary client,
84+ /// then the sessionsTracker will always be null.</remarks>
8385 public ServerSessionsTracker SessionsTracker { get ; private set ; }
8486
8587 /// <summary>
@@ -104,7 +106,7 @@ public class SharingStage : Singleton<SharingStage>
104106 public event Action < string > UserNameChanged ;
105107
106108 /// <summary>
107- /// Enables Server Discovery on the network
109+ /// Enables Server Discovery on the network.
108110 /// </summary>
109111 private DiscoveryClient discoveryClient ;
110112
@@ -123,7 +125,10 @@ public class SharingStage : Singleton<SharingStage>
123125 /// </summary>
124126 private bool isTryingToFindServer ;
125127
126- [ Tooltip ( "Show Detailed Information for server connections" ) ]
128+ /// <summary>
129+ /// Show Detailed Information for sharing services.
130+ /// </summary>
131+ [ Tooltip ( "Show Detailed Information for sharing services." ) ]
127132 public bool ShowDetailedLogs ;
128133
129134 public string UserName
@@ -179,7 +184,7 @@ protected override void Awake()
179184 }
180185 else
181186 {
182- ManagerInit ( ) ;
187+ ManagerInit ( connectOnAwake ) ;
183188 }
184189 }
185190
@@ -263,7 +268,7 @@ protected override void OnDestroy()
263268
264269 #endregion // Unity Methods
265270
266- #region Callbacks
271+ #region Event Callbacks
267272
268273 private void OnNetworkConnectionChanged ( NetworkConnection networkConnection )
269274 {
@@ -288,6 +293,7 @@ private void OnSystemDiscovered(DiscoveredSystem system)
288293 if ( system . GetRole ( ) != SystemRole . SessionDiscoveryServerRole ) { return ; }
289294
290295 // Found a server. Stop pinging the network and connect.
296+ discoveryClientAdapter . DiscoveredEvent -= OnSystemDiscovered ;
291297 isTryingToFindServer = false ;
292298 ServerAddress = system . GetAddress ( ) ;
293299
@@ -296,7 +302,7 @@ private void OnSystemDiscovered(DiscoveredSystem system)
296302 Debug . Log ( "Server discovered at: " + ServerAddress ) ;
297303 }
298304
299- ManagerInit ( ) ;
305+ ManagerInit ( true ) ;
300306
301307 if ( ShowDetailedLogs )
302308 {
@@ -329,16 +335,15 @@ private void OnLogReceived(string logString, string stackTrace, LogType type)
329335 }
330336 }
331337
332- #endregion // Callbacks
338+ #endregion // Event Callbacks
333339
334- private void ManagerInit ( )
340+ private void ManagerInit ( bool setConnection )
335341 {
336342 var config = new ClientConfig ( ClientRole ) ;
337343 config . SetIsAudioEndpoint ( IsAudioEndpoint ) ;
338344 config . SetLogWriter ( logWriter ) ;
339345
340- // Only set the server info is we are connecting on awake
341- if ( connectOnAwake )
346+ if ( setConnection )
342347 {
343348 config . SetServerAddress ( ServerAddress ) ;
344349 config . SetServerPort ( ServerPort ) ;
@@ -384,6 +389,7 @@ private void AutoDiscoverInit()
384389 {
385390 Debug . Log ( "Looking for servers..." ) ;
386391 }
392+
387393 discoveryClientAdapter = new DiscoveryClientAdapter ( ) ;
388394 discoveryClientAdapter . DiscoveredEvent += OnSystemDiscovered ;
389395
0 commit comments