refactored scripts to avoid execution order issues
This commit is contained in:
@ -98,7 +98,7 @@ public class UDPAvatarReceiver : MonoBehaviour
|
||||
|
||||
if (enableReceiver)
|
||||
{
|
||||
StartUDPListener();
|
||||
StartCoroutine(WaitAndSubscribe());
|
||||
}
|
||||
|
||||
if (showDebugInfo)
|
||||
@ -199,14 +199,6 @@ public class UDPAvatarReceiver : MonoBehaviour
|
||||
{
|
||||
try
|
||||
{
|
||||
// Wait for shared listener to be ready
|
||||
if (Convai.Scripts.Runtime.Multiplayer.SharedUDPListener.Instance == null)
|
||||
{
|
||||
Debug.LogError("SharedUDPListener not found! Make sure it's in the scene.");
|
||||
enableReceiver = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Subscribe to shared listener
|
||||
Convai.Scripts.Runtime.Multiplayer.SharedUDPListener.Instance.OnPacketReceived += HandlePacketReceived;
|
||||
|
||||
@ -219,6 +211,23 @@ public class UDPAvatarReceiver : MonoBehaviour
|
||||
enableReceiver = false;
|
||||
}
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator WaitAndSubscribe()
|
||||
{
|
||||
float timeout = 3f;
|
||||
while (Convai.Scripts.Runtime.Multiplayer.SharedUDPListener.Instance == null && timeout > 0f)
|
||||
{
|
||||
timeout -= Time.unscaledDeltaTime;
|
||||
yield return null;
|
||||
}
|
||||
if (Convai.Scripts.Runtime.Multiplayer.SharedUDPListener.Instance == null)
|
||||
{
|
||||
Debug.LogError("SharedUDPListener not ready after wait.");
|
||||
enableReceiver = false;
|
||||
yield break;
|
||||
}
|
||||
StartUDPListener();
|
||||
}
|
||||
|
||||
void HandlePacketReceived(byte[] data, IPEndPoint senderEndPoint)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user