-
Notifications
You must be signed in to change notification settings - Fork 3
Develop in Unity
Once finished Configure on Dev Center, you can switch to Unity for developing. A complete sample scene can be found at Assets\Examples\Main.unity.
-
Create a new Unity project.
-
Drag the UserProfile and XboxLiveServices prefab onto the scene. And also add a EventSystem from GameObject > UI.
-
-
Drag two IntegerStat prefabs onto the scene, set one's name to "ScoreStat" and the other's to "KillsStat".
-
For ScoreStat, set its ID to score and Display Name to High Score which are configured on Dev Center.
-
For KillsStat, set its ID to kills and Display Name to Kill Count. This stat is not configured on Dev Center and is used for "Shooting Master" achievement.
-
Drag two StatPanel prefabs onto the scene, also set one's name to "ScoreStatPanel" and the other's to "KillsStatPanel".
-
For the ScoreStatPanel, set its Stat to ScoreStat in Inspector. For the ScoreStatPanel, set its Stat to KillsStat.
-
Add two UI buttons to your scene, and in the
OnClick
event of each button, in the Unity inspector, add an IntegerStat object, and call theIncrement
function to increase the value of the stat by one every time you click the button. -
Add a "FlushStatsButton" UI button to call
RequestFlushToService
method to flush the data manually.
-
-
Drag a Leaderboard prefab onto the scene, set the Stat to ScoreStat, Leaderboard Type to Global and Entry Count to 3.
-
Set up "Shooting Master" achievement
-
Create a
ShootingMasterAchievement
class inherited fromAchievementBase
.using System; public class ShootingMasterAchievement : AchievementBase { public int targetNumber; private IntegerStat stat; // Use this for initialization void Start() { stat = GetComponent<IntegerStat>(); if (stat != null) { stat.StatChanged += UnlockAchievement; base.XboxLiveUser = stat.XboxLiveUser; } } public override uint CalculateProgress() { return (uint)Math.Round(Convert.ToDouble(stat.Value) / targetNumber * 100); } }
-
And add it as an component of KillsStat. So that KillsStat can be used to keeps track of the kill count that needed to unlock the achievement.
-
In Inspector, set ID to 1 and TargetNumber to 10.
-
-
Save the scene.
After all these done, you can Build and test the project.