Added Profile Pic Managemnt

dev-hazim
Hazim Bin Ijaz 4 weeks ago
parent ece6ca7637
commit a5d4fae805

@ -7676,7 +7676,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 46.75, y: -8.17}
m_AnchoredPosition: {x: 46.75, y: -8.169998}
m_SizeDelta: {x: -149.53, y: -58.42}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1975395084
@ -13147,6 +13147,7 @@ MonoBehaviour:
leaderboardYouPanel: {fileID: 722839593}
levelLeaderboardPopup: {fileID: 706426006}
levelLeaderboardLoading: {fileID: 1359513525}
levelTopperPic: {fileID: 2077189957}
debugHints: 0
--- !u!114 &1790415148045805191
MonoBehaviour:

@ -465,6 +465,17 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064589555812, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064589555812, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementTemplate
value:
objectReference: {fileID: 1144969350263548, guid: 52f308551e6b1a347a3a0d7de8089fa2,
type: 3}
- target: {fileID: 5869893064832991959, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: m_Name
@ -480,6 +491,11 @@ PrefabInstance:
propertyPath: States.Array.size
value: 7
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: DisplayAchievements
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.size
@ -488,12 +504,12 @@ PrefabInstance:
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[0].Progress
value: 4
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[6].Progress
value: 40
value: 3
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
@ -538,17 +554,17 @@ PrefabInstance:
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[6].LastProgressGoal
value: 45
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[0].LastProgressUpdate
value: 2
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: States.Array.data[6].LastProgressUpdate
value: 19
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
@ -693,7 +709,7 @@ PrefabInstance:
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
propertyPath: AchievementList.Array.data[6].ProgressGoal
value: 45
value: 5
objectReference: {fileID: 0}
- target: {fileID: 5869893064832991960, guid: 31c71d95d8fbeb7479842253d3964958,
type: 3}
@ -1188,23 +1204,12 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
playFabInit: {fileID: 0}
avatarImages:
- {fileID: 21300000, guid: ea3cab172bfebad4997f192ba43df8e3, type: 3}
- {fileID: 21300000, guid: fb208f21b2e399f45a7648d064e6fb69, type: 3}
- {fileID: 21300000, guid: 5e7d7e6aa85dfd04aa5ce01cc4f42b5c, type: 3}
playFabLeaderboards: {fileID: 0}
myProfile:
AdCampaignAttributions: []
AvatarUrl:
ContactEmailAddresses: []
DisplayName:
ExperimentVariants: []
LinkedAccounts: []
Locations: []
Memberships: []
PlayerId:
PublisherId:
PushNotificationRegistrations: []
Statistics: []
Tags: []
TitleId:
ValuesToDate: []
playFabUserDataManager: {fileID: 0}
--- !u!1 &1341897756
GameObject:
m_ObjectHideFlags: 0

@ -38,11 +38,19 @@ public class LeaderboardUIScreen : MonoBehaviour
private void PopulateLbItem(PlayerLeaderboardEntry lbEntry)
{
bool isSelf = lbEntry.Profile.PlayerId == PlayFabManager.Instance.myProfile.PlayerId;
bool isSelf = lbEntry.Profile.PlayerId == PlayFabManager.Instance.playFabUserDataManager.myProfile.PlayerId;
LBEntryItem lbItem = Instantiate(isSelf ? lbItemSelfPrefab : lbItemPrefab, content).GetComponent<LBEntryItem>();
lbItem.nameText.text = lbEntry.DisplayName;
lbItem.rankText.text = (lbEntry.Position + 1).ToString();
lbItem.scoreText.text = lbEntry.StatValue.ToString();
PlayFabManager.Instance.playFabUserDataManager.GetPlayerAvatarImage(lbEntry.PlayFabId, (sprite) =>
{
lbItem.profilePic.sprite = sprite;
},
(s) =>
{
Debug.Log("Couldnt get pic");
});
}
private void PopulatePedestalItem(PlayerLeaderboardEntry lbEntry)
@ -50,6 +58,14 @@ public class LeaderboardUIScreen : MonoBehaviour
LBPedestalItem pedestalItem = _lbPedestalItems[lbEntry.Position];
pedestalItem.nameText.text = lbEntry.DisplayName??lbEntry.PlayFabId;
pedestalItem.scoreText.text = lbEntry.StatValue.ToString();
PlayFabManager.Instance.playFabUserDataManager.GetPlayerAvatarImage(lbEntry.PlayFabId, (sprite) =>
{
pedestalItem.profilePic.sprite = sprite;
},
(s) =>
{
Debug.Log("Could'nt get pic");
});
}
private void OnLeaderboardFetchFailure(PlayFabError obj)

