GameUpdateManager.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. public class GameUpdateManager : MonoBehaviour
  5. {
  6. public static GameUpdateManager Instance;
  7. public TimeManager timeManager;
  8. public CondomDispenser condomDispenser;
  9. public FireInputController fireInputController;
  10. public ButtonSpermicidalWave buttonSpermicidalWave;
  11. public LevelFromDiskGameEntitySpawnManager levelFromDiskGameEntitySpawnManager;
  12. public bool _isPlaying;
  13. LevelProgressionManager _levelProgressionManager;
  14. GameEntitySpawnManager _gameEntitySpawnManager;
  15. LevelWithStageEffectsProgressionManager _levelWithStageEffectsProgressionManager;
  16. LevelWithStageEffectsGameEntitySpawnManager _levelWithStageEffectsGameEntitySpawnManager;
  17. LevelFromDiskProgressionManager _levelFromDiskProgressionManager;
  18. ScrollingManager _scrollingManager;
  19. void Awake()
  20. {
  21. Instance = this;
  22. NotificationCenter.AddListener(OnGameStart, NotificationType.GameStart);
  23. NotificationCenter.AddListener(OnEndLife, NotificationType.EndLife);
  24. NotificationCenter.AddListener(OnGetLife, NotificationType.GetLife);
  25. NotificationCenter.AddListener(OnGameOver, NotificationType.GameOver);
  26. NotificationCenter.AddListener(OnSelectLevelFromDisk, NotificationType.SelectLevelFromDisk);
  27. NotificationCenter.AddListener(OnSelectLevelWithStageEffects, NotificationType.SelectLevelWithStageEffects);
  28. _levelWithStageEffectsProgressionManager = GetComponent<LevelWithStageEffectsProgressionManager>();
  29. _levelWithStageEffectsGameEntitySpawnManager = GetComponent<LevelWithStageEffectsGameEntitySpawnManager>();
  30. _levelFromDiskProgressionManager = GetComponent<LevelFromDiskProgressionManager>();
  31. _scrollingManager = GetComponent<ScrollingManager>();
  32. }
  33. private void OnGetLife(Notification note)
  34. {
  35. /*if (!MenuManager._instance.mainMenuScreen.isActiveAndEnabled)
  36. {
  37. _isPlaying = true;
  38. }*/
  39. }
  40. private void OnEndLife(Notification note)
  41. {
  42. _isPlaying = false;
  43. }
  44. void OnDestroy()
  45. {
  46. NotificationCenter.RemoveListener(OnGameStart, NotificationType.GameStart);
  47. NotificationCenter.RemoveListener(OnGameOver, NotificationType.GameOver);
  48. NotificationCenter.RemoveListener(OnSelectLevelFromDisk, NotificationType.SelectLevelFromDisk);
  49. NotificationCenter.RemoveListener(OnSelectLevelWithStageEffects, NotificationType.SelectLevelWithStageEffects);
  50. NotificationCenter.RemoveListener(OnGetLife, NotificationType.GetLife);
  51. NotificationCenter.RemoveListener(OnEndLife, NotificationType.EndLife);
  52. }
  53. void OnGameStart(Notification note)
  54. {
  55. MenuManager._instance.IsGetLifeInGame = false;
  56. _isPlaying = true;
  57. }
  58. void OnGameOver(Notification note)
  59. {
  60. _isPlaying = false;
  61. }
  62. public void OnSelectLevelFromDisk(Notification note)
  63. {
  64. string levelName = (string)note.data;
  65. _levelWithStageEffectsProgressionManager.enabled = false;
  66. _levelWithStageEffectsGameEntitySpawnManager.enabled = false;
  67. _levelFromDiskProgressionManager.enabled = true;
  68. levelFromDiskGameEntitySpawnManager.enabled = true;
  69. levelFromDiskGameEntitySpawnManager.LoadFromDisk(levelName);
  70. _levelProgressionManager = _levelFromDiskProgressionManager;
  71. _gameEntitySpawnManager = levelFromDiskGameEntitySpawnManager;
  72. }
  73. public void OnSelectLevelFromDisk()
  74. {
  75. string levelName = "Level " + (LevelsManager.Instance.CurrentLevelIndex+1).ToString();
  76. _levelWithStageEffectsProgressionManager.enabled = false;
  77. _levelWithStageEffectsGameEntitySpawnManager.enabled = false;
  78. _levelFromDiskProgressionManager.enabled = true;
  79. levelFromDiskGameEntitySpawnManager.enabled = true;
  80. levelFromDiskGameEntitySpawnManager.LoadFromDisk(levelName);
  81. _levelProgressionManager = _levelFromDiskProgressionManager;
  82. _gameEntitySpawnManager = levelFromDiskGameEntitySpawnManager;
  83. }
  84. void OnSelectLevelWithStageEffects(Notification note)
  85. {
  86. Level level = (Level)note.data;
  87. _levelFromDiskProgressionManager.enabled = false;
  88. levelFromDiskGameEntitySpawnManager.enabled = false;
  89. _levelWithStageEffectsProgressionManager.enabled = true;
  90. _levelWithStageEffectsGameEntitySpawnManager.enabled = true;
  91. _levelWithStageEffectsProgressionManager.SelectLevel(level);
  92. _levelProgressionManager = _levelWithStageEffectsProgressionManager;
  93. _gameEntitySpawnManager = _levelWithStageEffectsGameEntitySpawnManager;
  94. }
  95. void FixedUpdate()
  96. {
  97. RecordingManager.Instance.CustomFixedUpdate();
  98. if (!_isPlaying)
  99. {
  100. return;
  101. }
  102. _scrollingManager.CustomFixedUpdate();
  103. fireInputController.CustomFixedUpdate();
  104. condomDispenser.CustomFixedUpdate();
  105. _levelProgressionManager.CustomFixedUpdate();
  106. timeManager.CustomFixedUpdate();
  107. _gameEntitySpawnManager.CustomFixedUpdate();
  108. //RecordingManager.Instance.CustomFixedUpdate();
  109. condomDispenser.UpdateCondoms();
  110. buttonSpermicidalWave.CustomFixedUpdate();
  111. foreach (Enemy enemy in _gameEntitySpawnManager.enemies)
  112. {
  113. Bounds enemyBounds = enemy.GetBounds();
  114. foreach (CondomBase condom in condomDispenser.condoms)
  115. {
  116. if (condom.CanCaptureEnemy(enemy))
  117. {
  118. Bounds condomBounds = condom.GetBounds();
  119. if (enemyBounds.Intersects(condomBounds))
  120. {
  121. enemy.OnCollisionWithCondom(condom);
  122. break; //stop checking for other condoms, this enemy has been capture... on to the next enemy
  123. }
  124. }
  125. }
  126. }
  127. foreach (Obstacle obstacle in _gameEntitySpawnManager.condomObstacles)
  128. {
  129. if(obstacle != null)
  130. {
  131. Bounds obstacleBounds = obstacle.GetBounds();
  132. foreach (CondomBase condom in condomDispenser.condoms)
  133. {
  134. if (!condom.HasCapturedAnEnemy())
  135. {
  136. Bounds condombBounds = condom.GetBounds();
  137. if (obstacleBounds.Intersects(condombBounds))
  138. {
  139. obstacle.SendMessage("OnCollisionWithCondomMsg", condom);
  140. }
  141. }
  142. }
  143. }
  144. }
  145. Bounds dispenserBounds = condomDispenser.GetBounds();
  146. foreach (Obstacle obstacle in _gameEntitySpawnManager.dispenserObstacles)
  147. {
  148. if(obstacle != null)
  149. {
  150. Bounds obstacleBounds = obstacle.GetBounds();
  151. if (obstacleBounds.Intersects(dispenserBounds))
  152. {
  153. obstacle.SendMessage("OnCollisionWithDispenserMsg");
  154. }
  155. }
  156. }
  157. }
  158. }