Пример #1
0
        void Awake()
        {
            if (_instance != null && _instance != this)
            {
                Destroy(gameObject);
                return;
            }
            _instance = this;
            CardGame.Invalid.CoroutineRunner = this;
            DontDestroyOnLoad(gameObject);

            if (!Directory.Exists(CardGame.GamesDirectoryPath))
            {
                CreateDefaultCardGames();
            }
            LookupCardGames();

            CardGame currentGame;

            Current = AllCardGames.TryGetValue(PlayerPrefs.GetString(PlayerPrefGameName), out currentGame)
                 ? currentGame : AllCardGames.First().Value;

            if (Debug.isDebugBuild)
            {
                Application.logMessageReceived += ShowLogToUser;
            }
            SceneManager.sceneLoaded   += OnSceneLoaded;
            SceneManager.sceneUnloaded += OnSceneUnloaded;
        }
        // Note: Does NOT Reset Game Scene
        public void ResetCurrentToDefault()
        {
            string preferredGameId = PlayerPrefs.GetString(PlayerPrefDefaultGame);

            Current = AllCardGames.TryGetValue(preferredGameId, out CardGame currentGame) && string.IsNullOrEmpty(currentGame.Error)
                ? currentGame : (AllCardGames.FirstOrDefault().Value ?? CardGame.Invalid);
        }
Пример #3
0
 public void SelectCardGame(string gameName, string gameUrl)
 {
     if (string.IsNullOrEmpty(gameName) || !AllCardGames.ContainsKey(gameName))
     {
         StartCoroutine(DownloadCardGame(gameUrl));
         return;
     }
     SelectCardGame(gameName);
 }
        // Note: Does NOT Reset Game Scene
        private void ResetCurrentToDefault()
        {
            string preferredGameId =
                PlayerPrefs.GetString(PlayerPrefDefaultGame, Tags.StandardPlayingCardsDirectoryName);

            Current = AllCardGames.TryGetValue(preferredGameId, out UnityCardGame currentGame) &&
                      string.IsNullOrEmpty(currentGame.Error)
                ? currentGame
                : (AllCardGames.FirstOrDefault().Value ?? UnityCardGame.UnityInvalid);
        }
Пример #5
0
        public void SelectCardGame(string gameName)
        {
            if (string.IsNullOrEmpty(gameName) || !AllCardGames.ContainsKey(gameName))
            {
                Debug.LogError(InvalidGameSelectionMessage);
                Selector.Show();
                return;
            }

            Current = AllCardGames[gameName];
            DoGameSceneActions();
        }
        public void Select(string gameId)
        {
            if (string.IsNullOrEmpty(gameId) || !AllCardGames.ContainsKey(gameId))
            {
                Debug.LogError(SelectionErrorMessage);
                Messenger.Show(SelectionErrorMessage);
                return;
            }

            Current = AllCardGames[gameId];
            ResetGameScene();
        }
Пример #7
0
 public void DeleteGame()
 {
     try
     {
         Directory.Delete(Current.GameFolderPath, true);
         AllCardGames.Remove(Current.Name);
         SelectCardGame(AllCardGames.Keys.First());
         Selector.Show();
     }
     catch (Exception ex)
     {
         Debug.LogError(GameDeleteErrorMessage + ex.Message);
     }
 }
Пример #8
0
        public void SelectLeft()
        {
            string prevGameName = AllCardGames.Keys.Last();

            SortedDictionary <string, CardGame> .Enumerator allCardGamesEnum = AllCardGames.GetEnumerator();
            bool found = false;

            while (!found && allCardGamesEnum.MoveNext())
            {
                if (!allCardGamesEnum.Current.Key.Equals(Current.Name))
                {
                    prevGameName = allCardGamesEnum.Current.Key;
                }
                else
                {
                    found = true;
                }
            }
            SelectCardGame(prevGameName);
        }
        private void Delete()
        {
            if (AllCardGames.Count < 1)
            {
                Debug.LogError(DeleteErrorMessage + DeleteWarningMessage);
                return;
            }

            try
            {
                Directory.Delete(Current.GameDirectoryPath, true);
                AllCardGames.Remove(Current.Id);
                ResetCurrentToDefault();
                ResetGameScene();
            }
            catch (Exception ex)
            {
                Debug.LogError(DeleteErrorMessage + ex.Message);
            }
        }
        public void Select(string gameId)
        {
            if (string.IsNullOrEmpty(gameId) || !AllCardGames.ContainsKey(gameId))
            {
                (_, string gameUrl) = CardGame.Decode(gameId);
                if (!Uri.IsWellFormedUriString(gameUrl, UriKind.Absolute))
                {
                    Debug.LogError(SelectionErrorMessage);
                    Messenger.Show(SelectionErrorMessage);
                }
                else
                {
                    StartCoroutine(DownloadCardGame(gameUrl));
                }
                return;
            }

            Current = AllCardGames[gameId];
            ResetGameScene();
        }
Пример #11
0
        public void SelectRight()
        {
            string nextGameName = Current.Name;

            SortedDictionary <string, CardGame> .Enumerator allCardGamesEnum = AllCardGames.GetEnumerator();
            bool found = false;

            while (!found && allCardGamesEnum.MoveNext())
            {
                if (allCardGamesEnum.Current.Key.Equals(Current.Name))
                {
                    found = true;
                }
            }
            if (allCardGamesEnum.MoveNext())
            {
                nextGameName = allCardGamesEnum.Current.Key;
            }
            else if (found)
            {
                nextGameName = AllCardGames.Keys.First();
            }
            SelectCardGame(nextGameName);
        }