示例#1
0
        private void ParseLeaderboardData(LeaderboardScoresDownloaded_t steamData)
        {
            UnityEngine.Debug.Log("Steam ParseLeaderboardData");

            List <OutrunLeaderboard.Entry> result = new List <OutrunLeaderboard.Entry> ();

            for (var i = 0; i < steamData.m_cEntryCount; i++)
            {
                LeaderboardEntry_t steamEntry;
                SteamUserStats.GetDownloadedLeaderboardEntry(steamData.m_hSteamLeaderboardEntries, i, out steamEntry, null, 0);

                OutrunLeaderboard.Entry resulEntry = new OutrunLeaderboard.Entry()
                {
                    userId     = steamEntry.m_steamIDUser.ToString()
                    , userName = SteamFriends.GetFriendPersonaName(steamEntry.m_steamIDUser)
                    , distance = steamEntry.m_nScore
                    , rank     = steamEntry.m_nGlobalRank
                    , isMe     = (steamEntry.m_steamIDUser == _playerId)
                };

                result.Add(resulEntry);
            }

            if (OnLeaderboardData != null)
            {
                OnLeaderboardData(result);
            }
        }
        private void OnData(Message <LeaderboardEntryList> msg)
        {
            if (msg.IsError)
            {
                switch (msg.GetError().Code)
                {
                case NO_LEADERBOARD_ENTRY:
                    UnityEngine.Debug.Log("Oculus: No leaderboard entry for this user");
                    SendDefaultEntry();
                    break;

                case LOG_IN_ERROR:
                    UnityEngine.Debug.Log("Oculus: Log in error");
                    SendDummyData();
                    break;

                default:
                    UnityEngine.Debug.LogError(string.Format("Error {0}: {1}", msg.GetError().Code, msg.GetError().Message));
                    break;
                }
            }
            else
            {
                List <OutrunLeaderboard.Entry> result = new List <OutrunLeaderboard.Entry> ();

                foreach (var entry in msg.Data)
                {
                    OutrunLeaderboard.Entry data = new OutrunLeaderboard.Entry()
                    {
                        userId     = entry.User.ID.ToString()
                        , userName = entry.User.OculusID
                        , rank     = entry.Rank
                        , distance = (int)entry.Score
                        , isMe     = (entry.User.ID == _playerId)
                    };

                    result.Add(data);
                }

                if (OnLeaderboardData != null)
                {
                    OnLeaderboardData(result);
                }
            }
        }
        private void SendDefaultEntry()
        {
            OutrunLeaderboard.Entry entry = new OutrunLeaderboard.Entry()
            {
                userId     = _playerId.ToString()
                , userName = _playerName
                , distance = 0
                , rank     = 0
                , isMe     = true
            };

            if (OnLeaderboardData != null)
            {
                OnLeaderboardData(new List <OutrunLeaderboard.Entry> ()
                {
                    entry
                });
            }
        }
        private void SendDummyData()
        {
            UnityEngine.Debug.LogWarning("Leaderboard dummy data");

            OutrunLeaderboard.Entry entry = new OutrunLeaderboard.Entry()
            {
                userId     = "Disconnected"
                , userName = "******"
                , distance = 0
                , rank     = 0
            };

            if (OnLeaderboardData != null)
            {
                OnLeaderboardData(new List <OutrunLeaderboard.Entry> ()
                {
                    entry
                });
            }
        }