add object select!!

This commit is contained in:
sjwie 2024-04-22 18:11:35 +09:00
parent 9f97ef6c93
commit 82b5159ed4
4 changed files with 40 additions and 3 deletions

View File

@ -1,7 +1,7 @@
"use client"; "use client";
import Image from "next/image"; import Image from "next/image";
import { useSearchParams } from "next/navigation"; import { useSearchParams } from "next/navigation";
import { Suspense } from "react"; import { Suspense, useCallback, useState } from "react";
import { Unity, UnityConfig, useUnityContext } from "react-unity-webgl"; import { Unity, UnityConfig, useUnityContext } from "react-unity-webgl";
const unityConfigBuilder: (path: string) => UnityConfig = (path) => ({ const unityConfigBuilder: (path: string) => UnityConfig = (path) => ({
loaderUrl: `${path}.loader.js`, loaderUrl: `${path}.loader.js`,
@ -33,10 +33,21 @@ const option = [
}, },
]; ];
const objOption = [
{
value: 0,
label: "frame1",
},
{
value: 1,
label: "frame2",
},
];
function UnityComponent() { function UnityComponent() {
const params = useSearchParams(); const params = useSearchParams();
const p = params.get("p"); const p = params.get("p");
console.log(p); const [selectedIndex, setSelectedIndex] = useState(0);
if (!p || isNaN(Number(p))) location.href = "/unity?p=0"; if (!p || isNaN(Number(p))) location.href = "/unity?p=0";
const { const {
@ -49,6 +60,19 @@ function UnityComponent() {
const loadingPercentage = Math.round(loadingProgression * 100); const loadingPercentage = Math.round(loadingProgression * 100);
const handleSelectIndex = useCallback(
(newValue: string) => {
console.log(newValue);
setSelectedIndex(Number(newValue));
UNSAFE__unityInstance?.SendMessage(
"Cube",
"HandleSelect",
Number(newValue),
);
},
[UNSAFE__unityInstance],
);
return ( return (
<> <>
<div className="mb-5 mt-5"> <div className="mb-5 mt-5">
@ -77,6 +101,19 @@ function UnityComponent() {
</option> </option>
))} ))}
</select> </select>
{Number(p) == 0 && (
<select
value={selectedIndex}
onChange={(e) => handleSelectIndex(e.target.value)}
className="ml-5 mt-5"
>
{objOption.map((o, i) => (
<option key={`${o.label}-${i}`} value={o.value}>
{o.label}
</option>
))}
</select>
)}
<Image <Image
src={"/unity/3d-test/TemplateData/fullscreen-button.png"} src={"/unity/3d-test/TemplateData/fullscreen-button.png"}
alt="전체 화면 버튼" alt="전체 화면 버튼"

File diff suppressed because one or more lines are too long