Upgrading from v2.0.9, confused by changes #159
-
|
Thank you for the fantastic work you have done with this library. I have just upgraded from version 2.0.9 to latest (3.0.4) and some of the breaking changes between versions are confusing me. First and most importantly is that I had some code similar to this example in the documentation, but GetTextureData no longer exists. My old code looked like this: As near as I can figure out, the equivalent in the new version would be this (FillPictureData being the main change): ...but the textureData that comes back (and is filled in as textureFile.PictureData) is too small. For a 1024x1024 ARGB image, I am only given a 1048576 byte array - which is too small, there should be 1048576 pixels, but 4194304 bytes (4 bytes per pixel). I tried "hacking" the size by manually multiplying m_streamData.size *= 4 before calling FillPictureData, but then the contents of the returned array don't look right anyway (apparently random data); perhaps m_streamData.offset is wrong too? Am I using FillPictureData correctly, as a replacement for the old GetPictureData? What else might I be doing wrong here? Or is this a bug? Secondly (let me know if you want me to break this into a separate discussion), and less importantly: in the old version I could do this to find a sprite asset with the given idName (of type string):
In the new version that overload is gone. Instead I am having to do this: ...and then manually search through sprites myself, looking for one with the matching idName. It seems to work, but it is much clunkier, and I'm not sure whether I'm missing something. Is there a better way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I forgot to update the docs, sorry about that. The purpose of this refactor (which, as a user of it myself, I'm not super happy about the design either) was to move all of the texture reading and writing code away from UABEA and into AssetsTools.NET. In particular, I wanted support for both decompression in C# and compression from C# (for limited formats) and the rest from C++. I wanted as much code to be C# because that's more code that works cross platform without any changes. The C++ was included because many texture encoding libraries only exist in C++. To support all of that, to allow for more control over the process, and to more easily support png import/export, the texture library got a bunch of changes.
Texture2D assets in Unity can store data in two ways. One is through a field called However, the data this returns is still the compressed data. Depending on how you are "showing the image in the application", there are different options.
The explanation to this one is a bit complex, but the TLDR is that the old way was unreliable and hacky. It may have worked for some use cases, but it was not guaranteed to work in all use cases. I think UABE's AssetsTools version of this function was also not very reliable. The old way this method worked was by checking if an asset matched a list of hardcoded class IDs and then reading the string at the start of the asset if it matched. There were two exceptions: MonoBehaviours don't store their name in their own asset most of the time, and GameObjects don't store their name at the beginning of the asset. These two assets had hardcoded handlers, but they only worked if their formats never changed (editor versions, custom version, etc. would break this method). To make this more resilient to changes while still being performant, a few new features had to be added.
This is something I was trying to avoid. Technically this works, but it's slow because it has to deserialize all assets you want to look through. Yes, it's only sprites in this case, but in other cases you may want to look through assets of all types. You're wasting time by reading whole assets to get the name at the very start. Recently, a new class was added for partial reading, AssetTypeValueIterator. It doesn't allocate memory for each field it reads, it just passes you field names and you can read it if you want or skip it. This is useful for name reading because you can keeping requesting fields until you reach In UABEANext, I recently added support for using the iterator to read names. The code is here. It supports multithreaded reading, checking if GameObjects or MonoBehaviours meet the format we're expecting and using a more optimal version instead, reading names through replaced assets, and length limiting in case the file is corrupt or custom. Then plan is for this code to move to AssetsTools.NET, but that hasn't happened yet. If you need it right now, you could adapt this code to plain AssetsTools.NET by replacing If you only care about reading sprite assets and you know the format isn't changing (or you're targeting a specific game), you can use the old code which goes something like this (untested): lock (fileInst.LockReader)
{
var reader = fileInst.file.Reader;
reader.Position = info.GetAbsoluteByteOffset(fileInst.file);
return reader.ReadCountStringInt32();
} |
Beta Was this translation helpful? Give feedback.
I forgot to update the docs, sorry about that. The purpose of this refactor (which, as a user of it myself, I'm not super happy about the design either) was to move all of the texture reading and writing code away from UABEA and into AssetsTools.NET. In particular, I wanted support for both decompression in C# and compression from C# (for limited formats) and the rest from C++. I wanted as much code to be C# because that's more code that works cross platform without any changes. The C++ was included because many texture encoding libraries only exist in C++. To support all of that, to allow for more control over the process, and to more easily support png …