12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using UnityEngine;
- using System.Collections;
- public class ChallengesManager : MonoBehaviour
- {
- public Level challengeLevel;
- ChallengeRequestUIData _currentChallenge;
- public ChallengeRequestUIData CurrentChallenge { get { return _currentChallenge; } }
- void Awake()
- {
- NotificationCenter.AddListener(OnAcceptChallenge, NotificationType.AcceptChallenge);
- NotificationCenter.AddListener(OnShowingScoresAfterGameOver, NotificationType.ShowingScoresAfterGameOver);
- NotificationCenter.AddListener(OnExitToMainMenu, NotificationType.MenuTransition);
- }
- void OnDestroy()
- {
- NotificationCenter.RemoveListener(OnAcceptChallenge, NotificationType.AcceptChallenge);
- NotificationCenter.RemoveListener(OnShowingScoresAfterGameOver, NotificationType.ShowingScoresAfterGameOver);
- NotificationCenter.RemoveListener(OnExitToMainMenu, NotificationType.MenuTransition);
- }
- void OnAcceptChallenge(Notification note)
- {
- AVDebug.Assert(_currentChallenge == null, "The previous challenge wasn't reset");
- _currentChallenge = (ChallengeRequestUIData)note.data;
- NotificationCenter.Post(NotificationType.SelectNextLevel, _currentChallenge.levelId);
- }
- void OnShowingScoresAfterGameOver(Notification note)
- {
- if (_currentChallenge != null)
- {
- FacebookHelper.Instance.SubmitChallengeScore(_currentChallenge.challengeId);
- NotificationCenter.Post(NotificationType.ShowWhoWonChallenge, _currentChallenge);
- _currentChallenge = null;
- }
- }
- void OnExitToMainMenu(Notification note)
- {
- MenuManager.MenuTransition t = (MenuManager.MenuTransition)note.data;
- if (t == MenuManager.MenuTransition.ExitToMainMenu)
- {
- //reset challenge
- _currentChallenge = null;
- }
- }
- }
|