Exemplo n.º 1
0
    public void Enter()
    {
        //PlayerPrefs.DeleteAll();

        ConnectivityController.CURRENT_ACTION = ConnectivityController.ENTER_ESPORT_TOURNAMENT_ACTION;
        GamesManager     gamesManager = new GamesManager();
        EventsController nbs          = new EventsController();
        UserManager      um           = new UserManager();

        StartCoroutine(nbs.checkInternetConnection((isConnected) => {
            // handle connection status here
            if (isConnected == true)
            {
                SceneManager.UnloadSceneAsync("Loader");
                SceneManager.LoadScene("Loader", LoadSceneMode.Additive);
                UnityThreadHelper.CreateThread(() => {
                    if (string.IsNullOrEmpty(GamesManager.GAME_ID))
                    {
                        Debug.LogError("Please Insert game id in GamesManager Class(gameId)");
                    }
                    else
                    {
                        string res = gamesManager.getGamebyId(GamesManager.GAME_ID);
                        if (!string.IsNullOrEmpty(res))
                        {
                            UnityThreadHelper.Dispatcher.Dispatch(() => {
                                StartCoroutine(BackgroundController.SaveBackgroundImage(BackgroundController.backgroundURL));
                                StartCoroutine(GamesManager.SaveIcon(GamesManager.ICON_URL));
                                StartCoroutine(TranslationManager.SavePreferedLaguage());
                            });
                            while (GamesManager.backgroundSaved == null || TranslationManager.isDownloaded == null)
                            {
                            }
                            if (GamesManager.backgroundSaved == true && TranslationManager.isDownloaded == true)
                            {
                                UnityThreadHelper.Dispatcher.Dispatch(() => {
                                    if (string.IsNullOrEmpty(GamesManager.GAME_ID))
                                    {
                                        Debug.LogError("Please Insert the correct game id in GamesManager Class(gameId)");
                                    }
                                    else
                                    {
                                        try
                                        {
                                            GameControll.isSeemba = true;

                                            if (um.getCurrentUserId() != null)
                                            {
                                                SceneManager.LoadSceneAsync("Home");
                                            }
                                            else
                                            {
                                                SceneManager.LoadSceneAsync("Intro");
                                            }
                                        }
                                        catch (NullReferenceException ex)
                                        {
                                            //Catch
                                        }
                                    }
                                });
                            }
                            else
                            {
                                UnityThreadHelper.Dispatcher.Dispatch(() => {
                                    SceneManager.UnloadSceneAsync("Loader");
                                    SceneManager.LoadScene("ConnectionFailed", LoadSceneMode.Additive);
                                });
                            }
                        }
                        else
                        {
                            Debug.LogError("Please Insert game id in GamesManager Class(gameId)");
                            UnityThreadHelper.Dispatcher.Dispatch(() => {
                                SceneManager.UnloadSceneAsync("Loader");
                            });
                        }
                    }
                });
            }
            else
            {
                try
                {
                    SceneManager.UnloadSceneAsync("ConnectionFailed");
                }
                catch (ArgumentException ex) { }
                SceneManager.LoadScene("ConnectionFailed", LoadSceneMode.Additive);
                SceneManager.UnloadSceneAsync("Loader");
            }
        }));
    }