Skip to content

Commit

Permalink
Adding Recall in smoketest app
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 689317214
Change-Id: Ia0cb8f19620fa3e2776609df9eb14fef38dbfb21
  • Loading branch information
Play Games Services Team authored and copybara-github committed Oct 24, 2024
1 parent 41c2f2d commit a24c50e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Samples/SmokeTest/Scripts/MainGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class MainGui : MonoBehaviour
private AchievementGUI mAchievementGui;
private LeaderboardGUI mLeaderboardGui;
private FriendsGUI mFriendsGui;
private RecallGUI mRecallGui;

// which UI are we showing?
public enum Ui {
Expand All @@ -72,7 +73,8 @@ public enum Ui {
Achievements,
Leaderboards,
UserInfo,
Friends
Friends,
Recall
}

public void Start()
Expand All @@ -86,6 +88,7 @@ public void Start()
this.mAchievementGui = new AchievementGUI(this);
this.mLeaderboardGui = new LeaderboardGUI(this);
this.mFriendsGui = new FriendsGUI(this);
this.mRecallGui = new RecallGUI(this);
}

public void SetUI(Ui page)
Expand Down Expand Up @@ -196,6 +199,10 @@ internal void ShowRegularUi()
{
SetUI(Ui.Events);
}
else if (GUI.Button(this.CalcGrid(1, 4), "Recall"))
{
SetUI(Ui.Recall);
}
}

internal void ShowEditSavedGameName()
Expand Down Expand Up @@ -660,6 +667,9 @@ internal void OnGUI()
case Ui.UserInfo:
ShowUserInfoUi();
break;
case Ui.Recall:
mRecallGui.OnGUI();
break;
default:
// check for a status of interest, and if there
// is one, then don't touch it. Otherwise
Expand Down
89 changes: 89 additions & 0 deletions Samples/SmokeTest/Scripts/RecallGUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// <copyright file="MainGui.cs" company="Google Inc.">
// Copyright (C) 2014 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

namespace SmokeTest
{
using UnityEngine;
using GooglePlayGames;

public class RecallGUI : MonoBehaviour
{
private MainGui mOwner;
private string mStatus;

internal RecallGUI(MainGui owner)
{
mOwner = owner;
mStatus = "";
}

internal void OnGUI()
{
float height = Screen.height / 11f;
GUILayout.BeginVertical(GUILayout.Height(Screen.height), GUILayout.Width(Screen.width));
GUILayout.Label("SmokeTest: Recall", GUILayout.Height(height));
GUILayout.BeginHorizontal(GUILayout.Height(height));
if (GUILayout.Button("Get Recall Access Token", GUILayout.Height(height), GUILayout.ExpandWidth(true)))
{
GetRecallAccessToken();
}
GUILayout.EndHorizontal();
GUILayout.Space(50f);
GUILayout.BeginHorizontal(GUILayout.Height(height));

if (GUILayout.Button("Back", GUILayout.ExpandHeight(true),
GUILayout.Height(height), GUILayout.ExpandWidth(true)))
{
mOwner.SetUI(MainGui.Ui.Main);
}

GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(mStatus);
GUILayout.EndVertical();
}

void SetStandBy(string msg)
{
mStatus = msg;
}

void EndStandBy()
{
mStatus += " (Done!)";
}

internal void ShowEffect(bool success)
{
Camera.main.backgroundColor =
success ? new Color(0.0f, 0.0f, 0.8f, 1.0f) : new Color(0.8f, 0.0f, 0.0f, 1.0f);
}

internal void GetRecallAccessToken()
{
SetStandBy("Fetching recall access token......");
PlayGamesPlatform.Instance.RequestRecallAccess(
recallAccess => {
EndStandBy();
string recallSessionId = recallAccess.sessionId;
mStatus = "Recall Session ID for current session is: " + recallSessionId;
Debug.Log("Recall Token fetched successfully: " + mStatus);
ShowEffect(recallSessionId != null && recallSessionId != "");
});
return;
}
}
}

0 comments on commit a24c50e

Please sign in to comment.