using UnityEngine; using System.Collections; using TMPro; using UnityEngine.UI; public class ScoreAvatar : MonoBehaviour { public TextMeshProUGUI playerName; public TextMeshProUGUI rank; public TextMeshProUGUI score; public RawImage avatar; public TextMeshProUGUI background; //public ReadTextureCoordinatesFromNGUI sperm; public Color myNameColor; public Color myInfoColor; public Color theirNameColor; public Color theirInfoColor; public GameObject BackgroundBronze; public GameObject BackgroundGold; public GameObject BackgroundSilver; public GameObject BackgroundDefault; public Texture2D anonymousAvatar; Score _scoreData; void OnDisable() { //reset the avatar's texture since this is a pooled object avatar.texture = anonymousAvatar; _scoreData = null; } public void SetData(Score data) { _scoreData = data; playerName.text = data.user.name+" "+data.user.surname; if(data.rank > 0) { rank.text = "#"+data.rank.ToString(); } else { rank.text = ""; } score.text = data.score.ToString("0,000"); switch (data.rank) { case 1: //sperm.spriteName = "sperm gold"; BackgroundBronze.SetActive(false); BackgroundGold.SetActive(true); BackgroundSilver.SetActive(false); BackgroundDefault.SetActive(false); break; case 2: //sperm.spriteName = "sperm silver"; BackgroundBronze.SetActive(false); BackgroundGold.SetActive(false); BackgroundSilver.SetActive(true); BackgroundDefault.SetActive(false); break; case 3: //sperm.spriteName = "sperm bronze"; BackgroundBronze.SetActive(true); BackgroundGold.SetActive(false); BackgroundSilver.SetActive(false); BackgroundDefault.SetActive(false); break; default: //sperm.spriteName = "standard sperm"; BackgroundBronze.SetActive(false); BackgroundGold.SetActive(false); BackgroundSilver.SetActive(false); BackgroundDefault.SetActive(true); break; } //sperm.Init(); if (IsLocalPlayer) { //background.spriteName = "ScoresPlayerBg"; SetLabelColors(myNameColor, myInfoColor); } else { //background.spriteName = "ScoresOthersBg"; SetLabelColors(theirNameColor, theirInfoColor); } SocialManager.Instance.GetFacebookProfilePicture(data.user.id, SocialManager.ProfilePicSettings.square, (isSuccessful, textureObject) => { if (isSuccessful && avatar != null) { avatar.texture = textureObject; } }); } void SetLabelColors(Color nameColor, Color infoColor) { playerName.color = nameColor; rank.color = score.color = infoColor; } public bool IsLocalPlayer { get { return _scoreData.user.id == SocialManager.Instance.userID; } } #if ADMIN_BUILD void OnClick() { AVDebug.Log("Selected player "+_scoreData.user.name+ " " +_scoreData.user.surname+" with facebook Id "+_scoreData.user.id); RecordingManager.Instance.selectedFacebookId = _scoreData.user.id; } #endif }