Skip to content

feat: fulfilling interface for tools to find network objects from an id #1086

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
10 changes: 10 additions & 0 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#if UNITY_EDITOR
using UnityEditor;
#endif
#if MULTIPLAYER_TOOLS
using Unity.Multiplayer.Tools;
#endif
using Unity.Profiling;
using UnityEngine.SceneManagement;
using Debug = UnityEngine.Debug;
Expand Down Expand Up @@ -396,6 +399,13 @@ private void Initialize(bool server)
#endif
}

#if MULTIPLAYER_TOOLS
NetworkSolutionInterface.SetInterface(new NetworkSolutionInterfaceParameters
{
NetworkObjectProvider = new NetworkObjectProvider(this)
});
#endif

if (NetworkConfig.NetworkTransport == null)
{
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if MULTIPLAYER_TOOLS
using Unity.Multiplayer.Tools;
using UnityEngine;

namespace Unity.Netcode
{
class NetworkObjectProvider : INetworkObjectProvider
{
private readonly NetworkManager m_NetworkManager;

public NetworkObjectProvider(NetworkManager networkManager)
{
m_NetworkManager = networkManager;
}

public Object GetNetworkObject(ulong networkObjectId)
{
if(m_NetworkManager.SpawnManager.SpawnedObjects.TryGetValue(networkObjectId, out NetworkObject value))
{
return value;
}

return null;
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"references": [
"Unity.Multiplayer.MetricTypes",
"Unity.Multiplayer.NetStats",
"Unity.Multiplayer.NetStatsReporting"
"Unity.Multiplayer.NetStatsReporting",
"Unity.Multiplayer.NetworkSolutionInterface"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
2 changes: 1 addition & 1 deletion testproject-tools-integration/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dependencies": {
"com.unity.ide.rider": "3.0.7",
"com.unity.netcode.gameobjects": "file:../../com.unity.netcode.gameobjects",
"com.unity.multiplayer.tools": "0.0.1-preview.3",
"com.unity.multiplayer.tools": "0.0.1-preview.4",
"com.unity.multiplayer.transport.utp": "file:../../com.unity.multiplayer.transport.utp",
"com.unity.test-framework": "1.1.26",
"com.unity.modules.ai": "1.0.0",
Expand Down