• Unity
  • Obtaining spine atlases

Hi all.
Spine atlases take up a lot of space in a project.
They need to be constantly compressed, but sometimes this is forgotten.
It would be desirable to write the utility for compression.

The question is, is it possible to get atlases when importing into a project, when unpacking files exported from spine?


I can shove them into 1 folder, and through AssetPostproces compress everything that is in this folder. But this option drives into the framework, I would like to get all the spine animation atlases and compress them on a mouse click in the editor window.

Related Discussions
...

Sorry this is not an answer to your question, but let me make sure your question first. Since you have asked several questions in the past about the spine-unity runtime, I assume you are referring to automatically compressing textures when importing skeleton files into Unity. Is it correct that the editor you mention below is the Unity editor?

I would like to get all the spine animation atlases and compress them on a mouse click in the editor window.

If so, I will move this thread to Unity (viewforum.php?f=12).

Yes, you got it right.


I managed to make automatic compression on import.
So it is entered into a separate JSON file.
Thanks to which, at any time, all imported animation atlases can be compressed by any available method for 2 platforms.

The only problem is that it must be stored in 1 folder.

TheZero a écrit

The question is, is it possible to get atlases when importing into a project, when unpacking files exported from spine?

I'm afraid I don't understand this line, could you please describe what you mean by this? Do you mean that you would like to use a post-process hook that is called when an atlas texture has been imported in Unity?

TheZero a écrit

I would like to get all the spine animation atlases and compress them on a mouse click in the editor window.

Could you please describe what exactly you mean by the line above? If you mean that you want to create a custom Unity Editor window (via editor scripting) where you have a button to gather all Spine atlas assets and call some compression methods on them: you could by script gather all assets of type SkeletonDataAsset, access the atlas assets (or through all assets of type SpineAtlasAsset directly), and then iterate over all Materials that are assigned at the AtlasAsset. Then at each Material, apply your compression method to the texture assigned at the material.

One thing you could always do is modify the spine-unity source code accordingly to apply your own custom code in required places, which however would require re-applying the changes after runtime updates.

In short.
All I need is to get the spine animation atlas.

When unloading an animation from a spine, it creates files for us.

1 - atlas
2 - json
3 - number, atlases - textures in png format (or selected in the environment)


I can track texture imports in the project.

But then all the textures will get there, which I do not need.

Is there a way to get png objects with animation textures (skins) without affecting your logic
when importing them into a project


Let's say I can somehow see which textures are bound to SpinAtlasAsset.

Then take their path and use it to cover the texture format with the quality I need


Sorry for my English.

I don't really know him


Poking around a bit in your code.

I understand how it tracks files related specifically to the spine atlas.

The only thing I do not understand is why these lines.

Is it true to say.
That in these lines it checks whether there is a file and if it has some settings, then we do nothing.
If there are no settings, then we set them ourselves?

A
"SpineEditorUtilities.Preferences.setTextureImporter Settings"

Somewhere it tracks whether the settings are set to it or not.

If this is the case, then I want to change the settings anyway.
So I just don't need them?

Except
"textureIsUninitialized"

As I mentioned above you could gather all SpineAtlasAsset and iterate through the materials and their process their main texture. The following code should basically do what you want, although not tested:

string[] guids = UnityEditor.AssetDatabase.FindAssets("t:SpineAtlasAsset");
foreach (string guid in guids) {
   string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guid);
   if (!string.IsNullOrEmpty(path)) {
      SpineAtlasAsset atlasAsset = UnityEditor.AssetDatabase.LoadAssetAtPath<SpineAtlasAsset>(path);
      foreach (Material atlasMaterial in atlasAsset.Materials) {
         CompressTexture(atlasMaterial.mainTexture);
      }
   }
}
TheZero a écrit

Poking around a bit in your code.

I understand how it tracks files related specifically to the spine atlas.

The only thing I do not understand is why these lines.

The code section you shared first tests whether the texture is imported for the first time (textureIsUninitialized) and if default import settings should be applied, as set in the Spine Preferences. If a reference texture settings asset is set in the Spine Preferences, it is applied (see the else branch), if it is not (and is null) some default settings will be applied instead (SetDefaultTextureSettings).

In general you likely don't want to only compress a texture when it's first imported (textureIsUninitialized) but every time it changes, so you don't want to add anything inside the whole if-branch at all. Instead you could add your lines of code to process (compress, if not already compressed) the texture below it.

Thanks, in general, I got something like texture compression when importing.

And when you open the dialog box, it checks if there are any other spine files in the project similar to your code above.

If there is, then add them to Json
And then if we need to compress all files, just select the format, quality and click on the button.


The question is, why don't you expand the spine settings by adding the ability to change the import format for different platforms?

Or does this exist and I wrote 1 part of the instrument in vain?

TheZero a écrit

Thanks, in general, I got something like texture compression when importing.

And when you open the dialog box, it checks if there are any other spine files in the project similar to your code above.

If there is, then add them to Json
And then if we need to compress all files, just select the format, quality and click on the button.

If you already have a setup for processing Spine assets in place, I don't understand why and what exactly you are asking. In general please always share with us what problems you already have solved, and what problems are remaining. Please describe that as precisely as possible, otherwise we waste a lot of time writing back and forth and suggesting a solution to a problem that you don't have in the first place.

TheZero a écrit

The question is, why don't you expand the spine settings by adding the ability to change the import format for different platforms?

Or does this exist and I wrote 1 part of the instrument in vain?

The Preset asset that can be assigned at the Spine Preferences property Atlas Texture Settings can hold normal texture preset settings for any target platform. That is, unless you are using a very old Unity version before Preset assets were introduced, then the same Spine Preferences property accepts a single Texture asset instead of a preset.

17 jours plus tard

Sorry it's been so long, but I'm only writing now.

In the process of correspondence, I found the answers I needed for myself.

The task was this. And thanks to you, I solved it.

When importing a spine package, it must set compression for all platforms.

Registered in the config.

In addition to this, it was necessary to get a list of all animations in the project and also compress them if they have an inappropriate method.

There should also be functionality if we want to choose our own compression method for some of the platforms and reap absolutely all spine atlases.

1 button.

All this was done thanks to this dialogue. Thank you

Here's what happened

This is not the final version yet because it is not very convenient

Very glad to hear that you're figured it out, thanks for getting back to us!