コード例 #1
0
        public override void Resume(StateExitValue results)
        {
            CommonData.mainGame.SelectAndPlayMusic(CommonData.prefabs.menuMusic, true);
            // Whenever we come back to the main menu, check:
            // If we have authentication data, but haven't fetched user data
            // yet, go try to get user data.
            if (results == null ||
                (results != null && results.sourceState != typeof(FetchUserData)))
            {
#if UNITY_EDITOR
                if (CommonData.currentUser == null)
                {
                    manager.PushState(new FetchUserData(Startup.DefaultDesktopID));
#else
                Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
                if (auth.CurrentUser != null && CommonData.currentUser == null)
                {
                    manager.PushState(new FetchUserData(auth.CurrentUser.UserId));
#endif
                    return;
                }
            }
            SetFirebaseMessagingListeners();
            SetFirebaseInvitesListeners();
            InitializeUI();
        }
コード例 #2
0
        public override void Resume(StateExitValue results)
        {
            ShowUI();
            if (results != null)
            {
                if (results.sourceState == typeof(WaitForTask))
                {
                    WaitForTask.Results taskResults = results.data as WaitForTask.Results;
                    if (taskResults.task.IsFaulted)
                    {
                        manager.SwapState(new ManageAccount());
                        manager.PushState(new BasicDialog(StringConstants.DeleteAccountFail +
                                                          taskResults.task.Exception.ToString()));
                    }
                    else
                    {
                        // Delete the user's profile data:
                        string           path     = CommonData.DBUserTablePath + userId;
                        FirebaseDatabase database = FirebaseDatabase.GetInstance(CommonData.app);

                        // Delete all maps associated with this user:
                        database.GetReference(path).SetValueAsync(null);
                        foreach (MapListEntry map in CommonData.currentUser.data.maps)
                        {
                            path = CommonData.DBMapTablePath + map.mapId;
                            database.GetReference(path).SetValueAsync(null);
                        }
                        manager.SwapState(new ChooseSignInMenu());
                        manager.PushState(new BasicDialog(StringConstants.DeleteAccountSuccess));
                    }
                }
            }
        }
コード例 #3
0
        public override void Resume(StateExitValue results)
        {
            ShowUI();

            // SignInResult is used with a email/password, while WaitForTask.Results
            // is used when signing in with an anonymous account.
            SignInResult result = results.data as SignInResult;

            WaitForTask.Results taskResult = results.data as WaitForTask.Results;

            if ((result != null && !result.Canceled) ||
                (taskResult != null && !taskResult.task.IsCanceled))
            {
                if (auth.CurrentUser != null)
                {
                    CommonData.isNotSignedIn = false;
                    manager.PopState();
                }
                else
                {
                    manager.PushState(new BasicDialog(
                                          Utilities.StringHelper.SigninInFailureString(taskResult.task)));
                }
            }
        }
コード例 #4
0
 // Resume the state.  Called when the state becomes active
 // when the state above is removed.  That state may send an
 // optional object containing any results/data.  Results
 // can also just be null, if no data is sent.
 public override void Resume(StateExitValue results)
 {
     CommonData.mainGame.SelectAndPlayMusic(CommonData.prefabs.menuMusic, true);
     ShowUI();
     CommonData.gameWorld.RespawnWorld();
     CommonData.mainCamera.mode = CameraController.CameraMode.Editor;
     if (results != null)
     {
         if (results.sourceState == typeof(WaitingForDBLoad <LevelMap>))
         {
             var resultData = results.data as WaitingForDBLoad <LevelMap> .Results;
             if (resultData.wasSuccessful && resultData.results != null)
             {
                 currentLevel = resultData.results;
                 currentLevel.DatabasePath = resultData.path;
                 CommonData.gameWorld.DisposeWorld();
                 CommonData.gameWorld.SpawnWorld(currentLevel);
                 Debug.Log("Map load complete!");
             }
             else
             {
                 Debug.LogWarning("Map load complete, but not successful...");
             }
         }
     }
     UpdateCameraController();
 }
コード例 #5
0
        // Ends the currently-running state, and resumes whatever is next
        // down the line.
        public void PopState()
        {
            StateExitValue result = CurrentState().Cleanup();

            stateStack.Pop();
            CurrentState().Resume(result);
        }
コード例 #6
0
 public override void Resume(StateExitValue results)
 {
     ShowUI();
     if (results != null)
     {
         if (results.sourceState == typeof(WaitForTask))
         {
             WaitForTask.Results taskResults = results.data as WaitForTask.Results;
             if (taskResults.task.IsFaulted)
             {
                 manager.PushState(new BasicDialog("Could not create account."));
             }
             else
             {
                 if (!string.IsNullOrEmpty(dialogComponent.DisplayName.text))
                 {
                     Firebase.Auth.UserProfile profile =
                         new Firebase.Auth.UserProfile();
                     profile.DisplayName = dialogComponent.DisplayName.text;
                     // We are fine with this happening in the background,
                     // so just return to the previous state after triggering the update.
                     auth.CurrentUser.UpdateUserProfileAsync(profile);
                 }
                 manager.PopState();
             }
         }
     }
 }
コード例 #7
0
        public override void Resume(StateExitValue results)
        {
            CommonData.mainGame.SelectAndPlayMusic(CommonData.prefabs.menuMusic, true);
            // Whenever we come back to the main menu, check:
            // If we have authentication data, but haven't fetched user data
            // yet, go try to get user data.
            bool shouldFetchUserData;

            if (results == null)
            {
                shouldFetchUserData = true;
            }
            else if (results.sourceState != typeof(FetchUserData) && results.sourceState != typeof(WaitForTask))
            {
                shouldFetchUserData = true;
            }
            else
            {
                shouldFetchUserData = false;
            }
            if (shouldFetchUserData)
            {
                Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
                if (auth.CurrentUser != null && CommonData.currentUser == null)
                {
                    manager.PushState(new FetchUserData(auth.CurrentUser.UserId));
                    return;
                }
            }
            SetFirebaseMessagingListeners();
            InitializeUI();
        }
コード例 #8
0
        // When we get back from the gameplay state, exit the app:
        public override void Resume(StateExitValue results)
        {
            Debug.Log("Shutting down!");

            CommonData.testLab.NotifyHarnessTestIsComplete();

            Application.Quit();
        }
コード例 #9
0
 // Resume the state.  Called when the state becomes active
 // when the state above is removed.  That state may send an
 // optional object containing any results/data.  Results
 // can also just be null, if no data is sent.
 public override void Resume(StateExitValue results)
 {
     ShowUI();
     CommonData.mainGame.SelectAndPlayMusic(CommonData.prefabs.gameMusic, true);
     Time.timeScale             = 1.0f;
     CommonData.mainCamera.mode = CameraController.CameraMode.Gameplay;
     Screen.sleepTimeout        = SleepTimeout.NeverSleep;
 }
コード例 #10
0
 // When we get back from the gameplay state, load the next map and continue.
 public override void Resume(StateExitValue results)
 {
     profiler.Finish();
     PerformanceProfiler.PerformanceData data = profiler.GetDataSnapshot();
     data.levelIndex = nextLevelIndex;
     performanceData.Add(data);
     if (!StartNextLevel())
     {
         Debug.Log(GenerateFullReport());
         manager.SwapState(new BasicDialog("Tests completed."));
     }
     else
     {
         Debug.Log(GenerateLevelReport(data));
     }
 }
コード例 #11
0
 // Resume the state.  Called when the state becomes active
 // when the state above is removed.  That state may send an
 // optional object containing any results/data.  Results
 // can also just be null, if no data is sent.
 public override void Resume(StateExitValue results)
 {
     if (results != null)
     {
         if (results.sourceState == typeof(WaitingForDBLoad <UserData>))
         {
             var resultData = results.data as WaitingForDBLoad <UserData> .Results;
             if (resultData.wasSuccessful)
             {
                 if (resultData.results != null)
                 {
                     // Got some results back!  Use this data.
                     CommonData.currentUser = new DBStruct <UserData>(
                         CommonData.DBUserTablePath + userID, CommonData.app);
                     CommonData.currentUser.Initialize(resultData.results);
                     Debug.Log("Fetched user " + CommonData.currentUser.data.name);
                 }
                 else
                 {
                     // Make a new user, using default credentials.
                     Debug.Log("Could not find user " + userID + " - Creating new profile.");
                     UserData temp = new UserData();
                     temp.name = StringConstants.DefaultUserName;
                     temp.id   = userID;
                     CommonData.currentUser = new DBStruct <UserData>(
                         CommonData.DBUserTablePath + userID, CommonData.app);
                     CommonData.currentUser.Initialize(temp);
                     CommonData.currentUser.PushData();
                 }
             }
             else
             {
                 // Can't fetch data.  Assume internet problems, stay offline.
                 CommonData.currentUser = null;
             }
         }
     }
     // Whether we successfully fetched, or had to make a new user,
     // return control to the calling state.
     manager.PopState();
     if (GooglePlayServicesSignIn.CanAutoSignIn())
     {
         manager.PushState(
             new WaitForTask(GooglePlayServicesSignIn.SignIn(),
                             StringConstants.LabelSigningIn, true));
     }
 }
コード例 #12
0
        public override void Resume(StateExitValue results)
        {
            InitializeUI();

            if (results != null)
            {
                if (results.sourceState == typeof(WaitForTask))
                {
                    WaitForTask.Results taskResults = results.data as WaitForTask.Results;
                    if (taskResults.task.IsFaulted)
                    {
                        manager.PushState(new BasicDialog(
                                              Utilities.StringHelper.SigninInFailureString(taskResults.task)));
                    }
                }
            }
        }
コード例 #13
0
 public override void Resume(StateExitValue results)
 {
     ShowUI();
     if (results != null)
     {
         WaitForTask.Results taskResults = results.data as WaitForTask.Results;
         if (taskResults != null && taskResults.task.IsFaulted)
         {
             manager.PushState(new BasicDialog(
                                   Utilities.StringHelper.SigninInFailureString(taskResults.task)));
         }
         else
         {
             manager.PopState();
         }
     }
 }
コード例 #14
0
ファイル: Startup.cs プロジェクト: yusufbahadir/mechahamster
 // Got back from either fetching userdata from the database, or
 // requesting an anonymous login.
 // If we got back from login, request/start a user with that ID.
 // If we got back from fetching user data, start the game.
 public override void Resume(StateExitValue results)
 {
     if (results.sourceState == typeof(ChooseSignInMenu) ||
         results.sourceState == typeof(WaitForTask))
     {
         // We just got back from trying to sign in anonymously.
         // Did it work?
         if (auth.CurrentUser != null)
         {
             // Yes!  Continue!
             manager.PushState(new FetchUserData(auth.CurrentUser.UserId));
         }
         else
         {
             // Nope.  Couldn't sign in.
             CommonData.isNotSignedIn = true;
             manager.SwapState(new States.MainMenu());
         }
     }
     else if (results.sourceState == typeof(FetchUserData))
     {
         // Just got back from fetching the user.
         // Did THAT work?
         InitializeAnalytics();
         if (CommonData.testLab.IsTestingScenario)
         {
             CommonData.currentReplayData = StringConstants.TestLoopReplayData;
             manager.SwapState(new States.TestLoop(CommonData.testLab.ScenarioNumber));
         }
         else
         {
             manager.SwapState(new States.MainMenu());
             if (CommonData.currentUser == null)
             {
                 //  If we can't fetch data, tell the user.
                 manager.PushState(new BasicDialog(StringConstants.CouldNotFetchUserData));
             }
         }
     }
     else
     {
         throw new System.Exception("Returned from unknown state: " + results.sourceState);
     }
 }
コード例 #15
0
        public override void Resume(StateExitValue results)
        {
            CommonData.mainCamera.mode = CameraController.CameraMode.Gameplay;
            if (results != null)
            {
                if (results.sourceState == typeof(WaitForTask))
                {
                    WaitForTask.Results resultData = results.data as WaitForTask.Results;

                    var task =
                        resultData.task as System.Threading.Tasks.Task <List <TimeData> >;
                    if (task != null)
                    {
                        DisplayTimes = task.Result;
                    }
                }
            }
            InitializeUI();
        }
コード例 #16
0
        public override void Resume(StateExitValue results)
        {
            if (results != null)
            {
                if (results.sourceState == typeof(UploadTime))
                {
                    ScoreUploaded = ScoreUploaded || (bool)results.data;
                }
                else if (results.sourceState == typeof(TopTimes))
                {
                    ScoreUploaded = true;
                }
            }

            ShowUI();
            dialogComponent.SubmitButton.gameObject.SetActive(
                !CommonData.gameWorld.HasPendingEdits &&
                !ScoreUploaded && CommonData.ShowInternetMenus());
        }
コード例 #17
0
 public override void Resume(StateExitValue results)
 {
     ShowUI();
     if (results != null)
     {
         if (results.sourceState == typeof(WaitForTask))
         {
             WaitForTask.Results taskResults = results.data as WaitForTask.Results;
             if (taskResults.task.IsFaulted)
             {
                 manager.SwapState(new BasicDialog(StringConstants.SignInPasswordResetError));
             }
             else
             {
                 manager.SwapState(new BasicDialog(string.Format(
                                                       StringConstants.SignInPasswordReset, dialogComponent.Email.text)));
             }
         }
     }
 }
コード例 #18
0
        public override void Resume(StateExitValue results)
        {
            if (results != null)
            {
                if (results.sourceState == typeof(WaitingForDBLoad <string>))
                {
                    var resultData = results.data as WaitingForDBLoad <string> .Results;

                    CommonData.currentUser.data.AddSharedMap(resultData.results, mapId);
                    CommonData.currentUser.PushData();

                    // Now tell them about it!
                    manager.SwapState(new BasicDialog(string.Format(StringConstants.SharedMapUserMessage,
                                                                    resultData.results)));
                }
                else
                {
                    manager.SwapState(new BasicDialog("Got back something weird..."));
                }
            }
        }
コード例 #19
0
        public override void Resume(StateExitValue results)
        {
            CommonData.mainCamera.mode = CameraController.CameraMode.Gameplay;
            if (results != null)
            {
                if (results.sourceState == typeof(WaitForTask))
                {
                    WaitForTask.Results resultData = results.data as WaitForTask.Results;

                    if (resultData.task.IsFaulted)
                    {
                        Debug.LogException(resultData.task.Exception);
                        manager.SwapState(new BasicDialog(StringConstants.UploadError));
                        return;
                    }

                    TimeUploaded = true;
                    Firebase.Analytics.FirebaseAnalytics.LogEvent(
                        StringConstants.AnalyticsEventTimeUploadFinished,
                        StringConstants.AnalyticsParamMapId, CommonData.gameWorld.worldMap.mapId);

                    // Show the top times for the level, highlighting which one was just uploaded.
                    var task =
                        resultData.task as System.Threading.Tasks.Task <List <UserScore> >;
                    List <UserScore> times = null;
                    if (task != null)
                    {
                        times = task.Result;
                    }
                    manager.SwapState(new TopTimes(times));
                    return;
                }
            }
            // This is a passthrough state, so if we are still the top, pop ourselves.
            if (manager.CurrentState() == this)
            {
                manager.PopState();
            }
        }
コード例 #20
0
 public override void Resume(StateExitValue results)
 {
     base.Resume(results);
     if (results != null)
     {
         if (results.sourceState == typeof(WaitingForDBLoad <LevelMap>))
         {
             var resultData = results.data as WaitingForDBLoad <LevelMap> .Results;
             if (resultData.wasSuccessful && resultData.results != null)
             {
                 currentLevel = resultData.results;
                 currentLevel.DatabasePath = resultData.path;
                 CommonData.gameWorld.DisposeWorld();
                 CommonData.gameWorld.SpawnWorld(currentLevel);
             }
             else
             {
                 manager.PushState(new BasicDialog("Unable to load map."));
             }
         }
     }
 }
コード例 #21
0
 public override void Resume(StateExitValue results)
 {
     ShowUI();
 }
コード例 #22
0
 public override void Resume(StateExitValue results)
 {
     InitializeUI();
 }
コード例 #23
0
 public override void Resume(StateExitValue results)
 {
     // After we have shown the dialog, quit.
     Application.Quit();
 }
コード例 #24
0
 // Resume the state.  Called when the state becomes active
 // when the state above is removed.  That state may send an
 // optional object containing any results/data.  Results
 // can also just be null, if no data is sent.
 public virtual void Resume(StateExitValue results)
 {
 }