ChallengesManager.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. using System.Collections;
  3. public class ChallengesManager : MonoBehaviour
  4. {
  5. public Level challengeLevel;
  6. ChallengeRequestUIData _currentChallenge;
  7. public ChallengeRequestUIData CurrentChallenge { get { return _currentChallenge; } }
  8. void Awake()
  9. {
  10. NotificationCenter.AddListener(OnAcceptChallenge, NotificationType.AcceptChallenge);
  11. NotificationCenter.AddListener(OnShowingScoresAfterGameOver, NotificationType.ShowingScoresAfterGameOver);
  12. NotificationCenter.AddListener(OnExitToMainMenu, NotificationType.MenuTransition);
  13. }
  14. void OnDestroy()
  15. {
  16. NotificationCenter.RemoveListener(OnAcceptChallenge, NotificationType.AcceptChallenge);
  17. NotificationCenter.RemoveListener(OnShowingScoresAfterGameOver, NotificationType.ShowingScoresAfterGameOver);
  18. NotificationCenter.RemoveListener(OnExitToMainMenu, NotificationType.MenuTransition);
  19. }
  20. void OnAcceptChallenge(Notification note)
  21. {
  22. AVDebug.Assert(_currentChallenge == null, "The previous challenge wasn't reset");
  23. _currentChallenge = (ChallengeRequestUIData)note.data;
  24. NotificationCenter.Post(NotificationType.SelectNextLevel, _currentChallenge.levelId);
  25. }
  26. void OnShowingScoresAfterGameOver(Notification note)
  27. {
  28. if (_currentChallenge != null)
  29. {
  30. FacebookHelper.Instance.SubmitChallengeScore(_currentChallenge.challengeId);
  31. NotificationCenter.Post(NotificationType.ShowWhoWonChallenge, _currentChallenge);
  32. _currentChallenge = null;
  33. }
  34. }
  35. void OnExitToMainMenu(Notification note)
  36. {
  37. MenuManager.MenuTransition t = (MenuManager.MenuTransition)note.data;
  38. if (t == MenuManager.MenuTransition.ExitToMainMenu)
  39. {
  40. //reset challenge
  41. _currentChallenge = null;
  42. }
  43. }
  44. }