• 中文
  • 如何正确在运行时更换网格中的图片 How to properly replace pictures in a grid

Related Discussions
...

我希望在unity运行时更换插槽中的图片,但如果插槽的图片启用了mesh功能,会导致显示了图集中不属于它的部分。
请问有办法正确显示吗?

Hi,I'd like to replace the image in the slot while unity is running, but if the slot's image has mesh enabled, it will result in showing parts of the atlas that don't belong to it.
Is there a way to display it correctly?

您在 Unity 运行时使用什么代码替换插槽中的附件?
What code are you using to replace the attachment at the slot at runtime in Unity?

目标目标插槽设置为 Mesh 类型,还是普通区域附件?
源附件是否最初分配在 Mesh 类型的插槽中?
Is the target destination slot set to type Mesh, or a normal region attachment?
Was the source attachment originally assigned at a slot of type Mesh?

Harald a écrit

您在 Unity 运行时使用什么代码替换插槽中的附件?
What code are you using to replace the attachment at the slot at runtime in Unity?

目标目标插槽设置为 Mesh 类型,还是普通区域附件?
源附件是否最初分配在 Mesh 类型的插槽中?
Is the target destination slot set to type Mesh, or a normal region attachment?
Was the source attachment originally assigned at a slot of type Mesh?

感谢您的回复。
Thank you for your reply

代码我使用了 Spine Examples 中的 AtlasRegionAttacher 类。
For the code I used the AtlasRegionAttacher class from Spine Examples.

在spine编辑器中,目标插槽设置为 Mesh 类型。
In the spine editor, the target slot is set to Mesh type.

附件最初并未分配到插槽中。
The attachment was not originally assigned to the slot。

感谢您提供更多信息。

看起来问题在于您的目标网格更大,包含很多空白空间,而源图集图像在其下方不包含所需的相同透明空间(称为空白)。

Spine 中使用的输入附件图像(红色的)是否包含其下方的透明空白,是否与蓝色的图像大小相同?如果不是,请注意,您需要使要在 Mesh 上使用的所有图像大小相同。

如果它们最初具有相同的大小并且它包含其下方的透明空白区域,那么当附件图像被打包到 atlas 纹理时就会出现问题。如果输入图像包含大量未使用但未在网格中使用的透明空间,则 打包期间的 Strip Whitespace X/Y 选项将删除这个未使用的空白。因此,当启用 Strip Whitespace X/Y 时,您需要在 Mesh 上使用一次图像,以声明确实使用了透明区域。

如果您在 Mesh 上分配了图像,并且打包仍然删除了空格,那么您可能是从命令行打包了图集,那么您需要使用 `


project <Path>`[/url] (项目路径以确定网格使用哪些图像..

您还可以在图集导出期间禁用 Strip Whitespace X/Y 以避免透明空白区域被切掉。这可能是最简单的解决方案,但它牺牲了一些图集空间。


Thank you for the additional information.

It looks like the problem is that your target Mesh is larger, containing a lot of empty space, while the source atlas image does not contain the required same transparent space (callend whitespace) below it.

Does the input attachment image (the red one) used in Spine contain the transparent whitespace below it, is it of the same image size as the blue one? If not, please note that you need to make all images that you want to use at a Mesh the same size.

If they are originally of the same size and it contains the transparent whitespace area below it, then the problem occurs when the attachment images are packed to the atlas texture. If the input image contains a lot of transparent space that is not used but it is not used at a mesh, the Strip Whitespace X/Y option during packing will remove this unused whitespace. So when having Strip Whitespace X/Y enabled, you would need to use the image at a Mesh once, to declare that the transparent areas are indeed used.

If you have the image assigned at a Mesh, and packing still removes the whitespace, maybe you packed the atlas from the command line, then you need to use `


project <Path>`[/url] (Path to a project to determine which images are used by meshes..

You could also disable Strip Whitespace X/Y during atlas export to avoid the transparent whitespace areas from being cut away. This is probably the easiest solution, but it sacrifices some atlas space.