This repository has moved! Please check out the latest version at the new location https://git.exmods.org/NGnius/GameSDKcraft
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

54 lines
1.3KB

  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. }