public void ReportStarAchievementProgress(int numStars) { if (numStars > 0 && numStars % 10 == 0) { int index = (numStars / 10) - 1; if (index >= 0 && index <= m_starAchievementIds.Length - 1) { PlayGameServices.unlockAchievement(m_starAchievementIds[index]); } } }
public void UnlockAchievement(string achievementName) { for (int i = 0; i < achievementNameID.Count; i++) { if (achievementNameID[i].achievementName == achievementName) { Debug.Log("Displaying achievements : " + achievementNameID[i].achievementID); PlayGameServices.unlockAchievement(achievementNameID[i].achievementID, true); } } }
public void RestoreAchievement(string achievementID) { #if UNITY_ANDROID if (!Enabled) { return; } string achievement = GetAchivementID(achievementID); if (achievement != null) { PlayGameServices.unlockAchievement(achievement, false); } #endif }
void ReportAchievement(string achievementID) { #if UNITY_IOS && GAMECENTER if (!GameCenterBinding.isPlayerAuthenticated()) { GameCenterBinding.authenticateLocalPlayer(); } GameCenterBinding.reportAchievement(achievementID, 100f); GameCenterBinding.showCompletionBannerForAchievements(); #endif #if UNITY_ANDROID #if GPGSERVIES && !AMAZONSTORE PlayGameServices.unlockAchievement(achievementID, true); #endif #endif }
//============================================================================= public void AddAchievement(int ID) { #if UNITY_IPHONE if ((IsLoggedIn() == true) && (m_ManagerState == eManagerState.Idle)) { GameCenterBinding.reportAchievement(ID.ToString(), 100.0f); m_ManagerState = eManagerState.AddAchievement; } else { if (AddAchievementFailEvent != null) { AddAchievementFailEvent("Error - not logged in or manager busy"); } m_bIsUploadingAchievement = false; m_UploadingAchievementTimeout = 20.0f; } #endif #if UNITY_ANDROID if ((IsLoggedIn() == true) && (m_ManagerState == eManagerState.Idle)) { string GPAchievementID = GPAchievementLookup[ID]; PlayGameServices.unlockAchievement(GPAchievementID, true); m_ManagerState = eManagerState.AddAchievement; } else { if (AddAchievementFailEvent != null) { AddAchievementFailEvent("Error - not logged in or manager busy"); } m_bIsUploadingAchievement = false; m_UploadingAchievementTimeout = 20.0f; } #endif #if UNITY_EDITOR m_bIsUploadingAchievement = false; m_UploadingAchievementTimeout = 5.0f; #endif }
public static void Report(Achievement achievement, int totalOrIncrement = 1) { if (!instanceExists) { Debug.LogWarning("AchievementManager:Report - s_Instance=null"); return; } if (instance.debugMode) { Debug.LogFormat("AchievementManager:Report({0},{1})", achievement, totalOrIncrement); } AchievementGroupInfo groupInfo = GetGroupInfo(achievement); if (groupInfo == null) { return; } // If not an incremental achievement and not total change, just return if (!groupInfo.isIncrement && groupInfo.currentCompleted == totalOrIncrement) { return; } groupInfo.AddOrSetCurrentCompleted(totalOrIncrement); OnAchievementChanged(groupInfo); // Report to GameCenter/PlayGames if (!PlayGameCenterManager.isAuthenticated) { return; } #if UNITY_IOS || UNITY_TVOS for (int i = 0, imax = groupInfo.achievementInfos.Length; i < imax; i++) { if (instance.debugMode) { Debug.LogFormat("AchievementManager:Report - currentCompleted={0}, requirements={1}", groupInfo.currentCompleted, groupInfo.achievementInfos[i].requirement); } GameCenterBinding.reportAchievement(groupInfo.achievementInfos[i].iOSId, Mathf.Min(100f * groupInfo.currentCompleted / groupInfo.achievementInfos[i].requirement, 100)); } #elif UNITY_ANDROID && !CHS for (int i = 0, imax = groupInfo.achievementInfos.Length; i < imax; i++) { AchievementInfo info = groupInfo.achievementInfos[i]; if (instance.debugMode) { Debug.LogFormat("AchievementManager:Report - groupInfo.isIncrement={0}, info.requirement={1}, info.androidId={2}", groupInfo.isIncrement, info.requirement, info.androidId); } if (groupInfo.isIncrement) // Increment achievement { if (info.requirement == 1) // Unlock directly if requirement is simply 1 { PlayGameServices.unlockAchievement(info.androidId); } else // Increment the achievement by 1 { PlayGameServices.incrementAchievement(info.androidId, totalOrIncrement); } } else // Simple achievement { if (groupInfo.currentCompleted >= info.requirement) { PlayGameServices.unlockAchievement(info.androidId); } } } #endif }
private static void OnAchievementsLoaded(string key) { if (key != "GPGModelAllAchievementMetadataKey") // The return data are all Play Games data returned, we only check for achievement { return; } if (!instanceExists) { return; } if (instance.debugMode) { Debug.Log("AchievementManager:OnAchievementsLoaded()"); } List <GPGAchievementMetadata> achievementMetadatas = PlayGameServices.getAllAchievementMetadata(); if (instance.debugMode) { Debug.LogFormat("AchievementManager:OnAchievementsLoaded - achievementMetadatas.Count={0}:", achievementMetadatas.Count); DebugUtils.Log(achievementMetadatas); } // Sync online achievement progress to local (new install but old progress), or local to online (offline progress) foreach (GPGAchievementMetadata achievementMetadata in achievementMetadatas) { foreach (AchievementGroupInfo groupInfo in instance.achievementGroupInfos) { for (int i = 0, imax = groupInfo.achievementInfos.Length; i < imax; i++) // Loop throught all achievements pre-set { AchievementInfo info = groupInfo.achievementInfos[i]; if (achievementMetadata.achievementId == info.androidId) { if (groupInfo.isIncrement) // Increment achievement { if (groupInfo.currentCompleted > achievementMetadata.completedSteps) { PlayGameServices.incrementAchievement(info.androidId, groupInfo.currentCompleted - achievementMetadata.completedSteps); } else if (groupInfo.currentCompleted < achievementMetadata.completedSteps) { groupInfo.currentCompleted = achievementMetadata.completedSteps; } } else // Simple achievement { if (groupInfo.currentCompleted > info.requirement) // Unlock if cached high score larger than the requirement { PlayGameServices.unlockAchievement(info.androidId); } } } } } } }
public void ReportHeartAchievement() { PlayGameServices.unlockAchievement(m_heartAchievementId); }
void OnGUI() { GUI.skin.label.alignment = TextAnchor.MiddleCenter; beginColumn(); GUILayout.Label("Authentication and Settings"); if (GUILayout.Button("Set Toasts on Bottom")) { PlayGameServices.setAchievementToastSettings(GPGToastPlacement.Bottom, 50); } if (GUILayout.Button("Authenticate")) { PlayGameServices.authenticate(); } if (GUILayout.Button("Sign Out")) { PlayGameServices.signOut(); } if (GUILayout.Button("Is Signed In")) { // Please note that the isSignedIn method is a total hack that was added to work around a current bug where Google // does not properly notify an app that the user signed out Debug.Log("is signed in? " + PlayGameServices.isSignedIn()); } if (GUILayout.Button("Get Player Info")) { var playerInfo = PlayGameServices.getLocalPlayerInfo(); Debug.Log(playerInfo); // if we are on Android and have an avatar image available, lets download the profile pic if (Application.platform == RuntimePlatform.Android && playerInfo.avatarUrl != null) { PlayGameServices.loadProfileImageForUri(playerInfo.avatarUrl); } } GUILayout.Label("Achievements"); if (GUILayout.Button("Show Achievements")) { PlayGameServices.showAchievements(); } if (GUILayout.Button("Increment Achievement")) { PlayGameServices.incrementAchievement("CgkI_-mLmdQEEAIQAQ", 2); } if (GUILayout.Button("Unlock Achievment")) { PlayGameServices.unlockAchievement("CgkI_-mLmdQEEAIQAw"); } endColumn(true); // toggle to show two different sets of buttons if (toggleButtonState("Show Cloud Save Buttons")) { secondColumnButtions(); } else { cloudSaveButtons(); } toggleButton("Show Cloud Save Buttons", "Toggle Buttons"); endColumn(false); }