Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace Unity.PlasticSCM.Editor.UI.Avatar
  4. {
  5. internal static class AvatarImages
  6. {
  7. internal static void Dispose()
  8. {
  9. foreach (Texture2D image in mAvatars.Values)
  10. UnityEngine.Object.DestroyImmediate(image, true);
  11. mAvatars.Clear();
  12. }
  13. internal static bool HasGravatar(string email)
  14. {
  15. return mAvatars.ContainsKey(email);
  16. }
  17. internal static void AddGravatar(string email, Texture2D image)
  18. {
  19. if (mAvatars.ContainsKey(email))
  20. return;
  21. mAvatars.Add(email, image);
  22. }
  23. internal static void UpdateGravatar(string email, byte[] rawImage)
  24. {
  25. if (!mAvatars.ContainsKey(email))
  26. return;
  27. Texture2D result = GetTexture(rawImage);
  28. mAvatars[email] = result;
  29. }
  30. internal static Texture2D GetAvatar(string email)
  31. {
  32. Texture2D image = GetGravatarImage(email);
  33. if (image != null)
  34. return image;
  35. return Images.GetEmptyGravatar();
  36. }
  37. static Texture2D GetGravatarImage(string email)
  38. {
  39. Texture2D avatar;
  40. mAvatars.TryGetValue(email, out avatar);
  41. return avatar;
  42. }
  43. static Texture2D GetTexture(byte[] rawImage)
  44. {
  45. Texture2D result = Images.GetNewTextureFromBytes(32, 32, rawImage);
  46. Texture2D maskImage = ApplyCircleMask.For(result);
  47. UnityEngine.Object.DestroyImmediate(result, true);
  48. return maskImage;
  49. }
  50. static readonly Dictionary<string, Texture2D> mAvatars =
  51. new Dictionary<string, Texture2D>();
  52. }
  53. }