Animace + Menu
This commit is contained in:
10
Networking/NGO/ISteamNGOAdapter.cs
Normal file
10
Networking/NGO/ISteamNGOAdapter.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace MegaKoop.Networking
|
||||
{
|
||||
// Implement this interface on a component attached to your NetworkManager GameObject.
|
||||
// Use it to configure your chosen Steam transport (SteamNetworkingSockets) for NGO.
|
||||
public interface ISteamNGOAdapter
|
||||
{
|
||||
void ConfigureHost(ulong hostSteamId);
|
||||
void ConfigureClient(ulong hostSteamId);
|
||||
}
|
||||
}
|
||||
2
Networking/NGO/ISteamNGOAdapter.cs.meta
Normal file
2
Networking/NGO/ISteamNGOAdapter.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba76ae1e67da5874bb01a8d78d494bfd
|
||||
77
Networking/NGO/NetworkBootstrap.cs
Normal file
77
Networking/NGO/NetworkBootstrap.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MegaKoop.Networking
|
||||
{
|
||||
/// <summary>
|
||||
/// Thin bootstrap around Netcode for GameObjects start/stop.
|
||||
/// Uses compile guards so the project compiles without NGO.
|
||||
/// </summary>
|
||||
public static class NetworkBootstrap
|
||||
{
|
||||
public static bool StartHost(string gameScene = "GameScene")
|
||||
{
|
||||
#if UNITY_NETCODE || NETCODE_PRESENT
|
||||
var nm = Unity.Netcode.NetworkManager.Singleton;
|
||||
if (nm == null)
|
||||
{
|
||||
Debug.LogError("[NetworkBootstrap] NetworkManager.Singleton not found in scene.");
|
||||
return false;
|
||||
}
|
||||
Object.DontDestroyOnLoad(nm.gameObject);
|
||||
bool ok = nm.StartHost();
|
||||
if (!ok)
|
||||
{
|
||||
Debug.LogError("[NetworkBootstrap] StartHost failed.");
|
||||
return false;
|
||||
}
|
||||
// Prefer NGO SceneManager if available
|
||||
if (nm.SceneManager != null)
|
||||
{
|
||||
nm.SceneManager.LoadScene(gameScene, Unity.Netcode.AdditiveScenes.NetworkSceneManager.LoadSceneMode.Single);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.SceneManagement.SceneManager.LoadScene(gameScene);
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
Debug.LogWarning("[NetworkBootstrap] Netcode for GameObjects not present. Define UNITY_NETCODE or NETCODE_PRESENT and add the package.");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool StartClient(string gameScene = "GameScene")
|
||||
{
|
||||
#if UNITY_NETCODE || NETCODE_PRESENT
|
||||
var nm = Unity.Netcode.NetworkManager.Singleton;
|
||||
if (nm == null)
|
||||
{
|
||||
Debug.LogError("[NetworkBootstrap] NetworkManager.Singleton not found in scene.");
|
||||
return false;
|
||||
}
|
||||
Object.DontDestroyOnLoad(nm.gameObject);
|
||||
bool ok = nm.StartClient();
|
||||
if (!ok)
|
||||
{
|
||||
Debug.LogError("[NetworkBootstrap] StartClient failed.");
|
||||
return false;
|
||||
}
|
||||
// Client will be moved to scene by NGO server scene management
|
||||
return true;
|
||||
#else
|
||||
Debug.LogWarning("[NetworkBootstrap] Netcode for GameObjects not present. Define UNITY_NETCODE or NETCODE_PRESENT and add the package.");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
#if UNITY_NETCODE || NETCODE_PRESENT
|
||||
var nm = Unity.Netcode.NetworkManager.Singleton;
|
||||
if (nm == null) return;
|
||||
if (nm.IsServer || nm.IsHost) nm.Shutdown(true);
|
||||
else if (nm.IsClient) nm.Shutdown();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Networking/NGO/NetworkBootstrap.cs.meta
Normal file
2
Networking/NGO/NetworkBootstrap.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b54f132c1f719e44b5d94bc0252c78f
|
||||
69
Networking/NGO/SteamNGOAdapter.cs
Normal file
69
Networking/NGO/SteamNGOAdapter.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
#if UNITY_NETCODE || NETCODE_PRESENT
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using Unity.Netcode;
|
||||
|
||||
namespace MegaKoop.Networking
|
||||
{
|
||||
/// <summary>
|
||||
/// Reflection-based adapter that tries to configure your Steam transport (attached to NetworkManager)
|
||||
/// for host/client using provided SteamIDs. If it can't find a known method, it logs a clear instruction.
|
||||
/// Replace this with a strongly typed adapter when you pick a specific Steam transport.
|
||||
/// </summary>
|
||||
public class SteamNGOAdapter : MonoBehaviour, ISteamNGOAdapter
|
||||
{
|
||||
private object Transport => NetworkManager.Singleton ? NetworkManager.Singleton.NetworkConfig.NetworkTransport : null;
|
||||
|
||||
public void ConfigureHost(ulong hostSteamId)
|
||||
{
|
||||
var t = Transport;
|
||||
if (t == null)
|
||||
{
|
||||
Debug.LogWarning("[SteamNGOAdapter] NetworkTransport not found on NetworkManager.");
|
||||
return;
|
||||
}
|
||||
if (TryInvoke(t, "ConfigureHost", hostSteamId)) return;
|
||||
if (TryInvoke(t, "SetHostSteamId", hostSteamId)) return;
|
||||
if (TryInvoke(t, "SetServerSteamId", hostSteamId)) return;
|
||||
if (TryInvoke(t, "InitAsServer", hostSteamId)) return;
|
||||
Debug.LogWarning("[SteamNGOAdapter] Could not configure host on transport via reflection. Please implement host configuration for your transport.");
|
||||
}
|
||||
|
||||
public void ConfigureClient(ulong hostSteamId)
|
||||
{
|
||||
var t = Transport;
|
||||
if (t == null)
|
||||
{
|
||||
Debug.LogWarning("[SteamNGOAdapter] NetworkTransport not found on NetworkManager.");
|
||||
return;
|
||||
}
|
||||
if (TryInvoke(t, "ConfigureClient", hostSteamId)) return;
|
||||
if (TryInvoke(t, "SetClientSteamId", hostSteamId)) return;
|
||||
if (TryInvoke(t, "ConnectToSteamId", hostSteamId)) return;
|
||||
if (TryInvoke(t, "InitAsClient", hostSteamId)) return;
|
||||
Debug.LogWarning("[SteamNGOAdapter] Could not configure client on transport via reflection. Please implement client configuration for your transport.");
|
||||
}
|
||||
|
||||
private bool TryInvoke(object target, string methodName, ulong steamId)
|
||||
{
|
||||
var mi = target.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||
if (mi == null) return false;
|
||||
try
|
||||
{
|
||||
if (mi.IsStatic)
|
||||
mi.Invoke(null, new object[] { steamId });
|
||||
else
|
||||
mi.Invoke(target, new object[] { steamId });
|
||||
Debug.Log($"[SteamNGOAdapter] Invoked {target.GetType().Name}.{methodName}({steamId})");
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning($"[SteamNGOAdapter] Invoke {methodName} failed: {e.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
2
Networking/NGO/SteamNGOAdapter.cs.meta
Normal file
2
Networking/NGO/SteamNGOAdapter.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d8309c9ecb40434aa684e073cf0a76b
|
||||
Reference in New Issue
Block a user