Домой United States USA — software How Do I Integrate HMS to My Game Using HMS Unity Plugin...

How Do I Integrate HMS to My Game Using HMS Unity Plugin 2.0? — Part 4

159
0
ПОДЕЛИТЬСЯ

In this fourth installment tutorial on integrating HMS into My Game, learn more about other features of GameService including Leaderboards and SaveGame.
Join the DZone community and get the full member experience. Before I begin, if you haven’t read part 3 of this installment, you can read it here. For part 2 of the series, you can read that here. If you have not seen part 1 either, you can click here. This is the fourth part of our HMS Unity Plugin 2.0 integration guide. This time, I will be talking about other features of GameService: Leaderboards and SaveGame. At first, this part of the series was not planned, however, I thought that developers who might be interested in the other two parts of the GameService may be left off without a guide. Thus, I am adding this 4th part. I will be using a different game than the other three but, I will try to be as helpful as I can in this article, so you can adjust these two features to wherever you want to. Small Warning Before We Proceed: I will show the AGC side steps as much as I can, but this article also assumes that you have completed part 1 of the app/project creation, etc., have an app running in contact with AGC, and the plugin is ready to use. You can just enable Banner Ads and tick test ads to test if the plugin is working. Also, for the tests, make sure your account is registered as a sandbox test account. Details can be found in the docs link if you have not done it yet. As I said, I am using a different game for this part, but again, a very simple hyper-casual one. You have a rock and 5 rock counts at the beginning of the game. You throw it in a projected trajectory to hit the balloons, and you score points. Since the balloon generation and speed are determined at random, it is not as easy as it looks, but it has a very simple logic. Its name is “Hit The Target.” Leaderboards let you create leaderboards in your game so that the players can compete and see how they rank in comparison to others. Huawei, like its achievements, has its own UI to help you out when setting up the leaderboard system. All you have to do is to make sure that GameService is enabled in AppGallery Connect (aka AGC), and then, create a leaderboard with some pre-defined rules and use the plugins’ easy-to-use managers to send/submit scores to leaderboards. It literally takes one line to submit the score in simple scenarios after the AGC is set up, thanks to HMS Unity Plugin 2.0.x. You need to sign in to AGC and go to My apps. Then choose your app. My app in this case is “Hit The Target”. Go from the “Distribute” tab to the “Operate” tab and choose “Leaderboards.” Then, click the “New” button. You should see the screen below: Add the details of your leaderboard, such as the kind of scores you want, formatting, min/max numbers that can be submitted, etc. are all things that can be edited here. When you are done, click “Save.” Now, we need to copy the ID of the leaderboard, so we can feed it to the plugin and use it in our game. Do not release the leaderboards. Click “Obtain Resources” and copy the ID of the leaderboard you just created. Now, head to Unity. Open the drop-down Huawei menu and click Kit Settings. Next, enable GameService (Account Kit will automatically be enabled, which is okay), and go to the GameService tab. Add a name to your leaderboard (I used the same long name that I used in AGC), and paste the ID you copied in the previous step. Then, click create constant classes. Make sure to check the “Initialize On Start” button or you will have to write additional code. The coding phase in Leaderboards is very easy. All you have to do is to submit the score to the leaderboard you have created. You use the instance of HMSLeaderboardManager as usual and just call SubmitScore() function.

Continue reading...