Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // UI.cpp
- namespace UI {
- bool UI::LoadSprite::create(){
- cancellationTokenSource = il2U::NewUnsafe(il2U::GetClassFromName("System.Threading", "CancellationTokenSource"));
- if(!il2U::RunMethod(&cancellationToken, cancellationTokenSource, "get_Token")){
- log(DEBUG, "Failed to get cancellationToken");
- return false;
- }
- if(!il2U::RunMethod(&recievedTexture2D, nullptr, il2U::FindMethod("", "MediaAsyncLoader", "LoadImageAsync", 2), il2U::createcsstr(path), cancellationToken)){
- log(DEBUG, "Failed to get Texture2D from LoadImageAsync");
- return false;
- }
- rectPosition = {0.0, 0.0};
- rectSize = {128.0, 128.0};
- rect = il2U::NewUnsafe(il2U::GetClassFromName("UnityEngine", "Rect"), &rectPosition, &rectSize);
- pixelsPerUnit = 10.0f;
- pivot = {0.0, 0.0};
- loadedSprite = il2U::NewUnsafe(il2U::GetClassFromName("UnityEngine", "Sprite"), &rect, &pivot, &pixelsPerUnit);
- return true;
- }
- }
- // UI.hpp
- namespace UI {
- class LoadSprite : public Il2CppObject {
- private:
- Il2CppObject* recievedTexture2D;
- Il2CppObject* cancellationTokenSource;
- Il2CppObject* cancellationToken;
- Il2CppObject* rect;
- Vector2 rectPosition;
- Vector2 rectSize;
- Vector2 pivot;
- float pixelsPerUnit;
- public:
- std::string path = "";
- Il2CppObject* loadedSprite;
- bool create();
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement