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); }
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); }
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(); }
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); } }
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(); }
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); }