Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Merge patch-atomic-vuplex-helper-adjustment-11-18-2024-1731921963 into dev #3265

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 15 additions & 29 deletions packages/kilonet/kilonet/Utils/VuplexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ namespace KBVE.Kilonet.Utils
{
public class VuplexHelper : MonoBehaviour
{
public string CanvasObjectName = "Canvas";
public string CanvasWebViewPrefabName = "CanvasWebViewPrefab";
public string CanvasWebViewPrefabViewName = "CanvasWebViewPrefabView";
public GameObject CanvasObject;
public GameObject CanvasWebViewPrefab;

private CanvasWebViewPrefab _canvasWebViewPrefab;

Expand All @@ -30,7 +29,7 @@ private void Start()
{
// Use UniTask to manage initialization
InitializeWebView().Forget(); // Use UniTask's Forget to run async without awaiting

InitializeSupabaseClientAsync().Forget(); // Initialize Supabase client asynchronously
}
catch (Exception ex)
Expand All @@ -42,45 +41,31 @@ private void Start()

private async UniTaskVoid InitializeWebView()
{
GameObject canvasObject = GameObject.Find(CanvasObjectName);
if (canvasObject == null)
if (CanvasObject == null)
{
Debug.LogError($"No GameObject found with the name {CanvasObjectName}");
Debug.LogError("CanvasObject is not set in the Unity Editor.");
return;
}

Transform canvasWebViewPrefabTransform = canvasObject.transform.Find(CanvasWebViewPrefabName);
if (canvasWebViewPrefabTransform == null)
if (CanvasWebViewPrefab == null)
{
Debug.LogError(
$"No GameObject found with the name {CanvasWebViewPrefabName} under {CanvasObjectName}."
);
Debug.LogError("CanvasWebViewPrefab is not set in the Unity Editor.");
return;
}

Transform canvasWebViewPrefabViewTransform = canvasWebViewPrefabTransform.Find(
CanvasWebViewPrefabViewName
);
if (canvasWebViewPrefabViewTransform == null)
// Attempt to locate the CanvasWebViewPrefabView inside CanvasWebViewPrefab
Transform prefabViewTransform = CanvasWebViewPrefab.transform.Find("CanvasWebViewPrefabView");
if (prefabViewTransform == null)
{
Debug.LogError(
$"No GameObject found with the name {CanvasWebViewPrefabViewName} under {CanvasWebViewPrefabName}."
);
Debug.LogError("Failed to locate CanvasWebViewPrefabView inside CanvasWebViewPrefab.");
return;
}

_canvasWebViewPrefab = canvasWebViewPrefabViewTransform.GetComponent<CanvasWebViewPrefab>();
_canvasWebViewPrefab = prefabViewTransform.GetComponent<CanvasWebViewPrefab>();
if (_canvasWebViewPrefab == null)
{
_canvasWebViewPrefab = canvasWebViewPrefabTransform.GetComponent<CanvasWebViewPrefab>();

if (_canvasWebViewPrefab == null)
{
Debug.LogError(
"Failed to locate the CanvasWebViewPrefab component after multiple attempts."
);
return;
}
Debug.LogError("CanvasWebViewPrefabView does not have a CanvasWebViewPrefab component.");
return;
}

await _canvasWebViewPrefab.WaitUntilInitialized();
Expand All @@ -89,6 +74,7 @@ private async UniTaskVoid InitializeWebView()
Debug.Log("Vuplex CanvasWebView successfully initialized and ready to receive messages.");
}


private async UniTaskVoid InitializeSupabaseClientAsync()
{
try
Expand Down