Skip to content

Commit

Permalink
Merge pull request #3267 from KBVE/patch-zeta-vuplex-error-handling-1…
Browse files Browse the repository at this point in the history
…1-18-2024-1731927676

[CI] Merge patch-zeta-vuplex-error-handling-11-18-2024-1731927676 into dev
  • Loading branch information
h0lybyte authored Nov 18, 2024
2 parents 808b7c1 + e2b938e commit ea9e108
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions packages/kilonet/kilonet/Utils/VuplexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ namespace KBVE.Kilonet.Utils
public class VuplexHelper : MonoBehaviour
{
public Canvas CanvasObject;
public BaseWebViewPrefab CanvasWebViewPrefab;

public BaseWebViewPrefab CanvasWebViewPrefab;
public CanvasWebViewPrefab CanvasWebViewPrefab;

public CanvasWebViewPrefab CanvasWebViewPrefabView;
private CanvasWebViewPrefab _canvasWebViewPrefab;

private Supabase.Client _supabaseClient;
Expand All @@ -29,10 +28,11 @@ private void Start()
{
try
{
// Use UniTask to manage initialization
InitializeWebView().Forget(); // Use UniTask's Forget to run async without awaiting
await UniTask.WhenAll(
InitializeWebView().Timeout(TimeSpan.FromSeconds(10)),
InitializeSupabaseClientAsync().Timeout(TimeSpan.FromSeconds(10))
);

InitializeSupabaseClientAsync().Forget(); // Initialize Supabase client asynchronously
}
catch (Exception ex)
{
Expand All @@ -55,28 +55,22 @@ private async UniTaskVoid InitializeWebView()
return;
}

// Attempt to locate the CanvasWebViewPrefabView inside CanvasWebViewPrefab
Transform prefabViewTransform = CanvasWebViewPrefab.transform.Find("CanvasWebViewPrefabView");
if (prefabViewTransform == null)
{
Debug.LogError("Failed to locate CanvasWebViewPrefabView inside CanvasWebViewPrefab.");
return;
}

_canvasWebViewPrefab = prefabViewTransform.GetComponent<CanvasWebViewPrefab>();
if (_canvasWebViewPrefab == null)
if (CanvasWebViewPrefabView == null)
{
Debug.LogError("CanvasWebViewPrefabView does not have a CanvasWebViewPrefab component.");
Debug.LogError("CanvasWebViewPrefabView is not set in the Unity Editor.");
return;
}

await _canvasWebViewPrefab.WaitUntilInitialized();
// Ensure CanvasWebViewPrefabView is properly initialized
await CanvasWebViewPrefabView.WaitUntilInitialized();

_canvasWebViewPrefab.WebView.MessageEmitted += OnMessageReceived;
// Register message handling
CanvasWebViewPrefabView.WebView.MessageEmitted += OnMessageReceived;
Debug.Log("Vuplex CanvasWebView successfully initialized and ready to receive messages.");
}



private async UniTaskVoid InitializeSupabaseClientAsync()
{
try
Expand Down

0 comments on commit ea9e108

Please sign in to comment.