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(); _levelWithStageEffectsGameEntitySpawnManager = GetComponent(); _levelFromDiskProgressionManager = GetComponent(); _scrollingManager = GetComponent(); } 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"); } } } } }