forked from Angus-Fan/TurnBasedStrategyGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameManagerScript.cs
794 lines (678 loc) · 32.3 KB
/
gameManagerScript.cs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class gameManagerScript : MonoBehaviour
{
//A lot of the UI does not need to be public, they just are currently if you need to make quick changes in the inspector
//Changing them to private will not break anything, but you will need to re-enable them to show in the inspector
[Header("UI GameObjects")]
public TMP_Text currentTeamUI;
public Canvas displayWinnerUI;
public TMP_Text UIunitCurrentHealth;
public TMP_Text UIunitAttackDamage;
public TMP_Text UIunitAttackRange;
public TMP_Text UIunitMoveSpeed;
public TMP_Text UIunitName;
public UnityEngine.UI.Image UIunitSprite;
public Canvas UIunitCanvas;
public GameObject playerPhaseBlock;
private Animator playerPhaseAnim;
private TMP_Text playerPhaseText;
//Raycast for the update for unitHover info
private Ray ray;
private RaycastHit hit;
/// The number of teams is hard coded as 2, if there are changes in the future a few of the
/// functions in this class need to be altered as well to update this change.
public int numberOfTeams = 2;
public int currentTeam;
public GameObject unitsOnBoard;
public GameObject team1;
public GameObject team2;
public GameObject unitBeingDisplayed;
public GameObject tileBeingDisplayed;
public bool displayingUnitInfo;
public tileMapScript TMS;
//Cursor Info for tileMapScript
public int cursorX;
public int cursorY;
//currentTileBeingMousedOver
public int selectedXTile;
public int selectedYTile;
//Variables for unitPotentialMovementRoute
List<Node> currentPathForUnitRoute;
List<Node> unitPathToCursor;
public bool unitPathExists;
public Material UIunitRoute;
public Material UIunitRouteCurve;
public Material UIunitRouteArrow;
public Material UICursor;
public int routeToX;
public int routeToY;
//This game object is to record the location of the 2 count path when it is reset to 0 this is used to remember what tile to disable
public GameObject quadThatIsOneAwayFromUnit;
public void Start()
{
currentTeam = 0;
setCurrentTeamUI();
teamHealthbarColorUpdate();
displayingUnitInfo = false;
playerPhaseAnim = playerPhaseBlock.GetComponent<Animator>();
playerPhaseText = playerPhaseBlock.GetComponentInChildren<TextMeshProUGUI>();
unitPathToCursor = new List<Node>();
unitPathExists = false;
TMS = GetComponent<tileMapScript>();
}
//2019/10/17 there is a small blink between disable and re-enable for path, its a bit jarring, try to fix it later
public void Update()
{
//Always trying to see where the mouse is pointing
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
//Update cursorLocation and unit appearing in the topLeft
cursorUIUpdate();
unitUIUpdate();
//If the unit is selected we want to highlight the current path with the UI
if (TMS.selectedUnit != null && TMS.selectedUnit.GetComponent<UnitScript>().getMovementStateEnum(1) == TMS.selectedUnit.GetComponent<UnitScript>().unitMoveState)
{
//Check to see if the cursor is in range, we cant show movement outside of range so there is no point if its outside
if (TMS.selectedUnitMoveRange.Contains(TMS.graph[cursorX, cursorY]))
{
//Generate new path to cursor try to limit this to once per new cursor location or else its too many calculations
if (cursorX != TMS.selectedUnit.GetComponent<UnitScript>().x || cursorY != TMS.selectedUnit.GetComponent<UnitScript>().y)
{
if (!unitPathExists&&TMS.selectedUnit.GetComponent<UnitScript>().movementQueue.Count==0)
{
unitPathToCursor = generateCursorRouteTo(cursorX, cursorY);
routeToX = cursorX;
routeToY = cursorY;
if (unitPathToCursor.Count != 0)
{
for(int i = 0; i < unitPathToCursor.Count; i++)
{
int nodeX = unitPathToCursor[i].x;
int nodeY = unitPathToCursor[i].y;
if (i == 0)
{
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Renderer>().material = UICursor;
}
else if (i!=0 && (i+1)!=unitPathToCursor.Count)
{
//This is used to set the indicator for tiles excluding the first/last tile
setCorrectRouteWithInputAndOutput(nodeX, nodeY,i);
}
else if (i == unitPathToCursor.Count-1)
{
//This is used to set the indicator for the final tile;
setCorrectRouteFinalTile(nodeX, nodeY, i);
}
TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY].GetComponent<Renderer>().enabled = true;
}
}
unitPathExists = true;
}
else if (routeToX != cursorX || routeToY != cursorY)
{
if (unitPathToCursor.Count != 0)
{
for (int i = 0; i < unitPathToCursor.Count; i++)
{
int nodeX = unitPathToCursor[i].x;
int nodeY = unitPathToCursor[i].y;
TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY].GetComponent<Renderer>().enabled = false;
}
}
unitPathExists = false;
}
}
else if(cursorX == TMS.selectedUnit.GetComponent<UnitScript>().x && cursorY == TMS.selectedUnit.GetComponent<UnitScript>().y)
{
TMS.disableUnitUIRoute();
unitPathExists = false;
}
}
}
}
}
//In:
//Out: void
//Desc: sets the current player Text in the UI
public void setCurrentTeamUI()
{
currentTeamUI.SetText("Current Player is : Player " + (currentTeam+1).ToString());
}
//In:
//Out: void
//Desc: increments the current team
public void switchCurrentPlayer()
{
resetUnitsMovements(returnTeam(currentTeam));
currentTeam++;
if (currentTeam == numberOfTeams)
{
currentTeam = 0;
}
}
//In: int i, the index for each team
//Out: gameObject team
//Desc: return the gameObject of the requested team
public GameObject returnTeam(int i)
{
GameObject teamToReturn = null;
if (i == 0)
{
teamToReturn = team1;
}
else if (i == 1)
{
teamToReturn = team2;
}
return teamToReturn;
}
//In: gameObject team - used to reset (re-enable) all the unit movements
//Out: void
//Desc: re-enables movement for all units on the team
public void resetUnitsMovements(GameObject teamToReset)
{
foreach (Transform unit in teamToReset.transform)
{
unit.GetComponent<UnitScript>().moveAgain();
}
}
//In:
//Out: void
//Desc: ends the turn and plays the animation
public void endTurn()
{
if (TMS.selectedUnit == null)
{
switchCurrentPlayer();
if (currentTeam == 1)
{
playerPhaseAnim.SetTrigger("slideLeftTrigger");
playerPhaseText.SetText("Player 2 Phase");
}
else if (currentTeam == 0)
{
playerPhaseAnim.SetTrigger("slideRightTrigger");
playerPhaseText.SetText("Player 1 Phase");
}
teamHealthbarColorUpdate();
setCurrentTeamUI();
}
}
//In: attacking unit and receiving unit
//Out: void
//Desc: checks to see if units remain on a team
public void checkIfUnitsRemain(GameObject unit, GameObject enemy)
{
// Debug.Log(team1.transform.childCount);
// Debug.Log(team2.transform.childCount);
StartCoroutine(checkIfUnitsRemainCoroutine(unit,enemy));
}
//In:
//Out: void
//Desc: updates the cursor for the UI
public void cursorUIUpdate()
{
//If we are mousing over a tile, highlight it
if (hit.transform.CompareTag("Tile"))
{
if (tileBeingDisplayed == null)
{
selectedXTile = hit.transform.gameObject.GetComponent<ClickableTileScript>().tileX;
selectedYTile = hit.transform.gameObject.GetComponent<ClickableTileScript>().tileY;
cursorX = selectedXTile;
cursorY = selectedYTile;
TMS.quadOnMapCursor[selectedXTile, selectedYTile].GetComponent<MeshRenderer>().enabled = true;
tileBeingDisplayed = hit.transform.gameObject;
}
else if (tileBeingDisplayed != hit.transform.gameObject)
{
selectedXTile = tileBeingDisplayed.GetComponent<ClickableTileScript>().tileX;
selectedYTile = tileBeingDisplayed.GetComponent<ClickableTileScript>().tileY;
TMS.quadOnMapCursor[selectedXTile, selectedYTile].GetComponent<MeshRenderer>().enabled = false;
selectedXTile = hit.transform.gameObject.GetComponent<ClickableTileScript>().tileX;
selectedYTile = hit.transform.gameObject.GetComponent<ClickableTileScript>().tileY;
cursorX = selectedXTile;
cursorY = selectedYTile;
TMS.quadOnMapCursor[selectedXTile, selectedYTile].GetComponent<MeshRenderer>().enabled = true;
tileBeingDisplayed = hit.transform.gameObject;
}
}
//If we are mousing over a unit, highlight the tile that the unit is occupying
else if (hit.transform.CompareTag("Unit"))
{
if (tileBeingDisplayed == null)
{
selectedXTile = hit.transform.parent.gameObject.GetComponent<UnitScript>().x;
selectedYTile = hit.transform.parent.gameObject.GetComponent<UnitScript>().y;
cursorX = selectedXTile;
cursorY = selectedYTile;
TMS.quadOnMapCursor[selectedXTile, selectedYTile].GetComponent<MeshRenderer>().enabled = true;
tileBeingDisplayed = hit.transform.parent.gameObject.GetComponent<UnitScript>().tileBeingOccupied;
}
else if (tileBeingDisplayed != hit.transform.gameObject)
{
if (hit.transform.parent.gameObject.GetComponent<UnitScript>().movementQueue.Count == 0)
{
selectedXTile = tileBeingDisplayed.GetComponent<ClickableTileScript>().tileX;
selectedYTile = tileBeingDisplayed.GetComponent<ClickableTileScript>().tileY;
TMS.quadOnMapCursor[selectedXTile, selectedYTile].GetComponent<MeshRenderer>().enabled = false;
selectedXTile = hit.transform.parent.gameObject.GetComponent<UnitScript>().x;
selectedYTile = hit.transform.parent.gameObject.GetComponent<UnitScript>().y;
cursorX = selectedXTile;
cursorY = selectedYTile;
TMS.quadOnMapCursor[selectedXTile, selectedYTile].GetComponent<MeshRenderer>().enabled = true;
tileBeingDisplayed = hit.transform.parent.GetComponent<UnitScript>().tileBeingOccupied;
}
}
}
//We aren't pointing at anything no cursor.
else
{
TMS.quadOnMapCursor[selectedXTile, selectedYTile].GetComponent<MeshRenderer>().enabled = false;
}
}
//In:
//Out: void
//Desc: the unit that is being highlighted will have its stats in the UI
public void unitUIUpdate()
{
if (!displayingUnitInfo)
{
if (hit.transform.CompareTag("Unit"))
{
UIunitCanvas.enabled = true;
displayingUnitInfo = true;
unitBeingDisplayed = hit.transform.parent.gameObject;
var highlightedUnitScript = hit.transform.parent.gameObject.GetComponent<UnitScript>();
UIunitCurrentHealth.SetText(highlightedUnitScript.currentHealthPoints.ToString());
UIunitAttackDamage.SetText(highlightedUnitScript.attackDamage.ToString());
UIunitAttackRange.SetText(highlightedUnitScript.attackRange.ToString());
UIunitMoveSpeed.SetText(highlightedUnitScript.moveSpeed.ToString());
UIunitName.SetText(highlightedUnitScript.unitName);
UIunitSprite.sprite = highlightedUnitScript.unitSprite;
}
else if (hit.transform.CompareTag("Tile"))
{
if (hit.transform.GetComponent<ClickableTileScript>().unitOnTile != null)
{
unitBeingDisplayed = hit.transform.GetComponent<ClickableTileScript>().unitOnTile;
UIunitCanvas.enabled = true;
displayingUnitInfo = true;
var highlightedUnitScript = unitBeingDisplayed.GetComponent<UnitScript>();
UIunitCurrentHealth.SetText(highlightedUnitScript.currentHealthPoints.ToString());
UIunitAttackDamage.SetText(highlightedUnitScript.attackDamage.ToString());
UIunitAttackRange.SetText(highlightedUnitScript.attackRange.ToString());
UIunitMoveSpeed.SetText(highlightedUnitScript.moveSpeed.ToString());
UIunitName.SetText(highlightedUnitScript.unitName);
UIunitSprite.sprite = highlightedUnitScript.unitSprite;
}
}
}
else if (hit.transform.gameObject.CompareTag("Tile"))
{
if (hit.transform.GetComponent<ClickableTileScript>().unitOnTile == null)
{
UIunitCanvas.enabled = false;
displayingUnitInfo = false;
}
else if (hit.transform.GetComponent<ClickableTileScript>().unitOnTile != unitBeingDisplayed)
{
UIunitCanvas.enabled = false;
displayingUnitInfo = false;
}
}
else if (hit.transform.gameObject.CompareTag("Unit"))
{
if (hit.transform.parent.gameObject != unitBeingDisplayed)
{
UIunitCanvas.enabled = false;
displayingUnitInfo = false;
}
}
}
//In:
//Out: void
//Desc: When the current team is active, the healthbars are blue, and the other team is red
public void teamHealthbarColorUpdate()
{
for(int i = 0; i < numberOfTeams; i++)
{
GameObject team = returnTeam(i);
if(team == returnTeam(currentTeam))
{
foreach (Transform unit in team.transform)
{
unit.GetComponent<UnitScript>().changeHealthBarColour(0);
}
}
else
{
foreach (Transform unit in team.transform)
{
unit.GetComponent<UnitScript>().changeHealthBarColour(1);
}
}
}
}
//In: x and y location to go to
//Out: list of nodes to traverse
//Desc: generate the cursor route to a position x , y
public List<Node> generateCursorRouteTo(int x, int y)
{
if (TMS.selectedUnit.GetComponent<UnitScript>().x == x && TMS.selectedUnit.GetComponent<UnitScript>().y == y)
{
Debug.Log("clicked the same tile that the unit is standing on");
currentPathForUnitRoute = new List<Node>();
return currentPathForUnitRoute;
}
if (TMS.unitCanEnterTile(x, y) == false)
{
//cant move into something so we can probably just return
//cant set this endpoint as our goal
return null;
}
//TMS.selectedUnit.GetComponent<UnitScript>().path = null;
currentPathForUnitRoute = null;
//from wiki dijkstra's
Dictionary<Node, float> dist = new Dictionary<Node, float>();
Dictionary<Node, Node> prev = new Dictionary<Node, Node>();
Node source = TMS.graph[TMS.selectedUnit.GetComponent<UnitScript>().x, TMS.selectedUnit.GetComponent<UnitScript>().y];
Node target = TMS.graph[x, y];
dist[source] = 0;
prev[source] = null;
//Unchecked nodes
List<Node> unvisited = new List<Node>();
//Initialize
foreach (Node n in TMS.graph)
{
//Initialize to infite distance as we don't know the answer
//Also some places are infinity
if (n != source)
{
dist[n] = Mathf.Infinity;
prev[n] = null;
}
unvisited.Add(n);
}
//if there is a node in the unvisited list lets check it
while (unvisited.Count > 0)
{
//u will be the unvisited node with the shortest distance
Node u = null;
foreach (Node possibleU in unvisited)
{
if (u == null || dist[possibleU] < dist[u])
{
u = possibleU;
}
}
if (u == target)
{
break;
}
unvisited.Remove(u);
foreach (Node n in u.neighbours)
{
//float alt = dist[u] + u.DistanceTo(n);
float alt = dist[u] + TMS.costToEnterTile(n.x, n.y);
if (alt < dist[n])
{
dist[n] = alt;
prev[n] = u;
}
}
}
//if were here we found shortest path, or no path exists
if (prev[target] == null)
{
//No route;
return null;
}
currentPathForUnitRoute = new List<Node>();
Node curr = target;
//Step through the current path and add it to the chain
while (curr != null)
{
currentPathForUnitRoute.Add(curr);
curr = prev[curr];
}
//Now currPath is from target to our source, we need to reverse it from source to target.
currentPathForUnitRoute.Reverse();
return currentPathForUnitRoute;
}
//In: gameObject quad
//Out: void
//Desc: reset its rotation
public void resetQuad(GameObject quadToReset)
{
quadToReset.GetComponent<Renderer>().material = UICursor;
quadToReset.transform.eulerAngles = new Vector3(90, 0, 0);
}
//In: Vector2 cursorPos the location we change, Vector3 the rotation that we will rotate the quad
//Out: void
//Desc: the quad is rotated approriately
public void UIunitRouteArrowDisplay(Vector2 cursorPos,Vector3 arrowRotationVector)
{
GameObject quadToManipulate = TMS.quadOnMapForUnitMovementDisplay[(int)cursorPos.x, (int)cursorPos.y];
quadToManipulate.transform.eulerAngles = arrowRotationVector;
quadToManipulate.GetComponent<Renderer>().material = UIunitRouteArrow;
quadToManipulate.GetComponent<Renderer>().enabled = true;
}
//In: two gameObjects current vector and the next one in the list
//Out: vector which is the direction between the two inputs
//Desc: the direction from current to the next vector is returned
public Vector2 directionBetween(Vector2 currentVector, Vector2 nextVector)
{
Vector2 vectorDirection = (nextVector - currentVector).normalized;
if (vectorDirection == Vector2.right)
{
return Vector2.right;
}
else if (vectorDirection == Vector2.left)
{
return Vector2.left;
}
else if (vectorDirection == Vector2.up)
{
return Vector2.up;
}
else if (vectorDirection == Vector2.down)
{
return Vector2.down;
}
else
{
Vector2 vectorToReturn = new Vector2();
return vectorToReturn;
}
}
//In: two nodes that are being checked and int i is the position in the path ie i=0 is the first thing in the list
//Out: void
//Desc: orients the quads to display proper information
public void setCorrectRouteWithInputAndOutput(int nodeX,int nodeY,int i)
{
Vector2 previousTile = new Vector2(unitPathToCursor[i - 1].x + 1, unitPathToCursor[i - 1].y + 1);
Vector2 currentTile = new Vector2(unitPathToCursor[i].x + 1, unitPathToCursor[i].y + 1);
Vector2 nextTile = new Vector2(unitPathToCursor[i + 1].x + 1, unitPathToCursor[i + 1].y + 1);
Vector2 backToCurrentVector = directionBetween(previousTile, currentTile);
Vector2 currentToFrontVector = directionBetween(currentTile, nextTile);
//Right (UP/DOWN/RIGHT)
if (backToCurrentVector == Vector2.right && currentToFrontVector == Vector2.right)
{
//Debug.Log("[IN[R]]->[Out[R]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 270);
quadToUpdate.GetComponent<Renderer>().material = UIunitRoute;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.right && currentToFrontVector == Vector2.up)
{
//Debug.Log("[IN[R]]->[Out[UP]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 180);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteCurve;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.right && currentToFrontVector == Vector2.down)
{
//Debug.Log("[IN[R]]->[Out[DOWN]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 270);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteCurve;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
//Left (UP/DOWN/LEFT)
else if (backToCurrentVector == Vector2.left && currentToFrontVector == Vector2.left)
{
//Debug.Log("[IN[L]]->[Out[L]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 90);
quadToUpdate.GetComponent<Renderer>().material = UIunitRoute;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.left && currentToFrontVector == Vector2.up)
{
//Debug.Log("[IN[L]]->[Out[UP]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 90);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteCurve;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.left && currentToFrontVector == Vector2.down)
{
//Debug.Log("[IN[L]]->[Out[DOWN]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 0);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteCurve;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
//UP (UP/RIGHT/LEFT)
else if (backToCurrentVector == Vector2.up && currentToFrontVector == Vector2.up)
{
//Debug.Log("[IN[UP]]->[Out[UP]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 0);
quadToUpdate.GetComponent<Renderer>().material = UIunitRoute;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.up && currentToFrontVector == Vector2.right)
{
//Debug.Log("[IN[UP]]->[Out[R]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 0);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteCurve;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.up && currentToFrontVector == Vector2.left)
{
//Debug.Log("[IN[UP]]->[Out[L]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 270);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteCurve;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
//DOWN (DOWN/RIGHT/LEFT)
else if (backToCurrentVector == Vector2.down && currentToFrontVector == Vector2.down)
{
//Debug.Log("[IN[DOWN]]->[Out[DOWN]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 0);
quadToUpdate.GetComponent<Renderer>().material = UIunitRoute;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.down && currentToFrontVector == Vector2.right)
{
//Debug.Log("[IN[DOWN]]->[Out[R]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 90);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteCurve;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.down && currentToFrontVector == Vector2.left)
{
//Debug.Log("[IN[DOWN]]->[Out[L]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 180);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteCurve;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
}
//In: two nodes that are being checked and int i is the position in the path ie i=0 is the first thing in the list
//Out: void
//Desc: orients the quad for the final node in list to display proper information
public void setCorrectRouteFinalTile(int nodeX,int nodeY,int i)
{
Vector2 previousTile = new Vector2(unitPathToCursor[i - 1].x + 1, unitPathToCursor[i - 1].y + 1);
Vector2 currentTile = new Vector2(unitPathToCursor[i].x + 1, unitPathToCursor[i].y + 1);
Vector2 backToCurrentVector = directionBetween(previousTile, currentTile);
if (backToCurrentVector == Vector2.right)
{
//Debug.Log("[IN[R]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 270);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteArrow;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.left)
{
//Debug.Log("[IN[L]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 90);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteArrow;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.up)
{
//Debug.Log("[IN[U]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 0);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteArrow;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
else if (backToCurrentVector == Vector2.down)
{
//Debug.Log("[IN[D]]");
GameObject quadToUpdate = TMS.quadOnMapForUnitMovementDisplay[nodeX, nodeY];
quadToUpdate.GetComponent<Transform>().rotation = Quaternion.Euler(90, 0, 180);
quadToUpdate.GetComponent<Renderer>().material = UIunitRouteArrow;
quadToUpdate.GetComponent<Renderer>().enabled = true;
}
}
//In: two units that last fought
//Out: void
//Desc: waits until all the animations and stuff are finished before calling the game
public IEnumerator checkIfUnitsRemainCoroutine(GameObject unit, GameObject enemy)
{
while (unit.GetComponent<UnitScript>().combatQueue.Count != 0)
{
yield return new WaitForEndOfFrame();
}
while (enemy.GetComponent<UnitScript>().combatQueue.Count != 0)
{
yield return new WaitForEndOfFrame();
}
if (team1.transform.childCount == 0)
{
displayWinnerUI.enabled = true;
displayWinnerUI.GetComponentInChildren<TextMeshProUGUI>().SetText("Player 2 has won!");
}
else if (team2.transform.childCount == 0)
{
displayWinnerUI.enabled = true;
displayWinnerUI.GetComponentInChildren<TextMeshProUGUI>().SetText("Player 1 has won!");
}
}
//In:
//Out: void
//Desc: set the player winning
public void win()
{
displayWinnerUI.enabled = true;
displayWinnerUI.GetComponentInChildren<TextMeshProUGUI>().SetText("Winner!");
}
}