You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nesrak1 edited this page Sep 23, 2023
·
2 revisions
Assuming you've installed the Texture nuget plugin, and some kind of image library like ImageSharp or System.Drawing, extracting textures is decently easy. Since it's open to any image library, it's a little more complicated than just "save to png", but it's easier than doing it all by hand. The decoder code is provided by AssetRipper's texture decoder library.
varam=newAssetsManager();am.LoadClassPackage("classdata.tpk");varfileInst=am.LoadAssetsFile("sharedassets0.assets",false);am.LoadClassDatabaseFromPackage(fileInst.file.Metadata.UnityVersion);vartextureInf=fileInst.file.GetAssetInfo(12345);vartextureBase=am.GetBaseField(fileInst,textureInf);vartexture=TextureFile.ReadTextureFile(textureBase);// load base field into helper classvartextureBgraRaw=texture.GetTextureData(fileInst);// get the raw bgra32 datavartextureImage=Image.LoadPixelData<Bgra32>(textureBgraRaw,texture.m_Width,texture.m_Height);// use imagesharp to convert to imagetextureImage.Mutate(i =>i.Flip(FlipMode.Vertical));// flip on x-axis (all textures in unity are stored flipped like this)textureImage.SaveAsPng("texture.png");