fixed port conflicts
This commit is contained in:
@ -66,7 +66,7 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
var cfg = networkConfigAsset != null ? networkConfigAsset : NetworkConfig.Instance;
|
||||
if (cfg != null)
|
||||
{
|
||||
listenPort = cfg.port;
|
||||
listenPort = cfg.multiplayerAudioPort;
|
||||
}
|
||||
}
|
||||
InitializeNetwork();
|
||||
@ -78,6 +78,16 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
ConvaiNPCManager.Instance.OnActiveNPCChanged += HandleActiveNPCChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// When re-enabled, ensure listener is running
|
||||
if (_cancellationTokenSource == null)
|
||||
{
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
StartListening();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
@ -91,6 +101,12 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
_cancellationTokenSource?.Cancel();
|
||||
_cancellationTokenSource?.Dispose();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Free the UDP port when this NPC gets disabled
|
||||
StopListening();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
@ -115,8 +131,13 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
|
||||
private void InitializeConvai()
|
||||
{
|
||||
// Get target NPC
|
||||
if (useActiveNPC)
|
||||
// Prefer local ConvaiNPC on the same GameObject, then fall back to active NPC
|
||||
var localNPC = GetComponent<ConvaiNPC>();
|
||||
if (localNPC != null)
|
||||
{
|
||||
targetNPC = localNPC;
|
||||
}
|
||||
else if (useActiveNPC)
|
||||
{
|
||||
targetNPC = ConvaiNPCManager.Instance?.GetActiveConvaiNPC();
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
if (cfg != null)
|
||||
{
|
||||
targetIP = cfg.ipAddress;
|
||||
targetPort = cfg.port;
|
||||
targetPort = cfg.multiplayerAudioPort;
|
||||
}
|
||||
}
|
||||
InitializeNetwork();
|
||||
|
||||
@ -113,12 +113,21 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
var cfg = networkConfigAsset != null ? networkConfigAsset : NetworkConfig.Instance;
|
||||
if (cfg != null)
|
||||
{
|
||||
listenPort = cfg.port;
|
||||
listenPort = cfg.multiplayerSpeechPort;
|
||||
}
|
||||
}
|
||||
InitializeAudio();
|
||||
InitializeNetwork();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_cancellationTokenSource == null)
|
||||
{
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
StartListening();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
@ -126,6 +135,11 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
_cancellationTokenSource?.Cancel();
|
||||
_cancellationTokenSource?.Dispose();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
StopListening();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
@ -62,7 +62,7 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
if (cfg != null)
|
||||
{
|
||||
targetIP = cfg.ipAddress;
|
||||
targetPort = cfg.port;
|
||||
targetPort = cfg.multiplayerSpeechPort;
|
||||
}
|
||||
}
|
||||
InitializeNetwork();
|
||||
@ -93,8 +93,13 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
|
||||
private void InitializeConvai()
|
||||
{
|
||||
// Get target NPC
|
||||
if (useActiveNPC)
|
||||
// Prefer local ConvaiNPC on the same GameObject, then fall back to active NPC
|
||||
var localNPC = GetComponent<ConvaiNPC>();
|
||||
if (localNPC != null)
|
||||
{
|
||||
sourceNPC = localNPC;
|
||||
}
|
||||
else if (useActiveNPC)
|
||||
{
|
||||
sourceNPC = ConvaiNPCManager.Instance?.GetActiveConvaiNPC();
|
||||
}
|
||||
|
||||
BIN
Unity-Master/Assets/Scripts/NetworkConfig.asset
(Stored with Git LFS)
BIN
Unity-Master/Assets/Scripts/NetworkConfig.asset
(Stored with Git LFS)
Binary file not shown.
@ -6,6 +6,10 @@ public class NetworkConfig : ScriptableObject
|
||||
[Header("Global Network Settings")]
|
||||
public string ipAddress = "127.0.0.1";
|
||||
public int port = 8080;
|
||||
|
||||
[Header("Multiplayer Ports")]
|
||||
public int multiplayerAudioPort = 12345; // For ConvaiSimpleUDPAudio (send/receive)
|
||||
public int multiplayerSpeechPort = 12346; // For ConvaiUDPSpeech (send/receive)
|
||||
|
||||
private static NetworkConfig _instance;
|
||||
public static NetworkConfig Instance
|
||||
|
||||
Reference in New Issue
Block a user