File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 11import { useCallback , useEffect , useMemo , useState } from "react" ;
2- import { Unity , useUnityContext , useUnityMetricsInfo } from "react-unity-webgl" ;
2+ import {
3+ Unity ,
4+ useUnityContext ,
5+ useUnityMetricsInfo ,
6+ UnityCacheControlMode ,
7+ } from "react-unity-webgl" ;
38import "./game.css" ;
49
510export function Game ( ) {
611 const [ score , setScore ] = useState ( 0 ) ;
712 const [ isStarted , setIsStarted ] = useState ( false ) ;
813
14+ const cacheControl = useCallback ( ( url : string ) : UnityCacheControlMode => {
15+ if ( url . endsWith ( ".wasm" ) || url . endsWith ( ".data" ) ) {
16+ return "immutable" ;
17+ }
18+ return "no-store" ;
19+ } , [ ] ) ;
20+
921 const {
1022 loadingProgression,
1123 unityProvider,
@@ -22,6 +34,7 @@ export function Game() {
2234 companyName : "Jeffrey Lanters" ,
2335 productName : "Crate Clicker" ,
2436 productVersion : "1.0.0" ,
37+ cacheControl : cacheControl ,
2538 } ) ;
2639
2740 const { fps } = useUnityMetricsInfo ( getMetricsInfo , {
@@ -72,7 +85,9 @@ export function Game() {
7285 />
7386 </ div >
7487 < div className = "score-display" > { score } </ div >
75- { ! isNaN ( fps ) && < div className = "fps-counter" > { Math . round ( fps ) } FPS</ div > }
88+ { fps && ! isNaN ( fps ) && (
89+ < div className = "fps-counter" > { Math . round ( fps ) } FPS</ div >
90+ ) }
7691 < Unity
7792 unityProvider = { unityProvider }
7893 devicePixelRatio = { window . devicePixelRatio }
You can’t perform that action at this time.
0 commit comments