123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using UnityEngine;
- using System.Collections;
- using System;
- public class GameUpdateManager : MonoBehaviour
- {
- public static GameUpdateManager Instance;
- public TimeManager timeManager;
- public CondomDispenser condomDispenser;
- public FireInputController fireInputController;
- public ButtonSpermicidalWave buttonSpermicidalWave;
- public LevelFromDiskGameEntitySpawnManager levelFromDiskGameEntitySpawnManager;
- public bool _isPlaying;
- LevelProgressionManager _levelProgressionManager;
- GameEntitySpawnManager _gameEntitySpawnManager;
- LevelWithStageEffectsProgressionManager _levelWithStageEffectsProgressionManager;
- LevelWithStageEffectsGameEntitySpawnManager _levelWithStageEffectsGameEntitySpawnManager;
- LevelFromDiskProgressionManager _levelFromDiskProgressionManager;
- ScrollingManager _scrollingManager;
- void Awake()
- {
- Instance = this;
- NotificationCenter.AddListener(OnGameStart, NotificationType.GameStart);
- NotificationCenter.AddListener(OnEndLife, NotificationType.EndLife);
- NotificationCenter.AddListener(OnGetLife, NotificationType.GetLife);
- NotificationCenter.AddListener(OnGameOver, NotificationType.GameOver);
- NotificationCenter.AddListener(OnSelectLevelFromDisk, NotificationType.SelectLevelFromDisk);
- NotificationCenter.AddListener(OnSelectLevelWithStageEffects, NotificationType.SelectLevelWithStageEffects);
- _levelWithStageEffectsProgressionManager = GetComponent<LevelWithStageEffectsProgressionManager>();
- _levelWithStageEffectsGameEntitySpawnManager = GetComponent<LevelWithStageEffectsGameEntitySpawnManager>();
- _levelFromDiskProgressionManager = GetComponent<LevelFromDiskProgressionManager>();
- _scrollingManager = GetComponent<ScrollingManager>();
- }
- private void OnGetLife(Notification note)
- {
- /*if (!MenuManager._instance.mainMenuScreen.isActiveAndEnabled)
- {
- _isPlaying = true;
- }*/
-
- }
- private void OnEndLife(Notification note)
- {
- _isPlaying = false;
- }
- void OnDestroy()
- {
- NotificationCenter.RemoveListener(OnGameStart, NotificationType.GameStart);
- NotificationCenter.RemoveListener(OnGameOver, NotificationType.GameOver);
- NotificationCenter.RemoveListener(OnSelectLevelFromDisk, NotificationType.SelectLevelFromDisk);
- NotificationCenter.RemoveListener(OnSelectLevelWithStageEffects, NotificationType.SelectLevelWithStageEffects);
- NotificationCenter.RemoveListener(OnGetLife, NotificationType.GetLife);
- NotificationCenter.RemoveListener(OnEndLife, NotificationType.EndLife);
- }
- void OnGameStart(Notification note)
- {
- MenuManager._instance.IsGetLifeInGame = false;
- _isPlaying = true;
- }
- void OnGameOver(Notification note)
- {
- _isPlaying = false;
- }
- public void OnSelectLevelFromDisk(Notification note)
- {
- string levelName = (string)note.data;
- _levelWithStageEffectsProgressionManager.enabled = false;
- _levelWithStageEffectsGameEntitySpawnManager.enabled = false;
- _levelFromDiskProgressionManager.enabled = true;
- levelFromDiskGameEntitySpawnManager.enabled = true;
- levelFromDiskGameEntitySpawnManager.LoadFromDisk(levelName);
- _levelProgressionManager = _levelFromDiskProgressionManager;
- _gameEntitySpawnManager = levelFromDiskGameEntitySpawnManager;
- }
- public void OnSelectLevelFromDisk()
- {
- string levelName = "Level " + (LevelsManager.Instance.CurrentLevelIndex+1).ToString();
- _levelWithStageEffectsProgressionManager.enabled = false;
- _levelWithStageEffectsGameEntitySpawnManager.enabled = false;
- _levelFromDiskProgressionManager.enabled = true;
- levelFromDiskGameEntitySpawnManager.enabled = true;
- levelFromDiskGameEntitySpawnManager.LoadFromDisk(levelName);
- _levelProgressionManager = _levelFromDiskProgressionManager;
- _gameEntitySpawnManager = levelFromDiskGameEntitySpawnManager;
- }
- void OnSelectLevelWithStageEffects(Notification note)
- {
- Level level = (Level)note.data;
- _levelFromDiskProgressionManager.enabled = false;
- levelFromDiskGameEntitySpawnManager.enabled = false;
- _levelWithStageEffectsProgressionManager.enabled = true;
- _levelWithStageEffectsGameEntitySpawnManager.enabled = true;
- _levelWithStageEffectsProgressionManager.SelectLevel(level);
- _levelProgressionManager = _levelWithStageEffectsProgressionManager;
- _gameEntitySpawnManager = _levelWithStageEffectsGameEntitySpawnManager;
- }
- void FixedUpdate()
- {
- RecordingManager.Instance.CustomFixedUpdate();
- if (!_isPlaying)
- {
- return;
- }
- _scrollingManager.CustomFixedUpdate();
- fireInputController.CustomFixedUpdate();
- condomDispenser.CustomFixedUpdate();
- _levelProgressionManager.CustomFixedUpdate();
- timeManager.CustomFixedUpdate();
- _gameEntitySpawnManager.CustomFixedUpdate();
- //RecordingManager.Instance.CustomFixedUpdate();
- condomDispenser.UpdateCondoms();
- buttonSpermicidalWave.CustomFixedUpdate();
- foreach (Enemy enemy in _gameEntitySpawnManager.enemies)
- {
- Bounds enemyBounds = enemy.GetBounds();
- foreach (CondomBase condom in condomDispenser.condoms)
- {
- if (condom.CanCaptureEnemy(enemy))
- {
- Bounds condomBounds = condom.GetBounds();
- if (enemyBounds.Intersects(condomBounds))
- {
- enemy.OnCollisionWithCondom(condom);
- break; //stop checking for other condoms, this enemy has been capture... on to the next enemy
- }
- }
- }
- }
- foreach (Obstacle obstacle in _gameEntitySpawnManager.condomObstacles)
- {
- if(obstacle != null)
- {
- Bounds obstacleBounds = obstacle.GetBounds();
- foreach (CondomBase condom in condomDispenser.condoms)
- {
- if (!condom.HasCapturedAnEnemy())
- {
- Bounds condombBounds = condom.GetBounds();
- if (obstacleBounds.Intersects(condombBounds))
- {
- obstacle.SendMessage("OnCollisionWithCondomMsg", condom);
- }
- }
- }
- }
-
- }
- Bounds dispenserBounds = condomDispenser.GetBounds();
- foreach (Obstacle obstacle in _gameEntitySpawnManager.dispenserObstacles)
- {
- if(obstacle != null)
- {
- Bounds obstacleBounds = obstacle.GetBounds();
- if (obstacleBounds.Intersects(dispenserBounds))
- {
- obstacle.SendMessage("OnCollisionWithDispenserMsg");
- }
- }
-
- }
- }
- }
|