forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (51 loc) · 1.69 KB
/
Copy pathscript.js
File metadata and controls
59 lines (51 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { getApplication } from './globals.js';
/**
* @import { AppBase } from './app-base.js'
*/
/**
* @callback CreateScreenCallback
* Callback used by {@link script.createLoadingScreen}.
* @param {AppBase} app - The application.
* @returns {void}
*/
// flag to avoid creating multiple loading screens e.g. when
// loading screen scripts are reloaded
let _createdLoadingScreen = false;
/**
* The script namespace holds the createLoadingScreen function that is used to override the default
* PlayCanvas loading screen.
*
* @namespace
* @category Script
*/
const script = {
// set during script load to be used for initializing script
app: null,
/**
* Handles the creation of the loading screen of the application. A script can subscribe to the
* events of a {@link AppBase} to show a loading screen, progress bar etc. In order for
* this to work you need to set the project's loading screen script to the script that calls
* this method.
*
* @param {CreateScreenCallback} callback - A function which can set up and tear down a
* customized loading screen.
* @example
* pc.script.createLoadingScreen((app) => {
* const showSplashScreen = () => {};
* const hideSplashScreen = () => {};
* const showProgress = (progress) => {};
* app.on("preload:start", showSplashScreen);
* app.on("preload:progress", showProgress);
* app.on("start", hideSplashScreen);
* });
*/
createLoadingScreen(callback) {
if (_createdLoadingScreen) {
return;
}
_createdLoadingScreen = true;
const app = getApplication();
callback(app);
}
};
export { script };