Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions testproject/Assets/DefaultNetworkPrefabs.asset
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,7 @@ MonoBehaviour:
SourceHashToOverride: 0
OverridingTargetPrefab: {fileID: 0}
- Override: 0
Prefab: {fileID: 8133991607019124060, guid: 421bcf732fe69486d8abecfa5eee63bb,
type: 3}
SourcePrefabToOverride: {fileID: 0}
SourceHashToOverride: 0
OverridingTargetPrefab: {fileID: 0}
- Override: 0
Prefab: {fileID: 3439633038736912633, guid: 398aad09d8b2a47eba664a076763cdcc,
Prefab: {fileID: 3830151999068797299, guid: 074ae41741b33f84ca886d5b8dc482d2,
type: 3}
SourcePrefabToOverride: {fileID: 0}
SourceHashToOverride: 0
Expand Down
26 changes: 17 additions & 9 deletions testproject/Assets/Scripts/ConnectionModeScript.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#if ENABLE_RELAY_SERVICE
using System;
#endif
using System.Collections;
using UnityEngine;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
using UnityEngine.SceneManagement;
#if ENABLE_RELAY_SERVICE
using System;
using Unity.Services.Core;
using Unity.Services.Authentication;
#endif
using UnityEngine;
using UnityEngine.SceneManagement;


/// <summary>
/// Used in tandem with the ConnectModeButtons prefab asset in test project
Expand All @@ -23,8 +26,10 @@ public class ConnectionModeScript : MonoBehaviour
[SerializeField]
private GameObject m_JoinCodeInput;

#if ENABLE_RELAY_SERVICE
[SerializeField]
private int m_MaxConnections = 10;
#endif

[SerializeField]
private LoadSceneMode m_ClientSynchronizationMode;
Expand Down Expand Up @@ -126,8 +131,10 @@ private void OnServicesInitialized()
if (HasRelaySupport())
{
m_JoinCodeInput.SetActive(true);
#if ENABLE_RELAY_SERVICE
m_ConnectionModeButtons?.SetActive(false || AuthenticationService.Instance.IsSignedIn);
m_AuthenticationButtons?.SetActive(NetworkManager.Singleton && !NetworkManager.Singleton.IsListening && !AuthenticationService.Instance.IsSignedIn);
#endif
}
}

Expand All @@ -138,11 +145,13 @@ public void OnStartServerButton()
{
if (NetworkManager.Singleton && !NetworkManager.Singleton.IsListening && m_ConnectionModeButtons)
{
#if ENABLE_RELAY_SERVICE
if (HasRelaySupport())
{
StartCoroutine(StartRelayServer(StartServer));
}
else
#endif
{
StartServer();
}
Expand Down Expand Up @@ -170,13 +179,13 @@ private void OnServerStopped(bool obj)
}
}


#if ENABLE_RELAY_SERVICE
/// <summary>
/// Coroutine that handles starting MLAPI in server mode if Relay is enabled
/// </summary>
private IEnumerator StartRelayServer(Action postAllocationAction)
{
#if ENABLE_RELAY_SERVICE

m_ConnectionModeButtons?.SetActive(false);

var serverRelayUtilityTask = RelayUtility.AllocateRelayServerAndGetJoinCode(m_MaxConnections);
Expand All @@ -198,11 +207,8 @@ private IEnumerator StartRelayServer(Action postAllocationAction)
NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(ipv4address, port, allocationIdBytes, key, connectionData);

postAllocationAction();
#else
yield return null;
#endif
}

#endif

/// <summary>
/// Handles starting netcode in host mode
Expand All @@ -211,11 +217,13 @@ public void OnStartHostButton()
{
if (NetworkManager.Singleton && !NetworkManager.Singleton.IsListening && m_ConnectionModeButtons)
{
#if ENABLE_RELAY_SERVICE
if (HasRelaySupport())
{
StartCoroutine(StartRelayServer(StartHost));
}
else
#endif
{
StartHost();
}
Expand Down
2 changes: 2 additions & 0 deletions testproject/Assets/Scripts/RelayUtility.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if ENABLE_RELAY_SERVICE
using System;
using System.Threading.Tasks;
using Unity.Services.Relay;
Expand Down Expand Up @@ -56,3 +57,4 @@ public class RelayUtility
return (allocation.RelayServer.IpV4, (ushort)allocation.RelayServer.Port, allocation.AllocationIdBytes, allocation.ConnectionData, allocation.HostConnectionData, allocation.Key);
}
}
#endif
10 changes: 6 additions & 4 deletions testproject/Assets/Scripts/UIController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using UnityEngine;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
#if ENABLE_RELAY_SERVICE
using Unity.Services.Core;
using Unity.Services.Authentication;
#endif
using UnityEngine;


public class UIController : MonoBehaviour
{
Expand Down Expand Up @@ -49,10 +50,10 @@ private void HideButtons()
ButtonsRoot.SetActive(false);
}


#if ENABLE_RELAY_SERVICE
public async void OnSignIn()
{
#if ENABLE_RELAY_SERVICE

await UnityServices.InitializeAsync();
Debug.Log("OnSignIn");
await AuthenticationService.Instance.SignInAnonymouslyAsync();
Expand All @@ -64,6 +65,7 @@ public async void OnSignIn()
JoinCode.SetActive(true);
AuthButton.SetActive(false);
}
#endif

}
#endif
}
17 changes: 8 additions & 9 deletions testproject/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"dependencies": {
"com.unity.addressables": "2.1.0",
"com.unity.ai.navigation": "2.0.0",
"com.unity.collab-proxy": "2.4.3",
"com.unity.ide.rider": "3.0.28",
"com.unity.addressables": "2.2.2",
"com.unity.ai.navigation": "2.0.5",
"com.unity.collab-proxy": "2.6.0",
"com.unity.ide.rider": "3.0.31",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.mathematics": "1.3.2",
"com.unity.netcode.gameobjects": "file:../../com.unity.netcode.gameobjects",
"com.unity.package-validation-suite": "0.49.0-preview",
"com.unity.services.authentication": "3.3.3",
"com.unity.services.core": "1.13.0",
"com.unity.services.relay": "1.0.5",
"com.unity.test-framework": "1.4.4",
"com.unity.services.authentication": "3.4.0",
"com.unity.services.core": "1.14.0",
"com.unity.test-framework": "1.4.5",
"com.unity.test-framework.performance": "3.0.3",
"com.unity.timeline": "1.8.7",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.9",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.10",
"com.unity.ugui": "2.0.0",
"com.unity.modules.accessibility": "1.0.0",
"com.unity.modules.ai": "1.0.0",
Expand Down
Loading
Loading