Professional Documents
Culture Documents
GitHub - Google Play Games Plugin For Unity
GitHub - Google Play Games Plugin For Unity
GitHub - Google Play Games Plugin For Unity
Overview
Google Play mängude pistikprogramm Unity jaoks võimaldab teil pääseda juurde
Google Play mängude API-le Unity sotsiaalse liidese kaudu. Pistikprogramm toetab
järgmisi Google Play mängude API funktsioone:
sign in
friends
unlock/reveal/increment achievement
post score to leaderboard
cloud save read/write
show built-in achievement/leaderboards UI
events
nearby connections
Funktsioonid:
System requirements:
o Android SDK
o Android v4.0 or higher
o Google Play Services library, version 11.6 or above
Uuendamine
Kui olete juba integreerinud oma projekti pistikprogrammi eelmise versiooniga ja
soovite minna üle uuele versioonile, vaadake versiooniuuenduse juhiseid upgrade
instructions
• Web client ID – see on lingitud veebirakenduse kliendi ID. Seda on vaja ainult siis,
kui teil on oma mängu jaoks veebipõhine taustaprogramm ja vajate serveri
autentimiskoodi, mille taustaserver vahetab juurdepääsuloa vastu, või kui teil on vaja
ID-luba, et mängija saaks teha muud, mittemängu (non-game) , API kõned.
Add Events
Sündmused võimaldavad teil jälgida kasutajate toiminguid teie mängus ja koostada
nende kohta Analyticsi abil aruandeid. Lisateavet sündmuste konfigureerimise ja
kasutamise kohta leiate jaotisest Game Concepts - Events
Plugin Installation
Plugina allalaadimiseks kloonige see Giti hoidla oma failisüsteemi (või laadige see
ZIP-failina alla ja pakkige lahti). Seejärel otsige praeguse ehituse kataloogist üles
unitypackage'i fail:
current-build/GooglePlayGamesPluginForUnity-X.YY.ZZ.unitypackage
Android Setup
Järgmisena seadistage Unity'is oma Android SDK installimise tee. See asub eelistuste
(preferences) menüüs jaotises External Tools.
Sisestage konstantide klassi nimi. See on täielikult kvalifitseeritud klassi nimi, mida
värskendatakse (või luuakse), mis sisaldab mänguressursside ID-sid. Nime vorming on
.. Näiteks AwesomeGame.GPGSIds
Kleepige ressursi määratluse andmed (resource definition data). Need on Google Play
arendajakonsooli XML-andmed, mis sisaldavad nii ressursi ID-sid kui ka Androidi
rakenduse ID-d.
Need andmed leiate Google Play arendajakonsoolist, klõpsates mis tahes ressursilehe
(nt saavutused või edetabelid) valikul „Hangi ressursse” ja seejärel klõpsates Androidil.
1. Set the JAVA_HOME environment variable to your Java SDK installation path
(for example, C:\Program Files\Java\jdk1.7.0_45).
2. Add the Java SDK's bin folder to your PATH environment variable (for
example, C:\Program Files\Java\jdk1.7.0_45\bin)
3. Reboot.
Käivitage projekt
Kui töötate Smoketest näidisega, peaksite saama projekti praegusel hetkel koostada
ja käivitada. Kui Smoketest käivitub, näete automaatset sisselogimiskatset.
Androidi loomiseks ja käitamiseks klõpsake nuppu File > Build Settings, select
the Android platform, then Switch to Platform, then Build and Run.
ISocialPlatform Compliance
The Google Play Games plugin implements Unity's social interface, for compatibility
with games that already use that interface when integrating with other platforms.
However, some features are unique to Play Games and are offered as extensions to
the standard social interface provided by Unity.
The standard API calls can be accessed through the Social.Active object, which is a
reference to an ISocialPlatform interface. The non-standard Google Play Games
extensions can be accessed by casting the Social.Active object to
the PlayGamesPlatform class, where the additional methods are available.
Sign in
Mängu avamisel luuakse automaatselt ühendus mänguteenustega. Kui ühendus on
edukas, tervitatakse mängijat hüpikaknaga ja teie mäng on valmis Games Unity
pluginat kasutama.
Märkus. Kui kasutaja pole selles seadmes kunagi Google Play mänge kasutanud,
viiakse ta automaatselt läbi ühekordsete seadistustoimingute, näiteks Play mängude
rakendusega profiili loomise.
The result code is an enum, which gives you different failure reasons that will help
you understand sign-in failures better.
If you prefer using Unity’s Social platform, then you can alternatively use the code
block below.
using GooglePlayGames;
Friends
Play Games Friends allows players to create and maintain a cross-games friends list.
You can request access to this friends list to help your players play your game with
their friends. See the Friends concept page for more details on the friends system.
View friends: Request access to a player’s friends list, so you can add their play
games friends to your in-game friends list
View a player profile: Let a player view the Play Games profile of another
player. This is essential so a player knows who their friends are, and can
connect to other Play Games players in your game. This will need to be tied to
a UI element to trigger the popup. See the friends guidelines for details.
See the best practices guidelines for instructions on how best to implement these
APIs.
Note: To use Friends, you need to update your PGS SDK to version 20.0.0
View friends
There are two ways to load friends, either using the ISocial framework or directly
with PlayGamesPlatform.
However, this call will fail if the current player has not yet granted permission to the
game to access this information. Use GetLastLoadFriendsStatus to check
if LoadFriends failed due to missing consent.
PlayGamesPlatform.Instance.GetLastLoadFriendsStatus((status) => {
// Check for consent
if (status == LoadFriendsStatus.ResolutionRequired) {
// Ask for resolution.
}
});
A game can ask the current player to share the friends list by
calling AskForLoadFriendsResolution.
PlayGamesPlatform.Instance.AskForLoadFriendsResolution((result) => {
if (result == UIStatus.Valid) {
// User agreed to share friends with the game. Reload friends.
} else {
// User doesn’t agree to share the friends list.
}
});
This function will show the appropriate platform-specific friends sharing UI. This UI
asks the player if they want to share their friends with the game.
The pageSize param represents the number of entries to request for this page. Note
that if cached data already exists, the returned buffer may contain more than this size.
The buffer is guaranteed to contain at least this many entries if the collection contains
enough records. If forceReload is set to true, this call will clear any locally-cached
data and attempt to fetch the latest data from the server. This would commonly be
used for actions like a user-initiated refresh. Normally, this should be set to false to
gain the advantages of data caching.
If the callback returns LoadFriendsStatus.LoadMore, then there are more friends to
load. LoadFriendsStatus.ResolutionRequired signals that the user has not shared
the friends list and you can directly
call PlayGamesPlatform.Instance.AskForLoadFriendsResolution.
PlayGamesPlatform.Instance.GetFriendsListVisibility(forceReload,
(friendsListVisibilityStatus) => {});
Player Statistics
Mängijastatistika API (The Player Stats API) võimaldab teil kohandada
mängukogemusi vastavalt mängijate konkreetsetele segmentidele ja mängija
elutsükli erinevatele etappidele. Saate luua iga mängijasegmendi jaoks kohandatud
kogemusi vastavalt mängijate edenemisele, kulutamisele ja kaasamisele. Näiteks saate
seda API-t kasutada ennetavate toimingute tegemiseks, et julgustada vähem aktiivset
mängijat teie mänguga uuesti tegelema, näiteks kuvades ja reklaamides uusi
mängusiseseid üksusi, kui mängija sisse logib.
Revealing/Unlocking an Achievement
To unlock an achievement, use the Social.ReportProgress method with a progress
value of 100.0f:
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
...
// unlock achievement (achievement ID "Cfjewijawiu_QA")
Social.ReportProgress("Cfjewijawiu_QA", 100.0f, (bool success) => {
// handle success or failure
});
Incrementing an Achievement
If your achievement is incremental, the Play Games implementation
of Social.ReportProgress will try to behave as closely as possible to the expected
behavior according to Unity's social API, but may not be exact. For this reason, we
recommend that you do not use Social.ReportProgress for incremental achievements.
Instead, use the PlayGamesPlatform.IncrementAchievement method, which is a
Play Games extension.
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
...
// increment achievement (achievement ID "Cfjewijawiu_QA") by 5 steps
PlayGamesPlatform.Instance.IncrementAchievement(
"Cfjewijawiu_QA", 5, (bool success) => {
// handle success or failure
});
To post a score and include a metadata tag use the Play Game Services instance
directly:
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
...
// post score 12345 to leaderboard ID "Cfji293fjsie_QA" and tag
"FirstDaily")
Social.ReportScore(12345, "Cfji293fjsie_QA", "FirstDaily", (bool
success) => {
// handle success or failure
});
Pange tähele, et platvorm ja server jätavad mängija olemasolevast rekordist
madalamad punktisummad automaatselt kõrvale, nii et saate hindeid vabalt esitada
ilma igasuguste kontrollideta, et kontrollida, kas skoor on mängija olemasolevast
punktisummast suurem või mitte.
If you wish to show a particular leaderboard instead of all leaderboards, you can pass
a leaderboard ID to the method. This, however, is a Play Games extension, so the
Social.Active object needs to be cast to a PlayGamesPlatform object first:
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
...
// show leaderboard UI
PlayGamesPlatform.Instance.ShowLeaderboardUI("Cfji293fjsie_QA");
Using Social.ILeaderboard
This method uses the ILeaderboard interface to define the scope and filters for
getting the data. This approach allows you to configure:
1. The leaderboard Id
2. The collection (social or public)
3. The timeframe (daily, weekly, all-time)
4. The rank position to start retrieving scores.
5. The number of scores (the default is 25).
6. Filter by user id.
If the from parameter is non-positive, then the results returned are player-centered,
meaning the scores around the current player's score are returned.
ILeaderboard lb = PlayGamesPlatform.Instance.CreateLeaderboard();
lb.id = "MY_LEADERBOARD_ID";
lb.LoadScores(ok =>
{
if (ok) {
LoadUsersAndDisplay(lb);
}
else {
Debug.Log("Error retrieving leaderboardi");
}
});
Using PlayGamesPlatform.LoadScores()
This method uses the PlayGamesPlatform directly. This approach provides additional
flexibility and information when accessing the leaderboard data.
PlayGamesPlatform.Instance.LoadScores(
GPGSIds.leaderboard_leaders_in_smoketesting,
LeaderboardStart.PlayerCentered,
100,
LeaderboardCollection.Public,
LeaderboardTimeSpan.AllTime,
(data) =>
{
mStatus = "Leaderboard data valid: " + data.Valid;
mStatus += "\n approx:" +data.ApproximateCount + " have " +
data.Scores.Length;
});
1. leaderboardId
2. start position (top scores or player centered)
3. row count
4. leaderboard collection (social or public)
5. time span (daily, weekly, all-time)
6. callback accepting a LeaderboardScoreData object.
The LeaderboardScoreData class is used to return information back to the caller when
loading scores. The members are: 1. Id - the leaderboard id 2. Valid - true if the
returned data is valid (the call was successful) 3. Status - the ResponseStatus of the
call 4. ApproximateCount - the approximate number of scores in the leaderboard 5.
Title - the title of the leaderboard 6. PlayerScore - the score of the current player 7.
Scores - the list of scores 8. PrevPageToken - a token that can be used to
call LoadMoreScores() to get the previous page of scores. 9. NextPageToken - a token
that can be used to call LoadMoreScores() to get the next page of scores.
void GetNextPage(LeaderboardScoreData data)
{
PlayGamesPlatform.Instance.LoadMoreScores(data.NextPageToken, 10,
(results) =>
{
mStatus = "Leaderboard data valid: " + data.Valid;
mStatus += "\n approx:" +data.ApproximateCount + " have " +
data.Scores.Length;
});
}
Recording Events
Incrementing an event is very simple, just call the following method:
using GooglePlayGames;
...
// Increments the event with Id "YOUR_EVENT_ID" by 1
PlayGamesPlatform.Instance.Events.IncrementEvent("YOUR_EVENT_ID", 1);
This call is "fire and forget", it will handle batching and execution for you in the
background.
ISavedGameClient savedGameClient =
PlayGamesPlatform.Instance.SavedGame;
savedGameClient.ShowSelectSavedGameUI("Select saved game",
maxNumToDisplay,
allowCreateNew,
allowDelete,
OnSavedGameSelected);
}
1. the saved game metadata passed to the callback passed to one of the Open
calls.
2. the updates to make to the metadata.
3. the actual byte array of data
4. a callback to call when the commit is complete.
// Takes the screenshot from top left hand corner of screen and
maps to top
// left hand corner of screenShot texture
screenShot.ReadPixels(
new Rect(0, 0, Screen.width, (Screen.width/1024)*700), 0, 0);
return screenShot;
}
1. Configure the web client id of the web application linked to your game in the
Play Game Console.
2. Call PlayGamesPlatform.Instance.RequestServerSideAccess once the player
is authenticated to get the server side access code.
3. Pass this code to your server application.
PlayGamesPlatform.Instance.RequestServerSideAccess(
/* forceRefreshToken= */ false,
code -> {
// send code to server
});
Additionally, it is possible to reduce the size of the entire Unity project using
Unity’s Managed Code Stripping, which will compress your entire project. This can be
used in conjunction with Proguard.
Play Games Services Proguard configuration
1. Go to File > Build Settings > Player Settings and click Publishing
Settings section. Choose Proguard for Minify > Release. Then, enable User
Proguard File. If you want the plugin to be proguarded for debug apks as
well, you can choose Proguard for Minify > Debug.
2. Copy the content of the proguard
configuration into Assets/Plugins/Android/proguard-user.txt.
That way, you can even submit scores and achievements simultaneously to two or
more social platforms:
// Submit achievement to original default social platform
Social.ReportProgress("MyAchievementIdHere", 100.0f, callback);
PlayGamesPlatform.Instance.ReportProgress("MyGooglePlayAchievementIdHere",
100.0f, callback);
Special Thanks
This section lists people who have contributed to this project by writing code,
improving documentation or fixing bugs.