ScoreAvatar.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using UnityEngine;
  2. using System.Collections;
  3. using TMPro;
  4. using UnityEngine.UI;
  5. public class ScoreAvatar : MonoBehaviour
  6. {
  7. public TextMeshProUGUI playerName;
  8. public TextMeshProUGUI rank;
  9. public TextMeshProUGUI score;
  10. public RawImage avatar;
  11. public TextMeshProUGUI background;
  12. //public ReadTextureCoordinatesFromNGUI sperm;
  13. public Color myNameColor;
  14. public Color myInfoColor;
  15. public Color theirNameColor;
  16. public Color theirInfoColor;
  17. public GameObject BackgroundBronze;
  18. public GameObject BackgroundGold;
  19. public GameObject BackgroundSilver;
  20. public GameObject BackgroundDefault;
  21. public Texture2D anonymousAvatar;
  22. Score _scoreData;
  23. void OnDisable()
  24. {
  25. //reset the avatar's texture since this is a pooled object
  26. avatar.texture = anonymousAvatar;
  27. _scoreData = null;
  28. }
  29. public void SetData(Score data)
  30. {
  31. _scoreData = data;
  32. playerName.text = data.user.name+" "+data.user.surname;
  33. if(data.rank > 0)
  34. {
  35. rank.text = "#"+data.rank.ToString();
  36. } else
  37. {
  38. rank.text = "";
  39. }
  40. score.text = data.score.ToString("0,000");
  41. switch (data.rank)
  42. {
  43. case 1:
  44. //sperm.spriteName = "sperm gold";
  45. BackgroundBronze.SetActive(false);
  46. BackgroundGold.SetActive(true);
  47. BackgroundSilver.SetActive(false);
  48. BackgroundDefault.SetActive(false);
  49. break;
  50. case 2:
  51. //sperm.spriteName = "sperm silver";
  52. BackgroundBronze.SetActive(false);
  53. BackgroundGold.SetActive(false);
  54. BackgroundSilver.SetActive(true);
  55. BackgroundDefault.SetActive(false);
  56. break;
  57. case 3:
  58. //sperm.spriteName = "sperm bronze";
  59. BackgroundBronze.SetActive(true);
  60. BackgroundGold.SetActive(false);
  61. BackgroundSilver.SetActive(false);
  62. BackgroundDefault.SetActive(false);
  63. break;
  64. default:
  65. //sperm.spriteName = "standard sperm";
  66. BackgroundBronze.SetActive(false);
  67. BackgroundGold.SetActive(false);
  68. BackgroundSilver.SetActive(false);
  69. BackgroundDefault.SetActive(true);
  70. break;
  71. }
  72. //sperm.Init();
  73. if (IsLocalPlayer)
  74. {
  75. //background.spriteName = "ScoresPlayerBg";
  76. SetLabelColors(myNameColor, myInfoColor);
  77. } else
  78. {
  79. //background.spriteName = "ScoresOthersBg";
  80. SetLabelColors(theirNameColor, theirInfoColor);
  81. }
  82. SocialManager.Instance.GetFacebookProfilePicture(data.user.id, SocialManager.ProfilePicSettings.square, (isSuccessful, textureObject) =>
  83. {
  84. if (isSuccessful && avatar != null)
  85. {
  86. avatar.texture = textureObject;
  87. }
  88. });
  89. }
  90. void SetLabelColors(Color nameColor, Color infoColor)
  91. {
  92. playerName.color = nameColor;
  93. rank.color = score.color = infoColor;
  94. }
  95. public bool IsLocalPlayer
  96. {
  97. get
  98. {
  99. return _scoreData.user.id == SocialManager.Instance.userID;
  100. }
  101. }
  102. #if ADMIN_BUILD
  103. void OnClick()
  104. {
  105. AVDebug.Log("Selected player "+_scoreData.user.name+ " " +_scoreData.user.surname+" with facebook Id "+_scoreData.user.id);
  106. RecordingManager.Instance.selectedFacebookId = _scoreData.user.id;
  107. }
  108. #endif
  109. }