Created
May 22, 2024 19:25
-
-
Save kirill578/77c5fa2cd7e2fa15ef6ff08dbef389f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Unity Page</title> | |
| <style> | |
| .red-div { | |
| background-color: red; | |
| width: 400px; | |
| height: 280px; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| color: white; | |
| font-size: 20px; | |
| } | |
| .input-field { | |
| width: 500px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="red-div">Unity goes here</div> | |
| <div> | |
| <button onclick="animateAvatar('idle')">Idle</button> | |
| <button onclick="animateAvatar('nod')">Nod</button> | |
| <button onclick="animateAvatar('wave')">Wave</button> | |
| </div> | |
| <div> | |
| <input type="text" class="input-field" id="audio-url" placeholder="Enter audio URL here" /> | |
| <button onclick="playAudio()">Play Audio</button> | |
| </div> | |
| <script> | |
| /* | |
| using System.Runtime.InteropServices; | |
| public class MyUnityClass : MonoBehaviour | |
| { | |
| [JSInvokable] | |
| public static void animateAvatar(string action) | |
| { | |
| Debug.Log("Message from JS: " + message); | |
| } | |
| [JSInvokable] | |
| public static void playAudio(string message) | |
| { | |
| Debug.Log("Message from JS: " + message); | |
| if (error) { | |
| Application.ExternalCall("onUnityError", 'error'); | |
| } else { | |
| Application.ExternalCall("onStatus", 'onAudioPlayingComplete'); | |
| } | |
| } | |
| } | |
| */ | |
| function animateAvatar(action) { | |
| console.log(action); | |
| // unityInstance.SendMessage('MyUnityClass', 'animateAvatar', action); | |
| } | |
| function playAudio() { | |
| const audioUrl = document.getElementById('audio-url').value; | |
| console.log(audioUrl); | |
| // unityInstance.SendMessage('MyUnityClass', 'playAudio', audioUrl); | |
| } | |
| function onUnityError(error) { | |
| console.log('Error: ' + error); | |
| } | |
| function onStatus(success) { | |
| console.log('Success: ' + success); | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment