Skip to content

Commit 870657e

Browse files
committed
Goal explosions and flipped X
1 parent 22bd9a2 commit 870657e

File tree

6 files changed

+4832
-22
lines changed

6 files changed

+4832
-22
lines changed

Assets/GoogleARCore/Examples/HelloAR/Scenes/HelloAR.unity

+3
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,16 @@ MonoBehaviour:
275275
SearchingForPlaneUI: {fileID: 1133631540}
276276
prefab: {fileID: 1996245458792640, guid: 5b8b93680df36d24297bbcd2cf2395c0, type: 2}
277277
boost: {fileID: 198631920856243186, guid: ccafa74804815a642a1948ef0fa3123d, type: 2}
278+
goalExplosion: {fileID: 198519054809072828, guid: 0fcb78f446e38bb4fae0fa02a8221e15,
279+
type: 2}
278280
field: {fileID: 1622367642563872, guid: 6d6fcfec73dec3e478b7d834e44057d5, type: 2}
279281
ball: {fileID: 1696128692082718, guid: 33876e2cf22a5ef44b587d8584f418c5, type: 2}
280282
namePrefab: {fileID: 1093890370552692, guid: 92931170967238b4380ff3a2aecdffa1, type: 2}
281283
scaleFactor: 1000
282284
orangeCar: {fileID: 2100000, guid: 930ec488361a897478032696d5b19d8b, type: 2}
283285
blueCar: {fileID: 2100000, guid: ca59746023ec83d42a7d216a4d131eb3, type: 2}
284286
planeGenerator: {fileID: 2083512464}
287+
goalIndicator: {fileID: 0}
285288
testing: 0
286289
--- !u!20 &896679035 stripped
287290
Camera:

Assets/GoogleARCore/Examples/HelloAR/Scripts/HelloARController.cs

+66-21
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public class HelloARController : MonoBehaviour
8989
// Settable parameters
9090
public GameObject prefab;
9191
public ParticleSystem boost;
92+
public ParticleSystem goalExplosion;
9293
public GameObject field;
9394
public GameObject ball;
9495
public GameObject namePrefab;
@@ -102,6 +103,7 @@ public class HelloARController : MonoBehaviour
102103
private GameObject ballObject;
103104
private GameObject fieldObject;
104105
private GameObject rootObject;
106+
private ParticleSystem goalExplosionObject;
105107
private float currentTime = 0f;
106108
private int currentFrame = 0;
107109
private List<GameObject> cars = new List<GameObject>();
@@ -195,6 +197,13 @@ private void Spawn(Vector3 position, Quaternion rotation, Transform parent)
195197
ballObject.transform.parent = rootObject.transform;
196198
ballObject.transform.localPosition = new Vector3(0f, 0f, 0f);
197199
ballObject.transform.localScale = new Vector3(10 * 1000 / scaleFactor, 10 * 1000 / scaleFactor, 10 * 1000 / scaleFactor);
200+
201+
goalExplosionObject = Instantiate(goalExplosion, new Vector3(0f, 0f, 0f), Quaternion.identity);
202+
goalExplosionObject.transform.parent = rootObject.transform;
203+
goalExplosionObject.transform.localScale = new Vector3(4/scaleFactor, 4/scaleFactor, 4/scaleFactor);
204+
goalExplosionObject.Stop();
205+
206+
198207
currentTime = (float)gameData.frames[0][2];
199208
}
200209

@@ -289,7 +298,7 @@ public void Update()
289298
for (int i = 0; i < cars.Count; i++)
290299
{
291300
var frameData = gameData.players[i][currentFrame];
292-
float x = (float)(double)frameData[0] / localScale;
301+
float x = -(float)(double)frameData[0] / localScale;
293302
float y = (float)(double)frameData[2] / localScale;
294303
float z = (float)(double)frameData[1] / localScale;
295304

@@ -299,8 +308,8 @@ public void Update()
299308
var yOffset = (double)-0.25;
300309
var zOffset = (double)0;
301310
var xCoeff = (double)1;
302-
var yCoeff = (double)-1;
303-
var zCoeff = (double)-1;
311+
var yCoeff = (double)1;
312+
var zCoeff = (double)1;
304313

305314
var rotX = ((double)frameData[3] / (2 * PI) + xOffset) * xCoeff * 360; // pitch
306315
var rotY = ((double)frameData[4] / (2 * PI) + yOffset) * yCoeff * 360; // yaw
@@ -333,13 +342,26 @@ public void Update()
333342
names[i].transform.Rotate(Vector3.up - new Vector3(0, 180, 0));
334343
}
335344

336-
float ballx = (float)gameData.ball[currentFrame][0] / localScale;
345+
float ballx = -(float)gameData.ball[currentFrame][0] / localScale;
337346
float bally = (float)gameData.ball[currentFrame][2] / localScale;
338347
float ballz = (float)gameData.ball[currentFrame][1] / localScale;
339348
ballObject.transform.localPosition = new Vector3(ballx, bally, ballz);
340349

350+
// Goal Explosions
351+
352+
foreach (Goal g in StaticReplayScript.proto.gameMetadata.goals)
353+
{
354+
if (g.frameNumber == currentFrame)
355+
{
356+
goalExplosionObject.transform.localPosition = new Vector3(ballx, bally, ballz);
357+
goalExplosionObject.Play();
358+
}
359+
}
360+
361+
362+
341363
// Time management
342-
currentTime += Time.deltaTime;
364+
currentTime += Time.deltaTime;
343365

344366
var currentFrameTime = gameData.frames[currentFrame][2];
345367
var nextFrameTime = gameData.frames[currentFrame + 1][2];
@@ -364,38 +386,40 @@ public void OnGUI()
364386
{
365387
var width = Screen.width;
366388
var height = Screen.height;
367-
var zoomOut = GUI.Button(new Rect(width * 2 / 10, 25, width / 25, width / 25), "-");
368-
var zoomIn = GUI.Button(new Rect(width * 3 / 10, 25, width / 25, width / 25), "+");
369-
if (zoomOut)
370-
{
371-
scaleFactor += 100;
372-
rootObject.transform.localScale = new Vector3(1 / scaleFactor, 1 / scaleFactor, 1 / scaleFactor);
373-
}
374-
else if (zoomIn)
375-
{
376-
scaleFactor -= 100;
377-
rootObject.transform.localScale = new Vector3(1 / scaleFactor, 1 / scaleFactor, 1 / scaleFactor);
378-
}
389+
379390

380391

381392
// Scoreboard
382393
int offset = 100;
383394
Color orange = new Color(1F, 0.64F, 0F);
384395
var halfway = width / 2;
385396
GUIStyle timeStyle = new GUIStyle();
386-
timeStyle.fontSize = 30;
397+
timeStyle.fontSize = 40;
387398
timeStyle.fontStyle = FontStyle.Bold;
388399

389400
timeStyle.normal.textColor = Color.gray;
390401
timeStyle.alignment = TextAnchor.MiddleCenter;
402+
403+
404+
405+
391406
int timeRemaining = 300;
392407
if (StaticReplayScript.gameData != null)
393408
{
394409
timeRemaining = (int)StaticReplayScript.gameData.frames[currentFrame][1];
395410
}
396411
//int timeRemaining = 175;
397412
int minRemaining = timeRemaining / 60;
398-
GUI.Label(new Rect(halfway, 35, 50, 50), String.Format("{0}:{1:D2}", minRemaining, timeRemaining % (minRemaining * 60)), timeStyle);
413+
int secondsRemaining;
414+
if (minRemaining > 0)
415+
{
416+
secondsRemaining = timeRemaining%(minRemaining*60);
417+
}
418+
else
419+
{
420+
secondsRemaining = timeRemaining;
421+
}
422+
GUI.Label(new Rect(halfway, 35, 50, 50), String.Format("{0}:{1:D2}", minRemaining, secondsRemaining), timeStyle);
399423

400424

401425
var team0Score = 0;
@@ -429,7 +453,7 @@ public void OnGUI()
429453

430454
GUIStyle style = new GUIStyle();
431455
///style.font = new Font("Liberation Sans");
432-
style.fontSize = 30;
456+
style.fontSize = 40;
433457
style.fontStyle = FontStyle.Bold;
434458

435459
style.normal.textColor = Color.white;
@@ -447,6 +471,12 @@ public void OnGUI()
447471
Proto proto = StaticReplayScript.proto;
448472
if (gameData != null && proto != null && fieldObject != null)
449473
{
474+
// Slider Styling
475+
GUIStyle thumbStyle = new GUIStyle(GUI.skin.horizontalSliderThumb);
476+
GUIStyle sliderStyle = new GUIStyle(GUI.skin.horizontalSlider);
477+
sliderStyle.padding = new RectOffset(width / 10, width / 10, width / 10, width / 10);
478+
479+
450480
var logoWidth = width/60;
451481
var nextFrame = (int)GUI.HorizontalSlider(new Rect(0, 19 / 20f * height, width, height / 20f), currentFrame, 0, gameData.frames.Count);
452482
if (nextFrame != currentFrame)
@@ -473,14 +503,29 @@ public void OnGUI()
473503
}
474504
}
475505

506+
GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
476507

508+
buttonStyle.fontSize = 30;
477509
// Button
478-
var back = GUI.Button(new Rect(25, 25, width / 10, width / 25), "Back to Menu");
510+
var back = GUI.Button(new Rect(25, 25, width / 10, width / 25), "Back to Menu", buttonStyle);
479511
if (back)
480512
{
481513
SceneManager.LoadScene("Menu");
482514
}
483515

516+
var zoomOut = GUI.Button(new Rect(width * 2 / 10, 25, width / 25, width / 25), "-", buttonStyle);
517+
var zoomIn = GUI.Button(new Rect(width * 3 / 10, 25, width / 25, width / 25), "+", buttonStyle);
518+
if (zoomOut)
519+
{
520+
scaleFactor += 100;
521+
rootObject.transform.localScale = new Vector3(1 / scaleFactor, 1 / scaleFactor, 1 / scaleFactor);
522+
}
523+
else if (zoomIn)
524+
{
525+
scaleFactor -= 100;
526+
rootObject.transform.localScale = new Vector3(1 / scaleFactor, 1 / scaleFactor, 1 / scaleFactor);
527+
}
528+
484529

485530
if (dataMsg != null)
486531
{

Assets/LoadingScreen.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void OnGUI()
140140
style.fontSize = 40;
141141
if (StaticReplayScript.gameData == null || StaticReplayScript.proto == null)
142142
{
143-
GUI.Label(new Rect(0, height*18/20f, width/2f, height*2/20f),
143+
GUI.Label(new Rect(width * 1/4f, height*18/20f, width/2f, height*2/20f),
144144
"Point towards a surface and click on the white grid when it appears.", style);
145145
}
146146

0 commit comments

Comments
 (0)