@@ -3,6 +3,16 @@ import { isBrowserEnvironment } from "../constants/is-browser-environment";
33import { UnityLoaderStatus } from "../enums/unity-loader-status" ;
44import { UnityConfig } from "../exports" ;
55
6+ interface ScriptData {
7+ count : number ;
8+ status : UnityLoaderStatus ;
9+ handleLoad ?: ( ) => void ;
10+ handleError ?: ( ) => void ;
11+ }
12+
13+ // Map to track script references, status, and event handlers.
14+ const scriptReferenceMap = new Map < string , ScriptData > ( ) ;
15+
616/**
717 * Hook to embed a Unity Loader script.
818 * @param source The source of the unity loader.
@@ -18,12 +28,12 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => {
1828 // this scenario, the window is not available. We can't create a Unity
1929 // Loader in this case.
2030 if ( isBrowserEnvironment === false ) {
21- return ;
31+ return undefined ;
2232 }
2333 // If the script's source is null, we'll reset the status to idle.
2434 if ( unityConfig . loaderUrl === null ) {
2535 setStatus ( UnityLoaderStatus . Idle ) ;
26- return ;
36+ return undefined ;
2737 }
2838 /**
2939 * Find existing script element by source. It may have been added by
@@ -78,7 +88,7 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => {
7888 if ( script !== null ) {
7989 script . removeEventListener ( "load" , setStateFromEvent ) ;
8090 script . removeEventListener ( "error" , setStateFromEvent ) ;
81- window . document . body . removeChild ( script ) ;
91+ script . remove ( ) ;
8292 }
8393 } ;
8494 } , [ unityConfig . loaderUrl ] ) ;
0 commit comments