| 1 | namespace Oculus.Platform.Samples.VrHoops |
| 2 | { |
| 3 | using UnityEngine; |
| 4 | using System.Collections; |
| 5 | using Oculus.Platform; |
| 6 | using Oculus.Platform.Models; |
| 7 | |
| 8 | public class AchievementsManager |
| 9 | { |
| 10 | // API NAME defined on the dashboard for the achievement |
| 11 | private const string LIKES_TO_WIN = "LIKES_TO_WIN"; |
| 12 | |
| 13 | // true if the local user hit the achievement Count setup on the dashboard |
| 14 | private bool m_likesToWinUnlocked; |
| 15 | |
| 16 | public bool LikesToWin |
| 17 | { |
| 18 | get { return m_likesToWinUnlocked; } |
| 19 | } |
| 20 | |
| 21 | public void CheckForAchievmentUpdates() |
| 22 | { |
| 23 | Achievements.GetProgressByName(new string[]{ LIKES_TO_WIN }).OnComplete( |
| 24 | (Message<AchievementProgressList> msg) => |
| 25 | { |
| 26 | foreach (var achievement in msg.Data) |
| 27 | { |
| 28 | if (achievement.Name == LIKES_TO_WIN) |
| 29 | { |
| 30 | m_likesToWinUnlocked = achievement.IsUnlocked; |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | public void RecordWinForLocalUser() |
| 38 | { |
| 39 | Achievements.AddCount(LIKES_TO_WIN, 1); |
| 40 | CheckForAchievmentUpdates(); |
| 41 | } |
| 42 | } |
| 43 | } |