Skip to content

fix: unet removed from unity trunk v1.0.0 #1684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNITY_UNET_PRESENT
using System;
#if UNITY_EDITOR
using UnityEditor;
Expand Down Expand Up @@ -50,3 +51,4 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
#endif
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if UNITY_UNET_PRESENT
#pragma warning disable 618 // disable is obsolete
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
using System;
Expand Down Expand Up @@ -279,3 +280,4 @@ private ConnectionConfig GetConfig()
}
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
#pragma warning restore 618 // restore is obsolete
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"name": "com.unity.multiplayer.tools",
"expression": "",
"define": "MULTIPLAYER_TOOLS"
},
{
"name": "Unity",
"expression": "(0,2022.2.0a5)",
"define": "UNITY_UNET_PRESENT"
}
],
"noEngineReferences": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.Collections.Generic;
using UnityEngine;
using NUnit.Framework;
#if UNITY_UNET_PRESENT
using Unity.Netcode.Transports.UNET;
#endif

namespace Unity.Netcode.RuntimeTests
{
Expand Down Expand Up @@ -68,6 +70,7 @@ public static bool StartNetworkManager(out NetworkManager networkManager, Networ

Debug.Log($"{nameof(NetworkManager)} Instantiated.");

#if UNITY_UNET_PRESENT
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the back port has to be different because of the fixes applied to develop for the console testing (#1664 & #1653). I will be migrating these updates into develop next week. Until then, this prevents certain tests from failing when UNet is not included and uses only SIPTransport.

var unetTransport = NetworkManagerGameObject.AddComponent<UNetTransport>();
if (networkConfig == null)
{
Expand All @@ -78,14 +81,25 @@ public static bool StartNetworkManager(out NetworkManager networkManager, Networ
}

NetworkManagerObject.NetworkConfig = networkConfig;

unetTransport.ConnectAddress = "127.0.0.1";
unetTransport.ConnectPort = 7777;
unetTransport.ServerListenPort = 7777;
unetTransport.MessageBufferSize = 65535;
unetTransport.MaxConnections = 100;
unetTransport.MessageSendMode = UNetTransport.SendMode.Immediately;
NetworkManagerObject.NetworkConfig.NetworkTransport = unetTransport;
#else
var sipTransport = NetworkManagerGameObject.AddComponent<SIPTransport>();
if (networkConfig == null)
{
networkConfig = new NetworkConfig
{
EnableSceneManagement = false,
};
}
NetworkManagerObject.NetworkConfig = networkConfig;
NetworkManagerObject.NetworkConfig.NetworkTransport = sipTransport;
#endif

// Starts the network manager in the mode specified
StartNetworkManagerMode(managerMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"name": "com.unity.multiplayer.tools",
"expression": "",
"define": "MULTIPLAYER_TOOLS"
},
{
"name": "Unity",
"expression": "(0,2022.2.0a5)",
"define": "UNITY_UNET_PRESENT"
}
],
"noEngineReferences": false
Expand Down
22 changes: 20 additions & 2 deletions testproject/Assets/Scripts/CommandLineHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using Unity.Netcode;
#if UNITY_UNET_PRESENT
using Unity.Netcode.Transports.UNET;

#endif

/// <summary>
/// Provides basic command line handling capabilities
Expand Down Expand Up @@ -200,9 +201,20 @@ private void SetTransportAddress(string address)
var transport = NetworkManager.Singleton.NetworkConfig.NetworkTransport;
switch (transport)
{
#if UNITY_UNET_PRESENT
case UNetTransport unetTransport:
unetTransport.ConnectAddress = address;
break;
#endif
case UnityTransport utpTransport:
{
utpTransport.ConnectionData.Address = address;
if (utpTransport.ConnectionData.ServerListenAddress == string.Empty)
{
utpTransport.ConnectionData.ServerListenAddress = address;
}
break;
}
}
}

Expand All @@ -211,10 +223,17 @@ private void SetPort(ushort port)
var transport = NetworkManager.Singleton.NetworkConfig.NetworkTransport;
switch (transport)
{
#if UNITY_UNET_PRESENT
case UNetTransport unetTransport:
unetTransport.ConnectPort = port;
unetTransport.ServerListenPort = port;
break;
#endif
case UnityTransport utpTransport:
{
utpTransport.ConnectionData.Port = port;
break;
}
}
}
}
Expand All @@ -232,6 +251,5 @@ private void Start()
{
s_CommandLineProcessorInstance = new CommandLineProcessor(Environment.GetCommandLineArgs());
}

}
}
5 changes: 5 additions & 0 deletions testproject/Assets/Scripts/testproject.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"name": "com.unity.services.relay",
"expression": "0.0.1-preview.3",
"define": "ENABLE_RELAY_SERVICE"
},
{
"name": "Unity",
"expression": "(0,2022.2.0a5)",
"define": "UNITY_UNET_PRESENT"
}
],
"noEngineReferences": false
Expand Down
10 changes: 8 additions & 2 deletions testproject/Assets/Tests/Runtime/testproject.runtimetests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"UNITY_EDITOR",
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"versionDefines": [
{
"name": "Unity",
"expression": "(0,2022.2.0a5)",
"define": "UNITY_UNET_PRESENT"
}
],
"noEngineReferences": false
}
}