fixed port conflicts
This commit is contained in:
@ -66,7 +66,7 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
|||||||
var cfg = networkConfigAsset != null ? networkConfigAsset : NetworkConfig.Instance;
|
var cfg = networkConfigAsset != null ? networkConfigAsset : NetworkConfig.Instance;
|
||||||
if (cfg != null)
|
if (cfg != null)
|
||||||
{
|
{
|
||||||
listenPort = cfg.port;
|
listenPort = cfg.multiplayerAudioPort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InitializeNetwork();
|
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()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
// Unsubscribe from events
|
// Unsubscribe from events
|
||||||
@ -92,6 +102,12 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
|||||||
_cancellationTokenSource?.Dispose();
|
_cancellationTokenSource?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDisable()
|
||||||
|
{
|
||||||
|
// Free the UDP port when this NPC gets disabled
|
||||||
|
StopListening();
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
// Auto-stop listening if no packets received for a while
|
// Auto-stop listening if no packets received for a while
|
||||||
@ -115,8 +131,13 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
|||||||
|
|
||||||
private void InitializeConvai()
|
private void InitializeConvai()
|
||||||
{
|
{
|
||||||
// Get target NPC
|
// Prefer local ConvaiNPC on the same GameObject, then fall back to active NPC
|
||||||
if (useActiveNPC)
|
var localNPC = GetComponent<ConvaiNPC>();
|
||||||
|
if (localNPC != null)
|
||||||
|
{
|
||||||
|
targetNPC = localNPC;
|
||||||
|
}
|
||||||
|
else if (useActiveNPC)
|
||||||
{
|
{
|
||||||
targetNPC = ConvaiNPCManager.Instance?.GetActiveConvaiNPC();
|
targetNPC = ConvaiNPCManager.Instance?.GetActiveConvaiNPC();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,7 +56,7 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
|||||||
if (cfg != null)
|
if (cfg != null)
|
||||||
{
|
{
|
||||||
targetIP = cfg.ipAddress;
|
targetIP = cfg.ipAddress;
|
||||||
targetPort = cfg.port;
|
targetPort = cfg.multiplayerAudioPort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InitializeNetwork();
|
InitializeNetwork();
|
||||||
|
|||||||
@ -113,13 +113,22 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
|||||||
var cfg = networkConfigAsset != null ? networkConfigAsset : NetworkConfig.Instance;
|
var cfg = networkConfigAsset != null ? networkConfigAsset : NetworkConfig.Instance;
|
||||||
if (cfg != null)
|
if (cfg != null)
|
||||||
{
|
{
|
||||||
listenPort = cfg.port;
|
listenPort = cfg.multiplayerSpeechPort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InitializeAudio();
|
InitializeAudio();
|
||||||
InitializeNetwork();
|
InitializeNetwork();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
if (_cancellationTokenSource == null)
|
||||||
|
{
|
||||||
|
_cancellationTokenSource = new CancellationTokenSource();
|
||||||
|
}
|
||||||
|
StartListening();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
StopListening();
|
StopListening();
|
||||||
@ -127,6 +136,11 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
|||||||
_cancellationTokenSource?.Dispose();
|
_cancellationTokenSource?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDisable()
|
||||||
|
{
|
||||||
|
StopListening();
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
// Process playback queue
|
// Process playback queue
|
||||||
|
|||||||
@ -62,7 +62,7 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
|||||||
if (cfg != null)
|
if (cfg != null)
|
||||||
{
|
{
|
||||||
targetIP = cfg.ipAddress;
|
targetIP = cfg.ipAddress;
|
||||||
targetPort = cfg.port;
|
targetPort = cfg.multiplayerSpeechPort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InitializeNetwork();
|
InitializeNetwork();
|
||||||
@ -93,8 +93,13 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
|||||||
|
|
||||||
private void InitializeConvai()
|
private void InitializeConvai()
|
||||||
{
|
{
|
||||||
// Get target NPC
|
// Prefer local ConvaiNPC on the same GameObject, then fall back to active NPC
|
||||||
if (useActiveNPC)
|
var localNPC = GetComponent<ConvaiNPC>();
|
||||||
|
if (localNPC != null)
|
||||||
|
{
|
||||||
|
sourceNPC = localNPC;
|
||||||
|
}
|
||||||
|
else if (useActiveNPC)
|
||||||
{
|
{
|
||||||
sourceNPC = ConvaiNPCManager.Instance?.GetActiveConvaiNPC();
|
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 string ipAddress = "127.0.0.1";
|
||||||
public int port = 8080;
|
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;
|
private static NetworkConfig _instance;
|
||||||
public static NetworkConfig Instance
|
public static NetworkConfig Instance
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user