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();
|
||||
@ -79,6 +79,16 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// When re-enabled, ensure listener is running
|
||||
if (_cancellationTokenSource == null)
|
||||
{
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
StartListening();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Unsubscribe from events
|
||||
@ -92,6 +102,12 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
_cancellationTokenSource?.Dispose();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Free the UDP port when this NPC gets disabled
|
||||
StopListening();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Auto-stop listening if no packets received for a while
|
||||
@ -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,13 +113,22 @@ 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()
|
||||
{
|
||||
StopListening();
|
||||
@ -127,6 +136,11 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
_cancellationTokenSource?.Dispose();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
StopListening();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Process playback queue
|
||||
|
||||
@ -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.
@ -7,6 +7,10 @@ public class NetworkConfig : ScriptableObject
|
||||
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