2017-09-23 12 views
0

所以。我製作了一個統一的遊戲5.我已經下載並配置了谷歌播放服務插件。我可以登錄併成功解鎖成就。但由於某種原因, Social.ShowAchievementsUI();Social.ShowLeaderboardUI(); 將無法​​正常工作。或者不會彈出任何內容。AchievementsUI和LeaderboardsUI不會彈出。登錄作品並解鎖成就彈出窗口工作

所以我試圖展示成就列表並顯示可用的排行榜列表。我有5個成就和4個排行榜。我在Google Play Alpha測試中擁有此版本的遊戲。使用打開成就菜單和排行榜的2個按鈕,但這些按鈕不起作用。 我給登錄碼是:

void Start() { 
    if (PlayGamesPlatform.Instance.IsAuthenticated() == false) 
    { 
     PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build(); 
     PlayGamesPlatform.InitializeInstance(config); 
     PlayGamesPlatform.DebugLogEnabled = true; 
     PlayGamesPlatform.Activate(); 
     SignIn(); 
    } 

void SignIn() 
{ 
     Social.localUser.Authenticate((bool success) => 
     {}); 
} 

用於示出achievementsUI

public void ShowAchievementsUI() 
{ 
    Social.ShowAchievementsUI(); 
} 

用於示出Leaderboard ui

public void ShowLeaderboardsUI() 
{ 
    Social.ShowLeaderboardUI(); 
} 

這些2由按鈕調用。

我使用:

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using GooglePlayGames; 
using UnityEngine.SocialPlatforms; 
using GooglePlayGames.BasicApi; 

回答

1

添加:

<activity android:name="com.google.games.bridge.NativeBridgeActivity" 
     android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" /> 

要AndroidManifest.xml中解決了該問題

0

首先爲您PlayGames命令的腳本。劇本本身只是一個公開課;但是,所有命令都是靜態的,以便您可以從其他腳本調用它們。

using GooglePlayGames; 
using GooglePlayGames.BasicApi; 
using UnityEngine; 

public class PlayGamesScript : MonoBehaviour { 

// Use this for initialization 
void Start() { 
    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build(); 
    PlayGamesPlatform.InitializeInstance(config); 
    PlayGamesPlatform.Activate(); 
    SignIn(); 
} 

// PRE: None 
// POST: Logs player into Google Play Games 
void SignIn() 
{ 
    Social.localUser.Authenticate (success => {}); 
} 

#region Achievements 
// PRE: Achievement created in Google Play Developer and the 
// achievement has been achieved by the player 
// POST: Unlocks the achievement for the player 
public static void UnlockAchievement(string id) 
{ 
    Social.ReportProgress(id, 100, success => { }); 
} 

// PRE: Achievement created in Google Play Developer and set to Incremental 
// achievement 
// POST: Increments the achievement by selected steps established by 
// the stepsToIncrement variable 
public static void IncrementAchievement(string id, int stepsToIncrement) 
{ 
    PlayGamesPlatform.Instance.IncrementAchievement(id, stepsToIncrement, success => { }); 
} 

// PRE: Achievements created in Google Play Developer and player 
// is logged in 
// POST: Shows the Achievements UI 
public static void ShowAchievementsUI() 
{ 
    if(PlayGamesPlatform.Instance.IsAuthenticated()) 
     Social.ShowAchievementsUI(); 
    else 
     Social.localUser.Authenticate((bool success)=>{ 
      Social.ShowAchievementsUI(); 
     }); 
} 
#endregion /Achievements 

#region Leaderboards 
// PRE: Leaderboard created in Google Play Developer and player is logged in 
// POST: Reports the score to the leaderboard id specified for Google Play 
public static void AddScoreToLeaderboard(string leaderboardId, long score) 
{ 
    Social.ReportScore(score, leaderboardId, success => { }); 
} 
// PRE: Leaderboard created in Google Play Developer and player is logged in 
// POST: Accesses the PlayGamesScript to display the Leaderboard UI 
public static void ShowLeaderboardsUI() 
{ 
    if(PlayGamesPlatform.Instance.IsAuthenticated()) 
     Social.ShowLeaderboardUI(); 
    else 
     Social.localUser.Authenticate((bool success)=>{ 
      Social.ShowLeaderboardUI(); 
     }); 
} 
#endregion /Leaderboards 

} 

你從另一個腳本(調用查看排行榜或成就UI腳本)調用這些功能,例如:

public class GooglePlayUIController : MonoBehaviour { 

    // PRE: Leaderboard created in Google Play Developer 
    // POST: Accesses the PlayGamesScript to display the Leaderboard UI 
    public void ShowLeaderboards() { 
     PlayGamesScript.ShowLeaderboardsUI(); 
    } 

    // PRE: Achievements created in Google Play Developer 
    // POST: Accesses the PlayGamesScript to display the Achievement UI 
    public void ShowAchievements() { 
     PlayGamesScript.ShowAchievementsUI(); 
    } 
} 

從那裏,你可以通過添加這些功能集成到你的按鈕OnClick()函數的Unity編輯器;這是我如何設置我的。

當然,不要忘記在選項卡窗口 - > Google Play遊戲 - > Android設置中將您的資源數據添加到Unity中,以便您可以調用每個成就的ID或調用排行榜ID,通過GPGSIds。例如,

// PRE: A game has been played until all lives equal zero 
// POST: A score has been posted to the online leaderboards 
private void PostScore() { 
    PlayGamesScript.AddScoreToLeaderboard (GPGSIds.high_score, player.score); 
} 
+0

所以,如果我在一個按鈕,它不會工作這種情況下ShowAchievementsUI()調用他們? public void ShowAchievementsUI() { Social.ShowAchievementsUI(); } 我已經配置好了。我有成就解鎖彈出窗口工作和所有的東西。但Social.ShowAchievementsUI()和Social.ShowLeaderboardUIi()將不起作用 –

+0

您提供的此代碼不應該更改任何內容,因爲它與我的類似。我說你沒有讀過這個問題。 –

+0

其實它不同,因爲你正試圖直接打開用戶界面,因爲我正在從靜態函數訪問函數。我遇到了同樣的問題,這是我的解決方案。看看這個youtube視頻,如果你還沒有找到你的問題的答案.... –