Example #1
0
        private void LoginAndCreateGame(LootLockerAuthResponse response)
        {
            int organisationID = response.user.organisations.FirstOrDefault().id;

            AppManager.activeOrganisationID = organisationID;
            ///lets try to find the demo game from the list of games coming from the server
            LootLockerGame demoGame = response.user.organisations.FirstOrDefault()?.games?.FirstOrDefault(x => x.is_demo == true);

            //if we found one, lets set the config up
            if (demoGame != null)
            {
                Debug.Log("There's already a Demo Game. Moving on.");
                AppManager.activeGameID         = demoGame.id;
                LootLockerConfig.current.gameID = demoGame.id;
                ///Lets pull more information about the game
                LootLockerSDKManager.GetDetailedInformationAboutAGame(LootLockerConfig.current.gameID.ToString(), (createGameResponse) =>
                {
                    if (createGameResponse.success)
                    {
                        //update the config of the game
                        LootLockerConfig.current.UpdateAPIKey(createGameResponse.game.game_key);
                        successScreen.SetActive(true);
                        activatingScreen.SetActive(false);
                    }
                    else
                    {
                        activatingScreen.SetActive(false);
                        carouselScreen.SetActive(true);
                        normalLoginContent.SetActive(false);
                        failedLoginContent.SetActive(true);
                    }
                });
            }
            else
            {
                //There's no "Demo Game". Create it.
                Debug.LogWarning("No game called Demo Game. Creating one...");
                LootLockerSDKManager.CreatingAGame("Demo Game", "0", true, organisationID, true, (createGameResponse) =>
                {
                    //we were succesful in creating a demo game
                    if (createGameResponse.success)
                    {
                        Debug.Log("Successful created a demo game: " + createGameResponse.text);
                        AppManager.activeGameID         = createGameResponse.game.id;
                        LootLockerConfig.current.gameID = createGameResponse.game.id;
                        LootLockerSDKManager.GetDetailedInformationAboutAGame(LootLockerConfig.current.gameID.ToString(), (createGameResponses) =>
                        {
                            if (createGameResponses.success)
                            {
                                LootLockerConfig.current.UpdateAPIKey(createGameResponses.game.game_key);
                                successScreen.SetActive(true);
                                activatingScreen.SetActive(false);
                            }
                            else
                            {
                                activatingScreen.SetActive(false);
                                carouselScreen.SetActive(true);
                                normalLoginContent.SetActive(false);
                                failedLoginContent.SetActive(true);
                            }
                        });
                    }
                    else
                    {
                        activatingScreen.SetActive(false);
                        carouselScreen.SetActive(true);
                        normalLoginContent.SetActive(false);
                        failedLoginContent.SetActive(true);
                    }
                });
            }
        }