refactored scripts to avoid execution order issues
This commit is contained in:
@ -64,7 +64,7 @@ public class VRExperimentController : MonoBehaviour
|
||||
}
|
||||
|
||||
InitializeObjectMaps();
|
||||
StartUDPListener();
|
||||
StartCoroutine(WaitAndSubscribe());
|
||||
|
||||
// Initially deactivate all objects and avatars
|
||||
DeactivateAllObjects();
|
||||
@ -193,13 +193,6 @@ public class VRExperimentController : MonoBehaviour
|
||||
{
|
||||
try
|
||||
{
|
||||
// Wait for shared listener to be ready
|
||||
if (Convai.Scripts.Runtime.Multiplayer.SharedUDPListener.Instance == null)
|
||||
{
|
||||
LogError("SharedUDPListener not found! Make sure it's in the scene.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Subscribe to shared listener
|
||||
Convai.Scripts.Runtime.Multiplayer.SharedUDPListener.Instance.OnPacketReceived += HandlePacketReceived;
|
||||
isListening = true;
|
||||
@ -212,6 +205,22 @@ public class VRExperimentController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private 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)
|
||||
{
|
||||
LogError("SharedUDPListener not ready after wait.");
|
||||
yield break;
|
||||
}
|
||||
StartUDPListener();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle packet received from shared listener
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user