Discord integration for Gamecraft
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.

ImageManager.cs 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Runtime.InteropServices;
  3. #if UNITY_EDITOR || UNITY_STANDALONE
  4. using UnityEngine;
  5. #endif
  6. namespace Discord
  7. {
  8. public partial struct ImageHandle
  9. {
  10. static public ImageHandle User(Int64 id)
  11. {
  12. return User(id, 128);
  13. }
  14. static public ImageHandle User(Int64 id, UInt32 size)
  15. {
  16. return new ImageHandle
  17. {
  18. Type = ImageType.User,
  19. Id = id,
  20. Size = size,
  21. };
  22. }
  23. }
  24. public partial class ImageManager
  25. {
  26. public void Fetch(ImageHandle handle, FetchHandler callback)
  27. {
  28. Fetch(handle, false, callback);
  29. }
  30. public byte[] GetData(ImageHandle handle)
  31. {
  32. var dimensions = GetDimensions(handle);
  33. var data = new byte[dimensions.Width * dimensions.Height * 4];
  34. GetData(handle, data);
  35. return data;
  36. }
  37. #if UNITY_EDITOR || UNITY_STANDALONE
  38. public Texture2D GetTexture(ImageHandle handle)
  39. {
  40. var dimensions = GetDimensions(handle);
  41. var texture = new Texture2D((int)dimensions.Width, (int)dimensions.Height, TextureFormat.RGBA32, false, true);
  42. texture.LoadRawTextureData(GetData(handle));
  43. texture.Apply();
  44. return texture;
  45. }
  46. #endif
  47. }
  48. }