1+ const rootPath = 'TemplateData' ;
2+
3+ function UnityProgress ( gameInstance , progress ) {
4+ if ( ! gameInstance . Module ) {
5+ return ;
6+ }
7+
8+ if ( ! gameInstance . logo ) {
9+ gameInstance . logo = document . createElement ( "div" ) ;
10+ gameInstance . logo . className = "logo " + gameInstance . Module . splashScreenStyle ;
11+ gameInstance . container . appendChild ( gameInstance . logo ) ;
12+ }
13+
14+ if ( ! gameInstance . progress ) {
15+ gameInstance . progress = document . createElement ( "div" ) ;
16+ gameInstance . progress . className = "progress " + gameInstance . Module . splashScreenStyle ;
17+ gameInstance . progress . empty = document . createElement ( "div" ) ;
18+ gameInstance . progress . empty . className = "empty" ;
19+ gameInstance . progress . appendChild ( gameInstance . progress . empty ) ;
20+ gameInstance . progress . full = document . createElement ( "div" ) ;
21+ gameInstance . progress . full . className = "full" ;
22+ gameInstance . progress . appendChild ( gameInstance . progress . full ) ;
23+ gameInstance . container . appendChild ( gameInstance . progress ) ;
24+ gameInstance . textProgress = document . createElement ( "div" ) ;
25+ gameInstance . textProgress . className = "text" ;
26+ gameInstance . container . appendChild ( gameInstance . textProgress ) ;
27+ }
28+
29+ gameInstance . progress . full . style . width = ( 100 * progress ) + "%" ;
30+ gameInstance . progress . empty . style . width = ( 100 * ( 1 - progress ) ) + "%" ;
31+ gameInstance . textProgress . innerHTML = 'Loading: ' + Math . floor ( progress * 100 ) + '%' + ' <img src="' + rootPath + '/gears.gif" class="spinner" />' ;
32+
33+ if ( progress == 1 ) {
34+ gameInstance . textProgress . innerHTML = 'Running, Please Wait.. <img src="' + rootPath + '/gears.gif" class="spinner" />' ;
35+ }
36+
37+ if ( progress == 'complete' ) {
38+ SendMessage = gameInstance . SendMessage ;
39+ gameInstance . logo . style . display = 'none' ;
40+ gameInstance . progress . style . display = 'none' ;
41+ gameInstance . textProgress . style . display = 'none' ;
42+ }
43+ }
44+
45+ window . Game = ( function ( ) {
46+ var Game = function ( ) {
47+ this . registerEvents ( ) ;
48+ } ;
49+
50+ Game . prototype . registerEvents = function ( ) {
51+ var _this = this ;
52+ /*
53+ window.addEventListener("keydown", function(e) {
54+ // space and arrow keys
55+ if ([8, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
56+ e.preventDefault();
57+ }
58+ }, false);
59+
60+ document.onmousedown = function() {
61+ window.focus();
62+ };
63+ */
64+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
65+ _this . resize ( ) ;
66+ } , false ) ;
67+
68+ window . addEventListener ( 'resize' , function ( ) {
69+ setTimeout ( function ( ) {
70+ _this . resize ( ) ;
71+ } , 1000 ) ;
72+ } , false ) ;
73+ } ;
74+
75+ Game . prototype . getQueryVariable = function ( variable ) {
76+ var query = window . location . search . substring ( 1 ) ;
77+ var vars = query . split ( "&" ) ;
78+ for ( var i = 0 ; i < vars . length ; i ++ ) {
79+ var pair = vars [ i ] . split ( "=" ) ;
80+ if ( pair [ 0 ] == variable ) {
81+ return pair [ 1 ] ;
82+ }
83+ }
84+ return ( false ) ;
85+ }
86+
87+ Game . prototype . resize = function ( ) {
88+ var gameContainer = document . getElementById ( 'gameContainer' ) ;
89+ var canvas = document . getElementById ( '#canvas' ) ;
90+
91+ var ratioTolerant = this . getQueryVariable ( 'ratio_tolerant' ) ;
92+ var gameSizeRatio = gameContainer . getAttribute ( 'width' ) / gameContainer . getAttribute ( 'height' ) ;
93+
94+ if ( ( ! document . mozFullScreen && ! document . webkitIsFullScreen ) ) {
95+ //FullScreen is disabled
96+ var maxHeight = window . innerHeight - 43 ; // minus the footer
97+ } else {
98+ //FullScreen is enabled
99+ var maxHeight = window . innerHeight ; // minus the footer
100+
101+ }
102+
103+ //var maxHeight = window.innerHeight - 43; // minus the footer
104+ var maxWidth = window . innerWidth ;
105+ var windowSizeRatio = maxWidth / maxHeight ;
106+ var newStyle = {
107+ width : gameContainer . getAttribute ( 'width' ) ,
108+ height : gameContainer . getAttribute ( 'height' )
109+ } ;
110+ if ( ratioTolerant ) {
111+ if ( ratioTolerant == 'true' ) {
112+ newStyle = {
113+ width : maxWidth ,
114+ height : maxHeight
115+ } ;
116+ } else if ( ratioTolerant == 'false' ) {
117+ if ( gameSizeRatio > windowSizeRatio ) {
118+ newStyle = {
119+ width : maxWidth ,
120+ height : maxWidth / gameSizeRatio
121+ } ;
122+ } else {
123+ newStyle = {
124+ width : maxHeight * gameSizeRatio ,
125+ height : maxHeight
126+ } ;
127+ }
128+ }
129+
130+ this . updateStyle ( gameContainer , newStyle ) ;
131+ // canvas does not exists on page load
132+ if ( canvas ) {
133+ this . updateStyle ( canvas , newStyle ) ;
134+ }
135+ }
136+ } ;
137+
138+ Game . prototype . updateStyle = function ( element , size ) {
139+ element . setAttribute ( 'width' , size . width ) ;
140+ element . setAttribute ( 'height' , size . height ) ;
141+ element . style . width = size . width + 'px' ;
142+ element . style . height = size . height + 'px' ;
143+ } ;
144+
145+ return Game ;
146+ } ) ( ) ;
147+
148+ var game = new Game ( ) ;
0 commit comments