• RuntimesUnity
  • 关于Spine-Unity的换装方式的性能问题

你好,我最近在unity编辑器里使用spine对象来制作角色,我想在角色工程文件里给每个服装添加一个skin并导出为unity可读的文件,然后通过SetSkin这个API来切换角色服装。这时我想到了一个问题,比如所有服装(100左右件)合并到一个spine工程文件后导出的spine对象是否会影响游戏性能?

    Related Discussions
    ...

    你好,

    关于在Spine-Unity中使用换装功能的性能问题,以下是一些关键点:

    1. 资源加载:如果你有大量的服装选项(如100件),建议不要一次性加载所有的图片。可以在运行时只加载当前使用的图片,并通过运行时重新打包(Runtime Repacking)来组织纹理。详细信息可以参考Combining Skins部分。

    2. 性能测试:为了确定性能是否会受到影响,建议在目标设备上进行测试。你可以下载spine-unity runtime进行评估,并使用其中的示例骨架进行测试。下载链接:spine-unity Download

    3. 优化措施:常见的性能优化措施包括减少材质切换和绘制调用。你可以通过合并皮肤或附件到单一的纹理来减少这些操作。更多信息可以参考spine-unity Performance部分。

    4. 动态重载:如果在运行时频繁更换皮肤,可能会导致性能下降。可以考虑在非关键时间点进行这些操作,或者分帧处理多个重载操作。

    5. 示例项目:spine-unity runtime中包含一些示例项目,如“Mix and Match Skins”,可以帮助你了解如何在运行时组合多个皮肤。

    总的来说,合理的资源管理和优化措施可以有效减少性能影响。

    kodoly7 By default, the SkeletonDataAsset references the AtlasAsset, which references its atlas pages as Materials, where each Material references the atlas page texture. So if you exported all atlas pages normally as a single AtlasAsset, all pages will be loaded as soon as your skeleton's SkeletonDataAsset is loaded.

    If you want to load atlas texture pages on-demand, you need to make sure to not include direct references and instead use Unity means of delayed-loading, such as Addressables. You can use a build script to clear any direct references to the delayed-loaded resources and use a loader script to load and assign references at runtime when actually used.

    To make it easy, we provide convenient modules. To use them, download the two packages Spine On Demand Loading and Spine Addressables. For more information on how to install the extension packages, please see the documentation:
    https://zh.esotericsoftware.com/spine-unity#%E5%8F%AF%E9%80%89%E7%9A%84UPM%E6%8F%92%E4%BB%B6%E5%8C%85

    Also check the Spine Addressables documentation:.
    EsotericSoftware/spine-runtimestree/4.2/spine-unity/Modules/com.esotericsoftware.spine.addressables/Documentation

    The spine.addressables package utilizes Unity's Addressables package, which will be installed automatically through dependencies if not already installed in your project.

      Misaki 非常感谢您的回复,我准备下班回家尝试安装这两个包并使用

      Misaki 您好,在您的回复的最后一段里给出的documentation里提到使用这个包的第一步是将将original high-resolution target material textures设置为Addressables,我想问一下original high-resolution target material textures囊括spine工程导出后生成的unity material文件和spine对象文理贴图的png文件两者?还是只囊括其中的material一者或者png文件一者?

        kodoly7 I'm afraid I didn't understand your question very well, perhaps because the machine translation didn't work very well. It would be easier if you actually tried it, but just in case, here are the steps to set it up for your reference:

        1. Declare your original high-resolution target Material textures as addressable.

        2. Select the SpineAtlasAsset, right-click the SpineAtlasAsset Inspector heading and select Add Addressables Loader.

          This generates an AddressableTextureLoader asset. This asset provides configuration parameters and sets up low-resolution placeholder textures which are automatically assigned in a pre-build step when building your game executable.

        3. Build your Addressables content as usual.

          Misaki 您好,我在导入spine addressable这个包时unity报错了:
          An error occurred while resolving packages:
          Package com.esotericsoftware.spine.addressables@file😃:\UnityProjects\Packages\com.esotericsoftware.spine.addressables has invalid dependencies or related test packages:
          com.esotericsoftware.spine.on-demand-loading (dependency): Package [com.esotericsoftware.spine.on-demand-loading@4.2.0] cannot be found
          com.esotericsoftware.spine.spine-unity (dependency): Package [com.esotericsoftware.spine.spine-unity@4.2.21] cannot be found

          @kodoly7 You need to install com.esotericsoftware.spine.on-demand-loading#4.2 first, before installing the com.esotericsoftware.spine.addressables package. So add the following package via git URL:
          https://github.com/EsotericSoftware/spine-runtimes.git?path=spine-unity/Modules/com.esotericsoftware.spine.on-demand-loading#4.2

          A description can also be found here:
          EsotericSoftware/spine-runtimes1890

            Harald 我先导入了on_demand-loading的数据包,提示没有安装spine-unity4.2.21这个包,可是我已经安装了spine运行时,而且是4.2版本的spine 运行时,报错数据里提到的spine-unity是运行时之外的包吗?
            以下是报错内容:
            An error occurred while resolving packages:
            Package com.esotericsoftware.spine.on-demand-loading@file😃:\UnityProjects\Packages\com.esotericsoftware.spine.on-demand-loading has invalid dependencies or related test packages:
            com.esotericsoftware.spine.spine-unity (dependency): Package [com.esotericsoftware.spine.spine-unity@4.2.21] cannot be found

            A re-import of the project may be required to fix the issue or a manual modification of D:/UnityProjects/Packages/manifest.json file.

            Harald 这是我的spine runtime version:
            Package version: spine-unity-4.2-2024-08-08.unitypackage

            @kodoly7 Thanks for the additional info. The experimental on-demand-loading package currently has a dependency to the spine-unity UPM package, which is not detected by the Unity Package Manager when installed as unitypackage. So the solution would be to either uninstall the spine-unity package from the unitypackage and re-install it via the Unity Package Manager (spine-csharp and spine-unity), as described here.

            An alternative would be to remove the dependency line

            "com.esotericsoftware.spine.spine-unity": "4.2.21"

            from the package.json inside the com.esotericsoftware.spine.on-demand-loading package directory. To be able to modify the package.json file, you might need to clone the spine-runtimes git repository to a local directory, and then modify the file.

            We're sorry for the inconvenience!

              Harald 感谢各位的帮助,我的问题已经成功解决了!