question

omerdruu avatar image
omerdruu asked

Viewing Users' Profile Photo in Photon Room

In the login section of the application (register), I make the user choose a profile photo and upload this photo to playfab. I then have the user download this image when they join a room. But the photo of all the users in the room is the same. Each user sees the photo of other players on their own screen as their own photo. If there are 4 players in the room, the same photo is downloaded 4 times.

How can I view their own picture of other players in the room?

My code file is almost identical to the one in this document( https://docs.microsoft.com/en-us/gaming/playfab/features/data/entities/quickstart ). I am sending you the different places:

To upload the photo :

 private void GaleridenResimCek(int maksimumBuyukluk)
    {
        NativeGallery.Permission izin = NativeGallery.GetImageFromGallery((konum) =>
        {
            Debug.Log("Seçilen resmin konumu: " + konum);
            if (konum != null)
            {
                // Seçilen resmi bir Texture2D'ye çevir
                Texture2D texture = NativeGallery.LoadImageAtPath(konum, maksimumBuyukluk);
                System.IO.File.Copy(konum, Application.persistentDataPath + "/SavedImage.png", true);


                if (texture == null)
                {

                    Debug.Log(konum + " konumundaki resimden bir texture oluşturulamadı.");
                    return;
                }


                profilep.sprite = Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100.0f);
            }
        }, "Bir resim seçin", "image/png");
    }
    void OnInitFileUpload(PlayFab.DataModels.InitiateFileUploadsResponse response)
    {
        var payload = File.ReadAllBytes(Application.persistentDataPath + "/SavedImage.png");
        
        GlobalFileLock += 1; // Start SimplePutCall
        PlayFabHttp.SimplePutCall(response.UploadDetails[0].UploadUrl,
            payload,
            FinalizeUpload,
            error => { Debug.Log(error); }
       
            );
        GlobalFileLock -= 1; // Finish InitiateFileUploads

    }

To download the photo : (This code file is inside the prefab, which is added to the player list content, which contains the player's profile photo and username.)

 void Start()
    {
            if (PlayFabClientAPI.IsClientLoggedIn() == true)
            {
                PlayFabAuthenticationAPI.GetEntityToken(new GetEntityTokenRequest(),
                  (entityResult) =>
                {
                    entityId = entityResult.Entity.Id;
                    entityType = entityResult.Entity.Type;

                    Debug.Log(entityId + entityType);
                    LoadAllFiles();
                }, OnPlayFabError);

            }

            PlayFabClientAPI.GetPlayerProfile(new GetPlayerProfileRequest()
            {
                ProfileConstraints = new PlayerProfileViewConstraints()
                {
                   ShowAvatarUrl = true
                }

            }, result =>
            {
                Debug.Log("Avatar Url is : " + result.PlayerProfile.AvatarUrl);

            },
          error => Debug.Log("Failed To Get Playfab Id"));     
    }

    IEnumerator GetActualFile(PlayFab.DataModels.GetFileMetadata fileData)
    {      
		 GlobalFileLock += 1; // Start Each SimpleGetCall
            PlayFabHttp.SimpleGetCall(fileData.DownloadUrl,
                result => { _entityFileJson[fileData.FileName] = Encoding.UTF8.GetString(result); GlobalFileLock -= 1; }, // Finish Each SimpleGetCall           
                error => { Debug.Log(error); }
            );
            PlayFabClientAPI.UpdateAvatarUrl(new UpdateAvatarUrlRequest()
            {
                ImageUrl = fileData.DownloadUrl

            },
    OnSuccess =>
    {}, OnFailed => { }); ;

            Debug.Log(fileData.DownloadUrl);
            Debug.Log(fileData.FileName);
            Debug.Log(fileData.Size);


        UnityWebRequest www = UnityWebRequestTexture.GetTexture(fileData.DownloadUrl);
        yield return www.SendWebRequest();
        Texture2D myTexture = DownloadHandlerTexture.GetContent(www);
        profilep2.sprite = Sprite.Create(myTexture, new Rect(0f, 0f, myTexture.width, myTexture.height), new Vector2(0.5f, 0.5f), 100.0f); ;

    }

Can you help me? Thanks.

unity3dentitiesphotondata
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

omerdruu avatar image omerdruu commented ·
0 Likes 0 ·

1 Answer

·
Made Wang avatar image
Made Wang answered

By default, GetEntityToken gets the entity Token of the player logged in by the current client, so your download method is only downloading the entity file of this player. What you need to get is the entity file URL of other players in the room, usually this operation should be done by your custom server, and the server should broadcast the URL to all players in the room.

I checked some documentation and found that PUN2 has SetPlayerCustomProperties() method, you can get the URL of the entity file before entering the room, then store it in custom properties, when a new player enters, other players can get it through Get() . I am not very familiar with photon, so it is recommended to seek the support of photon forum for specific details.

In addition, it should be noted that the valid time of each obtained entity file URL is only 10 minutes.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.