"use client"; import Image from "next/image"; import { useSearchParams } from "next/navigation"; import { Suspense } from "react"; import { Unity, UnityConfig, useUnityContext } from "react-unity-webgl"; const unityConfigBuilder: (path: string) => UnityConfig = (path) => ({ loaderUrl: `${path}.loader.js`, dataUrl: `${path}.data`, frameworkUrl: `${path}.framework.js`, codeUrl: `${path}.wasm`, streamingAssetsUrl: "StreamingAssets", companyName: "DTOL", productName: "3d-test", productVersion: "0.1", }); const option = [ { value: "/unity/3d-test/Build/3d-test", name: "3d-test" }, { value: "/unity/kartrider/Build/kartrider", name: "kartrider" }, { value: "/unity/test-project/build", name: "test-project" }, ]; function UnityComponent() { const params = useSearchParams(); const p = params.get("p"); console.log(p); if (!p || isNaN(Number(p))) location.href = "/unity?p=0"; const { unityProvider, isLoaded, loadingProgression, initialisationError, UNSAFE__unityInstance, } = useUnityContext(unityConfigBuilder(option[Number(p)].value)); const loadingPercentage = Math.round(loadingProgression * 100); return ( <>
Loading... ({loadingPercentage}%)