@@ -88,13 +88,15 @@ public class HelloARController : MonoBehaviour
88
88
89
89
// Settable parameters
90
90
public GameObject prefab ;
91
+ public ParticleSystem boost ;
91
92
public GameObject field ;
92
93
public GameObject ball ;
93
94
public GameObject namePrefab ;
94
95
public float scaleFactor = 1000f ;
95
96
public Material orangeCar ;
96
97
public Material blueCar ;
97
98
public GameObject planeGenerator ;
99
+ public Texture goalIndicator ;
98
100
99
101
// Instance objects
100
102
private GameObject ballObject ;
@@ -104,18 +106,27 @@ public class HelloARController : MonoBehaviour
104
106
private int currentFrame = 0 ;
105
107
private List < GameObject > cars = new List < GameObject > ( ) ;
106
108
private List < GameObject > names = new List < GameObject > ( ) ;
109
+ private List < ParticleSystem > boosts = new List < ParticleSystem > ( ) ;
107
110
private float hSliderValue = 1000f ;
108
111
private float localScale = 15f ;
109
-
112
+ private Dictionary < string , int > playerTeamMap = new Dictionary < string , int > ( ) ;
110
113
111
114
private string dataMsg ;
112
115
private string protoMsg ;
113
116
114
117
115
- private bool testing = true ;
118
+ public bool testing = true ;
119
+
120
+ public void Start ( )
121
+ {
122
+ Debug . Log ( "Proto: " + StaticReplayScript . proto ) ;
123
+ }
124
+
125
+
116
126
private void Spawn ( Vector3 position , Quaternion rotation , Transform parent )
117
127
{
118
128
var gameData = StaticReplayScript . gameData ;
129
+ Proto proto = StaticReplayScript . proto ;
119
130
// Choose the Andy model for the Trackable that got hit.
120
131
// Instantiate Andy model at the hit pose.
121
132
fieldObject = Instantiate ( this . field , position , rotation ) ;
@@ -133,7 +144,7 @@ private void Spawn(Vector3 position, Quaternion rotation, Transform parent)
133
144
rootObject . transform . localScale = new Vector3 ( 1 / scaleFactor , 1 / scaleFactor , 1 / scaleFactor ) ;
134
145
fieldObject . transform . parent = rootObject . transform ;
135
146
fieldObject . transform . localPosition = new Vector3 ( 0f , - 10f , 0f ) ;
136
- fieldObject . transform . localScale = new Vector3 ( 63 * 1000 / scaleFactor , 63 * 1000 / scaleFactor , 63 * 1000 / scaleFactor ) ;
147
+ fieldObject . transform . localScale = new Vector3 ( 65 * 1000 / scaleFactor , 65 * 1000 / scaleFactor , 65 * 1000 / scaleFactor ) ;
137
148
fieldObject . transform . localRotation = Quaternion . Euler ( 0f , - 90f , 0f ) ;
138
149
for ( int i = 0 ; i < gameData . players . Count ; i ++ )
139
150
{
@@ -144,16 +155,41 @@ private void Spawn(Vector3 position, Quaternion rotation, Transform parent)
144
155
car . transform . parent = rootObject . transform ;
145
156
car . transform . localPosition = new Vector3 ( x , y , z ) ;
146
157
//car.transform.localScale = new Vector3(120 * 1000 / scaleFactor, 120 * 1000 / scaleFactor, 120 * 1000 / scaleFactor);
147
- car . GetComponent < Renderer > ( ) . material = gameData . colors [ i ] == 0 ? blueCar : orangeCar ;
158
+ var renderer = car . transform . Find ( "carrosserie" ) . GetComponent < Renderer > ( ) ;
159
+ var materials = renderer . materials ;
160
+ materials [ 0 ] = gameData . colors [ i ] == 0 ? blueCar : orangeCar ;
161
+ renderer . materials = materials ;
162
+
163
+
164
+ var animatable = car . transform . Find ( "Animatable" ) ;
165
+ foreach ( Transform child in animatable )
166
+ {
167
+ var childRenderer = child . GetComponent < Renderer > ( ) ;
168
+ var childMaterials = childRenderer . materials ;
169
+ childMaterials [ 0 ] = gameData . colors [ i ] == 0 ? blueCar : orangeCar ;
170
+ childRenderer . materials = childMaterials ;
171
+ }
172
+ //car.GetComponent<Renderer>().material = gameData.colors[i] == 0 ? blueCar : orangeCar;
148
173
car . name = gameData . names [ i ] ;
149
174
cars . Add ( car ) ;
150
175
151
-
176
+ var boostObj = Instantiate ( this . boost , new Vector3 ( 0f , 0f , 0f ) , Quaternion . identity ) ;
177
+ boostObj . transform . parent = car . transform ;
178
+ boostObj . transform . localPosition = new Vector3 ( 0f , 0f , 0f ) ;
179
+ boostObj . transform . localRotation = Quaternion . Euler ( - 180f , 0f , 0f ) ;
180
+ var boostScale = 50f ;
181
+ boostObj . transform . localScale = new Vector3 ( 1 / boostScale , 1 / boostScale , 1 / boostScale ) ;
182
+ boostObj . GetComponent < ParticleSystem > ( ) . Stop ( ) ;
183
+ boosts . Add ( boostObj ) ;
152
184
var name = Instantiate ( namePrefab , new Vector3 ( 0f , 0f , 0f ) , Quaternion . identity ) ;
153
185
name . GetComponent < TextMesh > ( ) . text = gameData . names [ i ] ;
154
186
name . transform . parent = rootObject . transform ;
155
187
name . transform . localPosition = new Vector3 ( x , y + 1.0f , z ) ;
156
188
names . Add ( name ) ; // needed so we can look at camera all the time
189
+ Debug . Log ( "Count " + ( proto == null ) ) ;
190
+ Debug . Log ( proto . players [ i ] ) ;
191
+ Debug . Log ( proto . players [ i ] . isOrange ) ;
192
+ playerTeamMap [ proto . players [ i ] . id . id ] = proto . players [ i ] . isOrange ;
157
193
}
158
194
ballObject = Instantiate ( ball , new Vector3 ( 0f , 0f , 0f ) , Quaternion . identity ) ;
159
195
ballObject . transform . parent = rootObject . transform ;
@@ -169,10 +205,10 @@ public void Update()
169
205
{
170
206
if ( ! testing )
171
207
{
172
-
173
208
_UpdateApplicationLifecycle ( ) ;
174
209
}
175
210
var gameData = StaticReplayScript . gameData ;
211
+ var proto = StaticReplayScript . proto ;
176
212
if ( ! testing )
177
213
{
178
214
// Hide snackbar when currently tracking at least one plane.
@@ -197,16 +233,16 @@ public void Update()
197
233
{
198
234
//SceneManager.LoadScene("LoadData");
199
235
}
200
- if ( testing && gameData != null )
236
+ if ( testing && gameData != null && proto != null )
201
237
{
202
238
GameObject empty = new GameObject ( "Empty" ) ;
203
239
scaleFactor = 1000f ;
204
240
Spawn ( new Vector3 ( 0f , 0f , 0f ) , Quaternion . identity , empty . transform ) ;
205
-
241
+
206
242
FirstPersonCamera . transform . position = new Vector3 ( 0.5f , 0.5f , 0.5f ) ;
207
243
FirstPersonCamera . transform . LookAt ( empty . transform ) ;
208
244
}
209
- else
245
+ else if ( ! testing )
210
246
{
211
247
212
248
Touch touch ;
@@ -234,7 +270,7 @@ public void Update()
234
270
{
235
271
var anchor = hit . Trackable . CreateAnchor ( hit . Pose ) ;
236
272
Spawn ( hit . Pose . position , hit . Pose . rotation , anchor . transform ) ;
237
-
273
+
238
274
}
239
275
}
240
276
}
@@ -253,10 +289,10 @@ public void Update()
253
289
for ( int i = 0 ; i < cars . Count ; i ++ )
254
290
{
255
291
var frameData = gameData . players [ i ] [ currentFrame ] ;
256
- float x = ( float ) ( double ) frameData [ 0 ] / localScale ;
257
- float y = ( float ) ( double ) frameData [ 2 ] / localScale ;
258
- float z = ( float ) ( double ) frameData [ 1 ] / localScale ;
259
-
292
+ float x = ( float ) ( double ) frameData [ 0 ] / localScale ;
293
+ float y = ( float ) ( double ) frameData [ 2 ] / localScale ;
294
+ float z = ( float ) ( double ) frameData [ 1 ] / localScale ;
295
+
260
296
var PI = ( double ) 3.14159265 ;
261
297
262
298
var xOffset = ( double ) 0 ;
@@ -270,17 +306,33 @@ public void Update()
270
306
var rotY = ( ( double ) frameData [ 4 ] / ( 2 * PI ) + yOffset ) * yCoeff * 360 ; // yaw
271
307
var rotZ = ( ( double ) frameData [ 5 ] / ( 2 * PI ) + zOffset ) * zCoeff * 360 ; // roll
272
308
273
- var rotation = Quaternion . AngleAxis ( ( float ) rotY , Vector3 . up ) * // yaw
309
+ var rotation = Quaternion . AngleAxis ( ( float ) rotY , Vector3 . up ) * // yaw
274
310
Quaternion . AngleAxis ( ( float ) rotX , Vector3 . right ) *
275
- Quaternion . AngleAxis ( ( float ) rotZ , Vector3 . forward ) ;
311
+ Quaternion . AngleAxis ( ( float ) rotZ , Vector3 . forward ) ;
276
312
cars [ i ] . transform . localPosition = new Vector3 ( x , y , z ) ;
277
313
//cars[i].transform.localEulerAngles = new Vector3((float) rotZ, (float) rotY + 90, (float) rotX);
278
314
cars [ i ] . transform . localRotation = rotation ;
315
+
316
+ if ( frameData [ 6 ] is bool )
317
+ {
318
+
319
+ ParticleSystem boostObj = boosts [ i ] . GetComponent < ParticleSystem > ( ) ;
320
+ bool shouldBeEmitting = ( bool ) frameData [ 6 ] ;
321
+ if ( shouldBeEmitting && boostObj . isStopped )
322
+ {
323
+ boostObj . Play ( ) ;
324
+ }
325
+ else if ( ! shouldBeEmitting && ! boostObj . isStopped )
326
+ {
327
+ boostObj . Stop ( ) ;
328
+ }
329
+
330
+ }
279
331
names [ i ] . transform . localPosition = new Vector3 ( x , y + 0.5f , z ) ;
280
332
names [ i ] . transform . LookAt ( FirstPersonCamera . transform ) ;
281
333
names [ i ] . transform . Rotate ( Vector3 . up - new Vector3 ( 0 , 180 , 0 ) ) ;
282
334
}
283
-
335
+
284
336
float ballx = ( float ) gameData . ball [ currentFrame ] [ 0 ] / localScale ;
285
337
float bally = ( float ) gameData . ball [ currentFrame ] [ 2 ] / localScale ;
286
338
float ballz = ( float ) gameData . ball [ currentFrame ] [ 1 ] / localScale ;
@@ -291,7 +343,7 @@ public void Update()
291
343
292
344
var currentFrameTime = gameData . frames [ currentFrame ] [ 2 ] ;
293
345
var nextFrameTime = gameData . frames [ currentFrame + 1 ] [ 2 ] ;
294
- Debug . Log ( currentFrameTime . ToString ( ) ) ;
346
+ // Debug.Log(currentFrameTime.ToString());
295
347
if ( currentTime > nextFrameTime )
296
348
{
297
349
currentFrame += 1 ;
@@ -311,7 +363,8 @@ void DrawQuad(Rect position, Color color)
311
363
public void OnGUI ( )
312
364
{
313
365
var width = Screen . width ;
314
- var zoomOut = GUI . Button ( new Rect ( width * 2 / 10 , 25 , width / 25 , width / 25 ) , "-" ) ;
366
+ var height = Screen . height ;
367
+ var zoomOut = GUI . Button ( new Rect ( width * 2 / 10 , 25 , width / 25 , width / 25 ) , "-" ) ;
315
368
var zoomIn = GUI . Button ( new Rect ( width * 3 / 10 , 25 , width / 25 , width / 25 ) , "+" ) ;
316
369
if ( zoomOut )
317
370
{
@@ -328,7 +381,7 @@ public void OnGUI()
328
381
// Scoreboard
329
382
int offset = 100 ;
330
383
Color orange = new Color ( 1F , 0.64F , 0F ) ;
331
- var halfway = width / 2 ;
384
+ var halfway = width / 2 ;
332
385
GUIStyle timeStyle = new GUIStyle ( ) ;
333
386
timeStyle . fontSize = 30 ;
334
387
timeStyle . fontStyle = FontStyle . Bold ;
@@ -341,8 +394,30 @@ public void OnGUI()
341
394
timeRemaining = ( int ) StaticReplayScript . gameData . frames [ currentFrame ] [ 1 ] ;
342
395
}
343
396
//int timeRemaining = 175;
344
- int minRemaining = timeRemaining / 60 ;
397
+ int minRemaining = timeRemaining / 60 ;
345
398
GUI . Label ( new Rect ( halfway , 35 , 50 , 50 ) , String . Format ( "{0}:{1:D2}" , minRemaining , timeRemaining % ( minRemaining * 60 ) ) , timeStyle ) ;
399
+
400
+
401
+ var team0Score = 0 ;
402
+ var team1Score = 0 ;
403
+ if ( StaticReplayScript . proto != null )
404
+ {
405
+ foreach ( Goal g in StaticReplayScript . proto . gameMetadata . goals )
406
+ {
407
+ if ( g . frameNumber < currentFrame )
408
+ {
409
+ int playerTeam = playerTeamMap [ g . playerId . id ] ;
410
+ if ( playerTeam == 0 )
411
+ {
412
+ team0Score += 1 ;
413
+ }
414
+ else
415
+ {
416
+ team1Score += 1 ;
417
+ }
418
+ }
419
+ }
420
+ }
346
421
for ( int i = 0 ; i < 2 ; i ++ )
347
422
{
348
423
Color teamColor = ( i == 0 ) ? Color . blue : ( orange ) ;
@@ -356,11 +431,11 @@ public void OnGUI()
356
431
///style.font = new Font("Liberation Sans");
357
432
style . fontSize = 30 ;
358
433
style . fontStyle = FontStyle . Bold ;
359
-
434
+
360
435
style . normal . textColor = Color . white ;
361
436
style . alignment = TextAnchor . MiddleCenter ;
362
-
363
- GUI . Label ( position , i . ToString ( ) , style ) ;
437
+
438
+ GUI . Label ( position , ( i == 0 ? team0Score : team1Score ) . ToString ( ) , style ) ;
364
439
//Color oldColor = GUI.backgroundColor;
365
440
//GUI.backgroundColor = (i == 0) ? Color.blue : Color.red*Color.yellow;
366
441
//GUI.backgroundColor = oldColor;
@@ -369,10 +444,33 @@ public void OnGUI()
369
444
370
445
}
371
446
RootObject gameData = StaticReplayScript . gameData ;
372
- if ( gameData != null )
447
+ Proto proto = StaticReplayScript . proto ;
448
+ if ( gameData != null && proto != null && fieldObject != null )
373
449
{
374
- currentTime = GUI . HorizontalSlider ( new Rect ( 250 + 150 , 35 , 200 , 30 ) , currentTime , ( float ) gameData . frames [ 0 ] [ 2 ] , ( float ) gameData . frames [ gameData . frames . Count - 1 ] [ 2 ] ) ;
375
-
450
+ var logoWidth = width / 60 ;
451
+ var nextFrame = ( int ) GUI . HorizontalSlider ( new Rect ( 0 , 19 / 20f * height , width , height / 20f ) , currentFrame , 0 , gameData . frames . Count ) ;
452
+ if ( nextFrame != currentFrame )
453
+ {
454
+ currentFrame = nextFrame ;
455
+ currentTime = ( float ) gameData . frames [ nextFrame ] [ 2 ] ;
456
+ }
457
+ for ( int i = 0 ; i < proto . gameMetadata . goals . Count ; i ++ )
458
+ {
459
+ Goal g = proto . gameMetadata . goals [ i ] ;
460
+ var frame = g . frameNumber ;
461
+ var size = new Rect ( ( width * frame / ( float ) gameData . frames . Count ) - logoWidth / 2 , 18 / 20f * height , logoWidth , logoWidth ) ;
462
+ if ( playerTeamMap . ContainsKey ( g . playerId . id ) )
463
+ {
464
+ Color teamColor = playerTeamMap [ g . playerId . id ] == 0 ? Color . blue : ( orange ) ;
465
+ DrawQuad ( size , teamColor ) ;
466
+ }
467
+ else
468
+ {
469
+ Debug . Log ( string . Format ( "{0} is not in {1}" , g . playerId . id , playerTeamMap . Keys . Count ) ) ;
470
+ }
471
+
472
+ GUI . Box ( size , goalIndicator ) ;
473
+ }
376
474
}
377
475
378
476
@@ -389,7 +487,7 @@ public void OnGUI()
389
487
var style = new GUIStyle ( ) ;
390
488
style . fontSize = 20 ;
391
489
style . fontStyle = FontStyle . Bold ;
392
- GUI . Label ( new Rect ( 0 , width / 10 , width / 5 , width / 10 ) , dataMsg , style ) ;
490
+ GUI . Label ( new Rect ( 0 , width / 10 , width / 5 , width / 10 ) , dataMsg , style ) ;
393
491
}
394
492
if ( protoMsg != null )
395
493
{
0 commit comments