Advertisement
Guest User

LoadSprite

a guest
Feb 16th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. // UI.cpp
  2. namespace UI {
  3.  
  4.   bool UI::LoadSprite::create(){
  5.     cancellationTokenSource = il2U::NewUnsafe(il2U::GetClassFromName("System.Threading", "CancellationTokenSource"));
  6.     if(!il2U::RunMethod(&cancellationToken, cancellationTokenSource, "get_Token")){
  7.       log(DEBUG, "Failed to get cancellationToken");
  8.       return false;
  9.     }
  10.  
  11.     if(!il2U::RunMethod(&recievedTexture2D, nullptr, il2U::FindMethod("", "MediaAsyncLoader", "LoadImageAsync", 2), il2U::createcsstr(path), cancellationToken)){
  12.       log(DEBUG, "Failed to get Texture2D from LoadImageAsync");
  13.       return false;
  14.     }
  15.     rectPosition = {0.0, 0.0};
  16.     rectSize     = {128.0, 128.0};
  17.     rect = il2U::NewUnsafe(il2U::GetClassFromName("UnityEngine", "Rect"), &rectPosition, &rectSize);
  18.     pixelsPerUnit = 10.0f;
  19.     pivot = {0.0, 0.0};
  20.     loadedSprite = il2U::NewUnsafe(il2U::GetClassFromName("UnityEngine", "Sprite"), &rect, &pivot, &pixelsPerUnit);
  21.     return true;
  22.    }
  23. }
  24.  
  25. // UI.hpp
  26.  
  27. namespace UI {
  28.  
  29.     class LoadSprite : public Il2CppObject {
  30.         private:
  31.             Il2CppObject* recievedTexture2D;
  32.             Il2CppObject* cancellationTokenSource;
  33.             Il2CppObject* cancellationToken;
  34.             Il2CppObject* rect;
  35.             Vector2       rectPosition;
  36.             Vector2       rectSize;
  37.             Vector2       pivot;
  38.             float         pixelsPerUnit;
  39.         public:
  40.             std::string path = "";
  41.             Il2CppObject* loadedSprite;
  42.             bool create();
  43.     };
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement