Beispiel #1
0
    private void SaveFriendsForMap(JSONArray dataFriends)
    {
        if (FacebookUtils.friendAvatarUrls != "")
        {
            return;
        }

        List <string> avatarUrlList   = new List <string>();
        List <int>    selectedIndexes = new List <int>();

        for (int i = 0; i < CommonConst.MAX_FRIEND_IN_MAP; i++)
        {
            if (selectedIndexes.Count >= dataFriends.Count)
            {
                break;
            }
            int index = 0;
            while (true)
            {
                index = UnityEngine.Random.Range(0, dataFriends.Count - 1);
                if (!selectedIndexes.Contains(index))
                {
                    selectedIndexes.Add(index);
                    break;
                }
            }
            string avatarUrl = dataFriends[index]["picture"]["data"]["url"].Value;
            avatarUrlList.Add(avatarUrl);
        }

        string avatarUrls = CUtils.BuildStringFromCollection(avatarUrlList);

        FacebookUtils.friendAvatarUrls = avatarUrls;

        // levels
        List <int> friendLevels = new List <int>();

        for (int i = 0; i < CommonConst.START_FRIEND_LEVELS.Length; i++)
        {
            friendLevels.Add(CommonConst.START_FRIEND_LEVELS[i]);
        }
        string strFriendLevels = CUtils.BuildStringFromCollection(friendLevels);

        FacebookUtils.friendLevels = strFriendLevels;

        // scores
        for (int i = 0; i < friendLevels.Count; i++)
        {
            List <int> scores = new List <int>();
            for (int level = 1; level < friendLevels[i]; level++)
            {
                int baseScore = CommonConst.GetTargetScore(level);
                int score     = UnityEngine.Random.Range(baseScore, baseScore * 3);
                score = (score / 10) * 10;
                scores.Add(score);
            }
            string strScores = CUtils.BuildStringFromCollection(scores);
            FacebookUtils.SetFriendScores(i, strScores);
        }
    }