using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.HuaweiAppGallery; using UnityEngine.HuaweiAppGallery.Listener; using UnityEngine.HuaweiAppGallery.Model; public class udpServiceSampleScript : MonoBehaviour { private static ILoginListener _loginListener = new MyLoginListener(); private static ICancelAuthListener _cancelAuthListener = new MyCancelAuthListener(); private static IStartReadSmsListener _startReadSmsListener = new MyStartReadSmsListener(); private static ISMSReceive _SMSReceive = new MySMSReceive(); private static ICheckUpdateListener _checkUpdateListener = new MyCheckUpdateListener(); private static IGetAchievementListListener _getAchievementListListener = new MyGetAchievementListListener(); private static IGetAchievementsIntentListener _getAchievementsIntentListener = new MyGetAchievementIntentListener(); private static IRevealListener _revealListener = new MyRevealListener(); private static IIncrementListener _incrementListener = new MyIncrementListener(); private static ISetStepsListener _setStepsListener = new MySetStepsListener(); private static IUnlockListener _unlockListener = new MyUnlockListener(); private static ILeaderboardSwitchStatusListener _leaderboardSwitchStatusListener = new MyLeaderboardSwitchStatusListener(); private static ISubmitScoreListener _submitScoreListener = new MySubmitScoreListener(); private static IGetLeaderboardIntentListener _getLeaderboardIntentListener = new MyGetLeaderboardIntentListener(); private static IGetLeaderboardsListener _getLeaderboardsListener = new MyGetLeaderboardsListener(); private static IGetLeaderboardListener _getLeaderboardListener = new MyGetLeaderboardListener(); private static IGetLeaderboardScoresListener _getLeaderboardScoresListener = new MyGetLeaderboardScoresListener(); private static IGetLeaderboardScoreListener _getLeaderboardScoreListener = new MyGetLeaderboardScoreListener(); private static IGetEventListListener _getEventListListener = new MyGetEventListListener(); private static IGetGameListener _getGameListener = new MyGetGameListener(); private static IGetPlayerListener _getPlayerListener = new MyGetPlayerListener(); private static IGetPlayerStatisticsListener _getPlayerStatisticsListener = new MyGetPlayerStatisticsListener(); private static IGetCachePlayerIdListener _getCachePlayerIdListener = new MyGetCachePlayerIdListener(); private static ISubmitPlayerEventListener _submitPlayerEventListener = new MySubmitPlayerEventListener(); private static ISubmitPlayerEventListener _submitGameBeginEventListener = new MySubmitGameBeginEventListener(); private static IGetPlayerExtraInfoListener _getPlayerExtraInfoListener = new MyGetPlayerExtraInfoListener(); private static ISavePlayerInfoListener _savePlayerInfoListener = new MySavePlayerInfoListener(); private static ILimitSizeListener _limitSizeListener = new MyLimitSizeListener(); private static IGetSnapshotDataListener _getSnapshotDataListener = new MyGetSnapshotDataListener(); private static IGetAllSnapshotDataListener _getAllSnapshotDataListener = new MyGetAllSnapshotDataListener(); private static IGetShowSnapshotListIntentListener _getShowSnapshotListIntentListener = new MyGetShowSnapshotListIntentListener(); private static IGetCoverImageListener _getCoverImageListener = new MyGetCoverImageListener(); private static IGetSnapshotResultListener _getSnapshotResultListener = new MyGetSnapshotResultListener(); private static IGetSnapshotResultListener _updateSnapshotResultListener = new UpdateGetSnapshotResultListener(); private static IDeleteSnapshotListener _deleteSnapshotListener = new MyDeleteSnapshotListener(); // local variables private static List achievementIds = new List(); private static List eventIds = new List(); private static string rankingId = ""; private static string snapshotId = ""; private static SnapshotData tempSnapshotData; private static Snapshot tempSnapshot; private static AndroidJavaObject apkUpgradeInfo; private static string playerId = ""; private static string transactionId = ""; private static Text info_panel; private static Button init_button; private static Button login_button; private static Button current_player_button; private static Button check_update_button; private static Button achievement_button; private static Button event_button; private static Button ranking_button; private static Button game_button; private static Button gameSave_button; private static Button player_button; private static Button anti_addiction_button; private static Button float_button; private static Transform subaction_panel; public GameObject prefabButton; private readonly List accountFunctionNames = new List() { "login", "silentSignIn", "signOut", "cancelAuthorization", "startReadSms", "registerSMSBroadcastReceiver", "unregisterSMSBroadcastReceiver" }; private readonly List accountFunctions = new List() { () => { Show("starting login"); HuaweiGameService.Login(_loginListener); }, () => { Show("starting silentSignIn"); HuaweiGameService.SilentSignIn(_loginListener); }, () => { Show("starting SignOut"); HuaweiGameService.SignOut(_loginListener); }, () => { Show("starting cancelAuthorization"); HuaweiGameService.CancelAuthorization(_cancelAuthListener); }, () => { Show("starting startReadSms"); HuaweiGameService.StartReadSms(_startReadSmsListener); }, () => { Show("starting registerSMSBroadcastReceiver"); HuaweiGameService.RegisterSMSBroadcastReceiver(_SMSReceive); }, () => { Show("starting unregisterSMSBroadcastReceiver"); HuaweiGameService.UnregisterSMSBroadcastReceiver(); Show("unregisterSMSBroadcastReceiver end"); }, }; private readonly List checkUpdateFunctionNames = new List() { "CheckUpdate", "ReleaseCallBack" }; private readonly List checkUpdateFunctions = new List() { () => { Show("start check update."); HuaweiGameService.CheckUpdate(_checkUpdateListener); }, // () => // { // Show("start show update dialog."); // HuaweiGameService.ShowUpdateDialog(appUpdateInfo,true); // }, () => { Show("start release callback."); HuaweiGameService.ReleaseCallBack(); Show("release callback end."); }, }; private readonly List achievementFunctionNames = new List() { "achievementList", "achievementsIntent", "reveal", "asyncReveal", "increment", "asyncIncrement", "setSteps", "asyncSetSteps", "unlock", "asyncUnlock" }; private readonly List achievementFunctions = new List() { () => { Show("start getting achievement list"); HuaweiGameService.GetAchievementList(true, _getAchievementListListener); }, () => { Show("start getting achievement intent"); HuaweiGameService.GetAchievementsIntent(_getAchievementsIntentListener); }, () => { Show("start revealing achievement."); if (achievementIds.Count == 0) { Show("no achievement found, please get list first."); return; } string id = achievementIds[0]; Show("revealing achievement with id: " + id); HuaweiGameService.Reveal(id); }, () => { Show("start revealing achievement."); if (achievementIds.Count == 0) { Show("no achievement found, please get list first."); return; } string id = achievementIds[0]; Show("async revealing achievement with id: " + id); HuaweiGameService.AsyncReveal(id, _revealListener); }, () => { int step = 3; Show("start increase achievement with step " + step); if (achievementIds.Count == 0) { Show("no achievement found, please get list first."); return; } string id = achievementIds[0]; Show("increase achievement by " + step + " steps with id: " + id); HuaweiGameService.Increment(id, step); }, () => { int step = 3; Show("start async increase achievement with step " + step); if (achievementIds.Count == 0) { Show("no achievement found, please get list first."); return; } string id = achievementIds[0]; Show("async increase achievement by " + step + " steps with id: " + id); HuaweiGameService.AsyncIncrement(id, step, _incrementListener); }, () => { int step = 3; Show("start set achievement with step " + step); if (achievementIds.Count == 0) { Show("no achievement found, please get list first."); return; } string id = achievementIds[0]; Show("set achievement by " + step + " steps with id: " + id); HuaweiGameService.SetSteps(id, step); }, () => { int step = 3; Show("start async set achievement with step " + step); if (achievementIds.Count == 0) { Show("no achievement found, please get list first."); return; } string id = achievementIds[0]; Show("set async achievement by " + step + " steps with id: " + id); HuaweiGameService.AsyncSetSteps(id, step, _setStepsListener); }, () => { Show("start unlock achievement"); if (achievementIds.Count == 0) { Show("no achievement found, please get list first."); return; } string id = achievementIds[0]; Show("start unlock achievement with id: " + id); HuaweiGameService.Unlock(id); }, () => { Show("start async unlock achievement"); if (achievementIds.Count == 0) { Show("no achievement found, please get list first."); return; } string id = achievementIds[0]; Show("start async unlock achievement with id: " + id); HuaweiGameService.AsyncUnlock(id, _unlockListener); }, }; private readonly List eventFunctionNames = new List() { "GetEventList", "GetEventListForceReload", "GetEventListByIds", "GetEventListByIdsForceReload", "EventIncrement" }; private readonly List eventFunctions = new List() { () => { Show("start getting event list forcereload false."); HuaweiGameService.GetEventList(false, _getEventListListener); }, () => { Show("start getting event list. forcereload true"); HuaweiGameService.GetEventList(true, _getEventListListener); }, () => { Show("start getting event list by ids. forcereload false"); if (eventIds.Count == 0) { Show("no event ids found, please get event list first"); return; } HuaweiGameService.GetEventListByIds(false, eventIds.ToArray(), _getEventListListener); }, () => { Show("start getting event list by ids. forcereload true"); if (eventIds.Count == 0) { Show("no event ids found, please get event list first"); return; } HuaweiGameService.GetEventListByIds(true, eventIds.ToArray(), _getEventListListener); }, () => { Show("start EventIncrement with amount 1"); if (eventIds.Count == 0) { Show("no event ids found, please get event list first"); return; } string eventId = eventIds[0]; HuaweiGameService.EventIncrement(eventId, 1); } }; private readonly List rankingFunctionNames = new List() { "GetRankingsData", "GetRankingSwitchStatus", "SetRankingSwitchStatusClose", "SetRankingSwitchStatusOpen", "SubmitScore", "AsyncSubmitScore", "SubmitScoreWithTag", "AsyncSubmitScoreWithTag", "GetAllRankingIntent", "GetRankingIntent", "GetRankingIntent(timeSpan)", "GetRankingData", "GetRankingTopScores", "GetRankingTopScores(offsetPlayerRank)", "GetCurrentPlayerRankingScore", "GetPlayerCenteredRankingScores", "GetPlayerCenteredRankingScores(offsetPlayerRank)", "GetMoreRankingScores" }; private readonly List rankingFunctions = new List() { () => { Show("start GetRankingsData"); HuaweiGameService.GetLeaderboardsData(true, _getLeaderboardsListener); }, () => { Show("start GetRankingSwitchStatus."); HuaweiGameService.GetLeaderboardSwitchStatus(_leaderboardSwitchStatusListener); }, () => { Show("start SetRankingSwitchStatus with status close"); HuaweiGameService.SetLeaderboardSwitchStatus(0, _leaderboardSwitchStatusListener); }, () => { Show("start SetRankingSwitchStatus with status open"); HuaweiGameService.SetLeaderboardSwitchStatus(1, _leaderboardSwitchStatusListener); }, () => { Show("start SubmitScore"); if (rankingId == "") { Show("please get ranking id first."); return; } Show("start SubmitScore with ranking id: " + rankingId + " score: " + 2); HuaweiGameService.SubmitScore(rankingId, 2); }, () => { Show("start AsyncSubmitScore"); if (rankingId == "") { Show("please get ranking id first."); return; } Show("start AsyncSubmitScore with ranking id: " + rankingId + " score: " + 2); HuaweiGameService.AsyncSubmitScore(rankingId, 2, _submitScoreListener); }, () => { Show("start SubmitScoreWithTag"); if (rankingId == "") { Show("please get ranking id first."); return; } Show("start SubmitScoreWithTag with ranking id: " + rankingId + " score: " + 2 + " score tag: testScoreTag"); HuaweiGameService.SubmitScore(rankingId, 2, "testScoreTag"); }, () => { Show("start AsyncSubmitScoreWithTag"); if (rankingId == "") { Show("please get ranking id first."); return; } Show("start AsyncSubmitScoreWithTag with ranking id: " + rankingId + " score: " + 2 + " score tag: testScoreTag"); HuaweiGameService.AsyncSubmitScore(rankingId, 2, "testScoreTag", _submitScoreListener); }, () => { Show("start GetAllRankingIntent"); HuaweiGameService.GetAllLeaderboardsIntent(_getLeaderboardIntentListener); }, () => { Show("start GetRankingIntent"); if (rankingId == "") { Show("please get ranking id first."); return; } HuaweiGameService.GetLeaderboardIntent(rankingId, _getLeaderboardIntentListener); }, () => { Show("start GetRankingIntent, timeSpan==1"); if (rankingId == "") { Show("please get ranking id first."); return; } HuaweiGameService.GetLeaderboardIntent(rankingId,1, _getLeaderboardIntentListener); }, () => { Show("start GetRankingData"); if (rankingId == "") { Show("please get ranking id first."); return; } HuaweiGameService.GetLeaderboardData(rankingId, true, _getLeaderboardListener); }, () => { Show("start GetRankingTopScores"); if (rankingId == "") { Show("please get ranking id first."); return; } HuaweiGameService.GetLeaderboardTopScores(rankingId, 2, 10, true, _getLeaderboardScoresListener); }, () => { Show("start GetRankingTopScores-String rankingId, int timeDimension, int maxResults, long offsetPlayerRank"); if (rankingId == "") { Show("please get ranking id first."); return; } HuaweiGameService.GetLeaderboardTopScores(rankingId, 2, 10, 1, 0, _getLeaderboardScoresListener); }, () => { Show("start GetCurrentPlayerRankingScore"); if (rankingId == "") { Show("please get ranking id first."); return; } HuaweiGameService.GetCurrentPlayerLeaderboardScore(rankingId, 2, _getLeaderboardScoreListener); }, () => { Show("start GetPlayerCenteredRankingScores"); if (rankingId == "") { Show("please get ranking id first."); return; } HuaweiGameService.GetPlayerCenteredLeaderboardScores(rankingId, 2, 10, true, _getLeaderboardScoresListener); }, () => { Show("start GetPlayerCenteredRankingScores-String rankingId, int timeDimension,int maxResults, long offsetPlayerRank, int pageDirection"); if (rankingId == "") { Show("please get ranking id first."); return; } HuaweiGameService.GetPlayerCenteredLeaderboardScores(rankingId, 2, 10, 1, 0, _getLeaderboardScoresListener); }, () => { Show("start GetMoreRankingScores"); if (rankingId == "") { Show("please get ranking id first."); return; } //todo timespan field HuaweiGameService.GetMoreLeaderboardScores(rankingId, 0, 10, 0, 2, _getLeaderboardScoresListener); } }; private readonly List gameFunctionNames = new List() { "GetGame", "GetLocalGame" }; private readonly List gameFunctions = new List() { () => { Show("start getting game."); HuaweiGameService.GetGame(_getGameListener); }, () => { Show("start getting local game."); HuaweiGameService.GetLocalGame(_getGameListener); }, }; private readonly List playerFunctionNames = new List() { "getGamePlayerStatistics","getCachePlayerId","savePlayerInfo" }; private readonly List playerFunctions = new List() { () => { Show("start getGamePlayerStatistics."); HuaweiGameService.GetGamePlayerStatistics(true, _getPlayerStatisticsListener); }, () => { Show("start getCachePlayerId"); HuaweiGameService.GetCachePlayerId(_getCachePlayerIdListener); }, () => { Show("start savePlayerInfo"); AndroidJavaObject jo = new AndroidJavaObject("com.huawei.hms.jos.games.AppPlayerInfo"); jo.Set("rank", "test rank"); jo.Set("role", "test role"); jo.Set("area", "test are"); jo.Set("sociaty", "test sociaty"); jo.Set("playerId", "test playerId"); HuaweiGameService.SavePlayerInfo(jo, _savePlayerInfoListener); }, }; private readonly List antiAddictionFunctionNames = new List() { "submitPlayerEvent(GAMEBEGIN)","submitPlayerEvent(GAMEEND)","getPlayerExtraInfo" }; private readonly List antiAddictionFunctions = new List() { () => { Show("start submitPlayerEvent(GAMEBEGIN)"); if (string.IsNullOrEmpty(playerId)) { Show("playerId is empty, please get the playerId first"); } else { HuaweiGameService.SubmitPlayerEvent(playerId,System.Guid.NewGuid().ToString(),"GAMEBEGIN",_submitGameBeginEventListener); } }, () => { Show("start submitPlayerEvent(GAMEEND)"); if (string.IsNullOrEmpty(playerId)) { Show("playerId is empty, please get the playerId first"); } else if (string.IsNullOrEmpty(transactionId)) { Show("transactionId is empty, please get the transactionId first"); } else { HuaweiGameService.SubmitPlayerEvent(playerId,transactionId,"GAMEEND",_submitPlayerEventListener); } }, () => { Show("start getPlayerExtraInfo"); if (string.IsNullOrEmpty(transactionId)) { Show("transactionId is empty, please get the transactionId first"); } else { HuaweiGameService.GetPlayerExtraInfo(transactionId, _getPlayerExtraInfoListener); } }, }; private readonly List gameSaveFunctionNames = new List() { "GrantDriveAccess", "GetLimitThumbnailSize", "GetLimitDetailsSize", "AddSnapshot", "GetSnapshotDataList", "GetShowArchiveListIntent", "GetThumbnail", "LoadSnapshotContents", "LoadSnapshotContents(snapshotData)", "LoadSnapshotContents(snapshotData,conflictPolicy)","UpdateSnapshot","UpdateSnapshot(conflict)", "DeleteSnapshot" }; private readonly List gameSaveFunctions = new List() { () => { Show("start GrantDriveAccess."); HuaweiGameService.GrantDriveAccess(); }, () => { Show("start GetLimitThumbnailSize."); HuaweiGameService.GetLimitThumbnailSize(_limitSizeListener); }, () => { Show("start GetLimitDetailsSize."); HuaweiGameService.GetLimitDetailsSize(_limitSizeListener); }, () => { Show("start AddSnapshot. with fake img and description: " + "demo description"); SnapshotContent content = new SnapshotContent(); content.Content = System.Text.Encoding.UTF8.GetBytes("test add snapshot content"); SnapshotChange snapshotChange = new SnapshotChange(); snapshotChange.Description = "demo add snapshot description"; snapshotChange.PlayedTimeMillis = 600; snapshotChange.CurrentProgress = 50; snapshotChange.CoverImage = bitmap_bytes; snapshotChange.ImageMimeType = "png"; HuaweiGameService.AddSnapshot(content, snapshotChange, true, _getSnapshotDataListener); }, () => { Show("start GetSnapshotDataList."); HuaweiGameService.GetSnapshotDataList(true, _getAllSnapshotDataListener); }, () => { Show("start GetShowArchiveListIntent."); HuaweiGameService.GetShowArchiveListIntent("archive title",true,true,-1, _getShowSnapshotListIntentListener); }, () => { Show("start GetThumbnail."); if (snapshotId == "" || tempSnapshotData == null) { Show("no snapshot id found, GetSnapshotDataList or AddOne first."); } HuaweiGameService.GetThumbnail(tempSnapshotData.SnapshotId, _getCoverImageListener); }, () => { Show("start LoadSnapshotContents."); if (snapshotId == "") { Show("no snapshot id found, GetSnapshotDataList or AddOne first."); return; } HuaweiGameService.LoadSnapshotContents(snapshotId, 1, _getSnapshotResultListener); }, () => { Show("start LoadSnapshotContents(snapshotData)."); if (tempSnapshotData == null) { Show("no snapshot found, GetSnapshotDataList or AddOne first."); return; } HuaweiGameService.LoadSnapshotContents(tempSnapshotData, _getSnapshotResultListener); }, () => { Show("start LoadSnapshotContents(snapshotData,conflictPolicy), conflictPolicy == 1."); if (tempSnapshotData == null) { Show("no snapshot found, GetSnapshotDataList or AddOne first."); return; } HuaweiGameService.LoadSnapshotContents(tempSnapshotData, 1, _getSnapshotResultListener); }, () => { Show("start UpdateSnapshot."); if (snapshotId == "") { Show("no snapshot id found, GetSnapshotDataList or AddOne first."); return; } SnapshotContent content = new SnapshotContent(); content.Content = System.Text.Encoding.UTF8.GetBytes("test update snapshot content"); SnapshotChange snapshotChange = new SnapshotChange(); snapshotChange.Description = "updated demo description"; snapshotChange.PlayedTimeMillis = 2000; snapshotChange.CurrentProgress = 100; HuaweiGameService.UpdateSnapshot(snapshotId, snapshotChange, content, _updateSnapshotResultListener); }, () => { Show("try to update the conflicting snapshot. start UpdateSnapshot."); if (snapshotId == "") { Show("no snapshot id found, GetSnapshotDataList or AddOne first."); return; } SnapshotContent content = new SnapshotContent(); content.Content = System.Text.Encoding.UTF8.GetBytes("try to update the conflicting snapshot"); SnapshotChange snapshotChange = new SnapshotChange(); snapshotChange.Description = "updated conflicting description"; snapshotChange.PlayedTimeMillis = 600; snapshotChange.CurrentProgress = 50; HuaweiGameService.UpdateSnapshot(snapshotId, snapshotChange, content, _updateSnapshotResultListener); }, () => { Show("start DeleteSnapshot."); if (snapshotId == "" || tempSnapshotData == null) { Show("no snapshot found, GetSnapshotDataList or AddOne first."); return; } HuaweiGameService.DeleteSnapshot(tempSnapshotData, _deleteSnapshotListener); }, }; private readonly List floatFunctionNames = new List() { "ShowFloatWindow", "HideFloatWindow" }; private readonly List floatFunctions = new List() { () => { Show("start ShowFloatWindow."); HuaweiGameService.ShowFloatWindow(); }, () => { Show("start HideFloatWindow."); HuaweiGameService.HideFloatWindow(); }, }; // Use this for initialization void Start() { initUI(); initListeners(); appInit(); } // Update is called once per frame void Update() { } private void appInit() { Show("starting appInit"); HuaweiGameService.AppInit(); Show("appInit finished"); } private void initUI() { info_panel = GameObject.Find("Information").GetComponent(); subaction_panel = GameObject.Find("SubActionPanel").GetComponent(); init_button = GameObject.Find("initBtn").GetComponent