@ -43,7 +43,39 @@ public class PlayFabInit : MonoBehaviour
{
Debug.Log("Login successful!");
GetPlayerProfile();
GetCustomUserData();
}
private void GetCustomUserData()
{
GetPlayerProfileWithUserData();
}
public void GetPlayerProfileWithUserData()
{
var request = new GetPlayerCombinedInfoRequest
{
PlayFabId = PlayFabSettings.staticPlayer.PlayFabId, // Use the logged-in player's PlayFab ID
InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
{
GetUserData = true // This will include User Data like AvatarID in the response
}
};
PlayFabClientAPI.GetPlayerCombinedInfo(request, OnGetCombinedInfoSuccess, OnGetCombinedInfoFailure);
}
private void OnGetCombinedInfoSuccess(GetPlayerCombinedInfoResult result)
{
var userData = result.InfoResultPayload.UserData;
PlayFabManager.Instance.playFabUserDataManager.myCustomData = userData;
}
private void OnGetCombinedInfoFailure(PlayFabError error)
{
Debug.LogError("Failed to get combined player info: " + error.GenerateErrorReport());
}
public void GetPlayerProfile()
{
var request = new GetPlayerProfileRequest
@ -67,7 +99,7 @@ public class PlayFabInit : MonoBehaviour
private void OnGetProfileSuccess(GetPlayerProfileResult obj)
{
Debug.Log("Player profile fetching successful");
PlayFabManager.Instance.myProfile = obj.PlayerProfile;
PlayFabManager.Instance.playFabUserDataManager.myProfile = obj.PlayerProfile;
}
private void OnLoginFailure(PlayFabError error)

@ -1,5 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;
@ -7,8 +9,23 @@ public class PlayFabManager : MonoBehaviour
{
public static PlayFabManager Instance { get; private set; }
public PlayFabInit playFabInit;
public List<Sprite> avatarImages;
public PlayFabLeaderboards playFabLeaderboards;
public PlayerProfileModel myProfile;
public PlayFabUserData playFabUserDataManager;
private int myAvatarIndex
{
get
{
if (playFabUserDataManager.myCustomData != null && playFabUserDataManager.myCustomData.ContainsKey("AvatarID"))
{
return int.Parse(playFabUserDataManager.myCustomData["AvatarID"].Value);
}
return 0;
}
}
public Sprite myDisplayPicture => avatarImages[myAvatarIndex];
private void Awake()
{
if (Instance != null && Instance != this)
@ -23,6 +40,9 @@ public class PlayFabManager : MonoBehaviour
playFabInit = gameObject.AddComponent<PlayFabInit>();
playFabLeaderboards = gameObject.AddComponent<PlayFabLeaderboards>();
playFabUserDataManager = gameObject.AddComponent<PlayFabUserData>();
}
}

@ -0,0 +1,52 @@
using System;
using System.Collections;
using System.Collections.Generic;
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;
public class PlayFabUserData : MonoBehaviour
{
public PlayerProfileModel myProfile;
public Dictionary<string, UserDataRecord> myCustomData;
public void GetPlayerUserData(string playfabID, Action<Dictionary<string,UserDataRecord>> onCallback, Action<string> onFallback)
{
var request = new GetPlayerCombinedInfoRequest
{
PlayFabId = playfabID, // Use the logged-in player's PlayFab ID
InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
{
GetUserData = true // This will include User Data like AvatarID in the response
}
};
PlayFabClientAPI.GetPlayerCombinedInfo(request, result => onCallback(result.InfoResultPayload.UserData), result=>onFallback(result.ErrorMessage));
}
public void GetPlayerAvatarImage(string playfabID, Action<Sprite> onCallback, Action<string> onFallback)
{
var request = new GetPlayerCombinedInfoRequest
{
PlayFabId = playfabID, // Use the logged-in player's PlayFab ID
InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
{
GetUserData = true // This will include User Data like AvatarID in the response
}
};
PlayFabClientAPI.GetPlayerCombinedInfo(request, result =>
{
if (result.InfoResultPayload.UserData != null && result.InfoResultPayload.UserData.ContainsKey("AvatarID"))
{
Sprite dp = PlayFabManager.Instance.avatarImages[
int.Parse(result.InfoResultPayload.UserData["AvatarID"].Value)];
onCallback(dp);
}
else
onCallback(PlayFabManager.Instance.avatarImages[0]);
}, result=>onFallback(result.ErrorMessage));
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ee4dea21bf118984281a95b0829061bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -47,6 +47,7 @@ public class GameScene : MonoBehaviour
public GameObject leaderboardYouPanel;
public Popup levelLeaderboardPopup;
public GameObject levelLeaderboardLoading;
[SerializeField] private Image levelTopperPic;
public static GameScene instance;
@ -98,6 +99,7 @@ public class GameScene : MonoBehaviour
PlayFabManager.Instance.playFabLeaderboards.GetLeaderboardByKey(statisticName, OnLBSuccess, OnLBFail);
}
private void OnLBSuccess(List<PlayerLeaderboardEntry> obj)
{
if (obj.Count > 0)
@ -105,8 +107,16 @@ public class GameScene : MonoBehaviour
leaderboardNameText.text = obj[0].DisplayName;
float time = obj[0].StatValue / 1000f;
timeText.text = time + " secs";
leaderboardYouPanel.SetActive(obj[0].PlayFabId == PlayFabManager.Instance.myProfile.PlayerId);
leaderboardYouPanel.SetActive(obj[0].PlayFabId == PlayFabManager.Instance.playFabUserDataManager.myProfile.PlayerId);
levelLeaderboardLoading.SetActive(false);
PlayFabManager.Instance.playFabUserDataManager.GetPlayerAvatarImage(obj[0].PlayFabId, sprite =>
{
levelTopperPic.sprite = sprite;
},
(s) =>
{
Debug.Log("Couldnt get pic");
});
}
}

@ -15,6 +15,8 @@ U should buy the asset from home store if u use it in your project!
using MS;
using System.Collections.Generic;
using DG.Tweening;
using PlayFab;
using PlayFab.ClientModels;
using PlayFab.MultiplayerModels;
using TMPro;
using UnityEngine;
@ -144,9 +146,35 @@ public class HomeScene : MonoBehaviour
PlayerPrefs.SetInt(GameConstants.AvatarSelectedCheckKey, 1);
PlayerPrefs.SetInt(GameConstants.AvatarSelectedIndex, AvatarID);
AvatarSelectedSprite = AvatarSprites[AvatarID];
SetAvatarID(AvatarID);
//NameEnterPanel.Close();
}
public void SetAvatarID(int avatarID)
{
var request = new UpdateUserDataRequest
{
Data = new Dictionary<string, string>
{
{ "AvatarID", avatarID.ToString() } // Convert int to string for storage
}
};
PlayFabClientAPI.UpdateUserData(request, OnDataUpdateSuccess, OnDataUpdateFailure);
}
private void OnDataUpdateSuccess(UpdateUserDataResult result)
{
Debug.Log("Avatar ID updated successfully.");
}
private void OnDataUpdateFailure(PlayFabError error)
{
Debug.LogError("Failed to update Avatar ID: " + error.GenerateErrorReport());
}
private void SetupSettingToggle()
{
soundToggle.isOn = Sound.instance.IsEnabled();

Loading…
Cancel
Save