0
\$\begingroup\$

I m making a multiplayer game using playfab.

One player send a friend request Second player then not display a player name?? I want the access(display) a player name??? see the referance,

Code:

ListingPrefab.cs

   public class ListingPrefab : MonoBehaviour  
   {
      public static ListingPrefab Instance;

      public Text playerNameText;
    }
FriendRequest.cs

public class FriendRequest : MonoBehaviour
{
    public GameObject listingPrefab;   //btn
    public Transform panel;           //parent

    //Display Friend
    void DisplayFriends(List<FriendInfo> friendsCache)
    {
        foreach (FriendInfo f in friendsCache)    // I think problem is here
        {
            GameObject listfriend = Instantiate(listingPrefab);
            ListingPrefab templisting = listfriend.GetComponent<ListingPrefab>();
            templisting.transform.SetParent(panel, true);

            //PlayerPrefs.GetString("PlayerName", ListingPrefab.Instance.playerNameText.text.ToString());  
            //PlayerPrefs.SetString("PlayerName",  ListingPrefab.Instance.playerNameText.text.ToString());  

            Debug.Log("playername:" + templisting.playerNameText + friendsearch);
            //Debug.Log("helloone"+ f.TitleDisplayName);
            templisting.playerNameText.text = f.TitleDisplayName;                               // TitleDisplayName PlayFab unique username for this friend.
        }
    }

    void DisplayPlayFabError(PlayFabError error)
    {
        Debug.LogError(error.GenerateErrorReport());
    }
    void DisplayError(string error)
    {
        Debug.LogError(error);
    }

    //Getfriend
    List<FriendInfo> _friends = null;

    public void GetFriends()  //you can call button click                      
    {
        PlayFabClientAPI.GetFriendsList(new GetFriendsListRequest
        {
            IncludeSteamFriends = false,
            IncludeFacebookFriends = false
        }, result => {
            _friends = result.Friends;
            DisplayFriends(_friends); // triggers your UI
        }, DisplayPlayFabError);
        Debug.Log("Inside GetFriends");
    }

    //Add friend
    enum FriendIdType { PlayFabId, Username, Email, DisplayName };

    void AddFriend(FriendIdType idType, string friendId)                    
    {
        var request = new AddFriendRequest();
        switch (idType)
        {
            case FriendIdType.PlayFabId:
                request.FriendPlayFabId = friendId;
                break;
            case FriendIdType.Username:
                request.FriendUsername = friendId;
                break;
            case FriendIdType.Email:
                request.FriendEmail = friendId;
                break;
            case FriendIdType.DisplayName:
                request.FriendTitleDisplayName = friendId;
                break;
        }
        // Execute request and update friends when we are done
        PlayFabClientAPI.AddFriend(request, result =>
        {
            Debug.Log("Friend added successfully!");       //Add a friend
        }, DisplayPlayFabError);
    }

    string friendsearch;
    [SerializeField]
    GameObject friendpanel;

    public void InputFriendID(string inputfriendid)
    {
        friendsearch = inputfriendid;
    }

    public void SubmitFriendRequest()     
    {
        AddFriend(FriendIdType.PlayFabId, friendsearch);
    }

    public void OpenCloseFriends()
    {
        friendpanel.SetActive(!friendpanel.activeInHierarchy);
    }

}

Prerequisites SDK: Unity

  1. The title ID is set in the PlayFabSharedSettings object (alaready i have)
  2. The project can successfully log in a user (alaready i have)
  3. The title has at least two registered users (alaready i have)

image:

I have 15 Player.

enter image description here

How To access a PlayerName??

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Presumably you read through the PlayFab Friends API and the AddFriend method. How have you tried invoking this in your game so far? \$\endgroup\$ – DMGregory Aug 19 '19 at 8:52
  • \$\begingroup\$ @DMGregory First requirement of the you have to display friend list Before you send request?? void DisplayFriends(List<FriendInfo> friendsCache) //Display a friend { friendsCache.ForEach(f => Debug.Log(f.FriendPlayFabId)); }but, how to get friend list?? i m first time working with playfab .. \$\endgroup\$ – alensducks Aug 19 '19 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.