@@ -3,6 +3,16 @@ import { isBrowserEnvironment } from "../constants/is-browser-environment";
3
3
import { UnityLoaderStatus } from "../enums/unity-loader-status" ;
4
4
import { UnityConfig } from "../exports" ;
5
5
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
+
6
16
/**
7
17
* Hook to embed a Unity Loader script.
8
18
* @param source The source of the unity loader.
@@ -18,12 +28,12 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => {
18
28
// this scenario, the window is not available. We can't create a Unity
19
29
// Loader in this case.
20
30
if ( isBrowserEnvironment === false ) {
21
- return ;
31
+ return undefined ;
22
32
}
23
33
// If the script's source is null, we'll reset the status to idle.
24
34
if ( unityConfig . loaderUrl === null ) {
25
35
setStatus ( UnityLoaderStatus . Idle ) ;
26
- return ;
36
+ return undefined ;
27
37
}
28
38
/**
29
39
* Find existing script element by source. It may have been added by
@@ -78,7 +88,7 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => {
78
88
if ( script !== null ) {
79
89
script . removeEventListener ( "load" , setStateFromEvent ) ;
80
90
script . removeEventListener ( "error" , setStateFromEvent ) ;
81
- window . document . body . removeChild ( script ) ;
91
+ script . remove ( ) ;
82
92
}
83
93
} ;
84
94
} , [ unityConfig . loaderUrl ] ) ;
0 commit comments