1+ #if ENABLE_RELAY_SERVICE
2+ using System ;
3+ #endif
14using System . Collections ;
2- using UnityEngine ;
35using Unity . Netcode ;
46using Unity . Netcode . Transports . UTP ;
5- using UnityEngine . SceneManagement ;
67#if ENABLE_RELAY_SERVICE
7- using System ;
88using Unity . Services . Core ;
99using Unity . Services . Authentication ;
1010#endif
11+ using UnityEngine ;
12+ using UnityEngine . SceneManagement ;
13+
1114
1215/// <summary>
1316/// Used in tandem with the ConnectModeButtons prefab asset in test project
@@ -23,8 +26,10 @@ public class ConnectionModeScript : MonoBehaviour
2326 [ SerializeField ]
2427 private GameObject m_JoinCodeInput ;
2528
29+ #if ENABLE_RELAY_SERVICE
2630 [ SerializeField ]
2731 private int m_MaxConnections = 10 ;
32+ #endif
2833
2934 [ SerializeField ]
3035 private LoadSceneMode m_ClientSynchronizationMode ;
@@ -126,8 +131,10 @@ private void OnServicesInitialized()
126131 if ( HasRelaySupport ( ) )
127132 {
128133 m_JoinCodeInput . SetActive ( true ) ;
134+ #if ENABLE_RELAY_SERVICE
129135 m_ConnectionModeButtons ? . SetActive ( false || AuthenticationService . Instance . IsSignedIn ) ;
130136 m_AuthenticationButtons ? . SetActive ( NetworkManager . Singleton && ! NetworkManager . Singleton . IsListening && ! AuthenticationService . Instance . IsSignedIn ) ;
137+ #endif
131138 }
132139 }
133140
@@ -138,11 +145,13 @@ public void OnStartServerButton()
138145 {
139146 if ( NetworkManager . Singleton && ! NetworkManager . Singleton . IsListening && m_ConnectionModeButtons )
140147 {
148+ #if ENABLE_RELAY_SERVICE
141149 if ( HasRelaySupport ( ) )
142150 {
143151 StartCoroutine ( StartRelayServer ( StartServer ) ) ;
144152 }
145153 else
154+ #endif
146155 {
147156 StartServer ( ) ;
148157 }
@@ -170,13 +179,13 @@ private void OnServerStopped(bool obj)
170179 }
171180 }
172181
173-
182+ #if ENABLE_RELAY_SERVICE
174183 /// <summary>
175184 /// Coroutine that handles starting MLAPI in server mode if Relay is enabled
176185 /// </summary>
177186 private IEnumerator StartRelayServer ( Action postAllocationAction )
178187 {
179- #if ENABLE_RELAY_SERVICE
188+
180189 m_ConnectionModeButtons ? . SetActive ( false ) ;
181190
182191 var serverRelayUtilityTask = RelayUtility . AllocateRelayServerAndGetJoinCode ( m_MaxConnections ) ;
@@ -198,11 +207,8 @@ private IEnumerator StartRelayServer(Action postAllocationAction)
198207 NetworkManager . Singleton . GetComponent < UnityTransport > ( ) . SetRelayServerData ( ipv4address , port , allocationIdBytes , key , connectionData ) ;
199208
200209 postAllocationAction ( ) ;
201- #else
202- yield return null ;
203- #endif
204210 }
205-
211+ #endif
206212
207213 /// <summary>
208214 /// Handles starting netcode in host mode
@@ -211,11 +217,13 @@ public void OnStartHostButton()
211217 {
212218 if ( NetworkManager . Singleton && ! NetworkManager . Singleton . IsListening && m_ConnectionModeButtons )
213219 {
220+ #if ENABLE_RELAY_SERVICE
214221 if ( HasRelaySupport ( ) )
215222 {
216223 StartCoroutine ( StartRelayServer ( StartHost ) ) ;
217224 }
218225 else
226+ #endif
219227 {
220228 StartHost ( ) ;
221229 }
0 commit comments