我在Unity中制作spine动画。我定义了4个slots,attachments中 每一个slots 都关联了很多图片。我通过替换attachments里面的图片实现换装的效果。 我有一个问题,比如我有 头,身体,武器,头发 四个slots,如果我更换身体上面的衣服,如果才能匹配上不同大小的衣服?我现在通过范例,可以实现换装,但是因为换装图片尺寸的问题,换装之后,位置没有能够匹配成功。比如 我想实现匕首和长茅换装,是否保证图片的大小完全一样才可以?

"skins": [
	{
		"name": "default",
		"attachments": {
			"head": {
				"playerBase_head_1": { "x": -111, "y": 535.5, "width": 292, "height": 437 },
				"playerBase_head_2": { "x": -111, "y": 531.5, "width": 292, "height": 445 },
				"playerBase_head_3": { "x": -111, "y": 533, "width": 292, "height": 442 },
				"playerBase_head_4": { "x": -114, "y": 533, "width": 292, "height": 424 },
				"playerBase_head_5": { "x": -114.5, "y": 518.5, "width": 293, "height": 429 },
				"playerBase_head_6": { "x": -270.5, "y": 556, "width": 293, "height": 420 },
				"playerBase_head_7": { "x": -63, "y": 527, "width": 302, "height": 416 },
				"playerBase_head_8": { "x": -42, "y": 519.5, "width": 310, "height": 445 },
				"playerBase_head_9": { "x": -28.5, "y": 527.5, "width": 317, "height": 427 },
				"playerBase_head_10": { "x": 8.5, "y": 529.5, "width": 317, "height": 423 },
				"playerBase_head_11": { "x": 63.5, "y": 527.5, "width": 317, "height": 427 },
				"playerBase_head_12": { "x": 134.5, "y": 531, "width": 317, "height": 420 },
				"playerBase_head_13": { "x": 45.5, "y": 543, "width": 349, "height": 404 },
				"playerBase_head_14": { "x": -154, "y": 515, "width": 332, "height": 434 },
				"playerBase_head_15": { "x": -181.5, "y": 545, "width": 423, "height": 436 },
				"playerBase_head_16": { "x": -181.5, "y": 545.5, "width": 423, "height": 435 },
				"playerBase_head_17": { "x": 45.5, "y": 543, "width": 349, "height": 404 },
				"playerBase_head_18": { "x": 44, "y": 543, "width": 352, "height": 404 }
			},
			"hat": {
				"playerBase_hat_1": { "x": -115, "y": 601.5, "width": 352, "height": 419 },
				"playerBase_hat_2": { "x": -115, "y": 601.5, "width": 352, "height": 419 },
				"playerBase_hat_3": { "x": -115, "y": 601.5, "width": 352, "height": 419 },
				"playerBase_hat_4": { "x": -118, "y": 592.5, "width": 352, "height": 419 },
				"playerBase_hat_5": { "x": -118.5, "y": 580.5, "width": 351, "height": 419 },
				"playerBase_hat_6": { "x": -274.5, "y": 613.5, "width": 351, "height": 419 },
				"playerBase_hat_7": { "x": -51.5, "y": 575.5, "width": 347, "height": 421 },
				"playerBase_hat_8": { "x": -23.5, "y": 578.5, "width": 345, "height": 421 },
				"playerBase_hat_9": { "x": -4, "y": 576, "width": 342, "height": 420 },
				"playerBase_hat_10": { "x": 33, "y": 576, "width": 342, "height": 420 },
				"playerBase_hat_11": { "x": 88, "y": 576, "width": 342, "height": 420 },
				"playerBase_hat_12": { "x": 159, "y": 576, "width": 342, "height": 420 },
				"playerBase_hat_13": { "x": 111.5, "y": 625.5, "width": 371, "height": 383 },
				"playerBase_hat_14": { "x": -183.5, "y": 590, "width": 353, "height": 394 },
				"playerBase_hat_15": { "x": -222.5, "y": 676, "width": 373, "height": 280 },
				"playerBase_hat_16": { "x": -222.5, "y": 676, "width": 373, "height": 280 },
				"playerBase_hat_17": { "x": 111.5, "y": 625.5, "width": 371, "height": 383 },
				"playerBase_hat_18": { "x": 111.5, "y": 625.5, "width": 371, "height": 383 }
			}
			
			
		}
	},
	{
		"name": "change",
		"attachments": {
			"cloth": {
				"playerBase_cloth_1": { "x": -132.5, "y": 202, "width": 863, "height": 406 },
				"playerBase_cloth_2": { "x": -86.5, "y": 233, "width": 955, "height": 468 },
				"playerBase_cloth_3": { "x": -83.5, "y": 316.5, "width": 853, "height": 635 },
				"playerBase_cloth_4": { "x": -76.5, "y": 326.5, "width": 829, "height": 655 },
				"playerBase_cloth_5": { "x": -66.5, "y": 335, "width": 809, "height": 672 },
				"playerBase_cloth_6": { "x": -276.5, "y": 261, "width": 755, "height": 524 },
				"playerBase_cloth_7": { "x": -126.5, "y": 190, "width": 875, "height": 382 },
				"playerBase_cloth_8": { "x": -115.5, "y": 190, "width": 875, "height": 382 },
				"playerBase_cloth_9": { "x": -109.5, "y": 190, "width": 875, "height": 382 },
				"playerBase_cloth_10": { "x": -72.5, "y": 190, "width": 875, "height": 382 },
				"playerBase_cloth_11": { "x": -17.5, "y": 190, "width": 875, "height": 382 },
				"playerBase_cloth_12": { "x": 53.5, "y": 190, "width": 875, "height": 382 },
				"playerBase_cloth_13": { "x": -93.5, "y": 200, "width": 863, "height": 402 },
				"playerBase_cloth_14": { "x": -108, "y": 188, "width": 824, "height": 444 },
				"playerBase_cloth_15": { "x": -85, "y": 167, "width": 806, "height": 472 },
				"playerBase_cloth_16": { "x": -85, "y": 167, "width": 806, "height": 472 },
				"playerBase_cloth_17": { "x": -93.5, "y": 200, "width": 863, "height": 402 },
				"playerBase_cloth_18": { "x": -93, "y": 200, "width": 864, "height": 402 }
			},
			"weapon": {
				"playerBase_weapon_1": { "x": -222, "y": 1, "width": 10, "height": 10 },
				"playerBase_weapon_2": { "x": 212.5, "y": 566.5, "width": 171, "height": 279 },
				"playerBase_weapon_3": { "x": 227, "y": 723.5, "width": 168, "height": 289 },
				"playerBase_weapon_4": { "x": 266.5, "y": 759.5, "width": 201, "height": 277 },
				"playerBase_weapon_5": { "x": 290.5, "y": 768, "width": 203, "height": 264 },
				"playerBase_weapon_6": { "x": -650.5, "y": 523.5, "width": 271, "height": 167 },
				"playerBase_weapon_7": { "x": -217, "y": 1, "width": 10, "height": 10 },
				"playerBase_weapon_8": { "x": -208, "y": 1, "width": 10, "height": 10 },
				"playerBase_weapon_9": { "x": -206, "y": 1, "width": 10, "height": 10 },
				"playerBase_weapon_10": { "x": -203.5, "y": 1, "width": 9, "height": 10 },
				"playerBase_weapon_11": { "x": -201, "y": 0.5, "width": 10, "height": 9 },
				"playerBase_weapon_12": { "x": -199, "y": 1, "width": 10, "height": 10 },
				"playerBase_weapon_13": { "x": -212.5, "y": 1, "width": 9, "height": 10 },
				"playerBase_weapon_14": { "x": -196, "y": 1, "width": 10, "height": 10 },
				"playerBase_weapon_15": { "x": -220, "y": 1, "width": 10, "height": 10 },
				"playerBase_weapon_16": { "x": -224, "y": 1, "width": 10, "height": 10 },
				"playerBase_weapon_17": { "x": -215, "y": 1, "width": 10, "height": 10 },
				"playerBase_weapon_18": { "x": -210, "y": 1, "width": 10, "height": 10 }
			}
		}
	}
],
    Related Discussions
    ...

    monight There are several ways to change the look of a character at runtime, such as replacing the texture atlas page itself, as you are trying to do, but you can also create new skins at runtime or use Sprites as a source to provide images for the skeleton and create new attachments and repack the texture atlas to include them. It would be easier to manage that way, because you don't have to worry about getting the textures the same size. There is an example scene and example scripts that demonstrate how to do this, so have a look at them: Assets/Spine Examples/Other Examples/Mix and Match Equip.unity

    However, if you want to use images of different sizes for mesh attachments, this approach will not work. If what you want to replace is something soft like clothing, it is better to prepare a skin for each piece of clothing and set the mesh vertices and weights. An example of such a setup can be found in Assets/Spine Examples/Other Examples/Mix and Match Skins.unity.

      Misaki 非常感谢,谢谢您的解答。通过您的描述我的理解是:如果是不同尺寸的图片,想实现换装是不能通过局部换装实现(比如示例场景Mix and Match)。或者就是像您说的那样准备多个皮肤达到不同尺寸的换装效果。请教您一下,我得理解对吗?

        monight Sorry if my explanation was insufficient. How to replace an image of a part of a skeleton with an image of a different size depends on whether the part to be replaced is a mesh attachment or not.

        If it is not the mesh attachment you want to replace: you can use individual images that are not included in the texture atlas at runtime and to replace the attachment.

        If it needs to be different sizes and have different meshes and weights, it is safe to create it as a skin in Spine. Multiple skins can then be combined at runtime, and textures can be repackaged to collect only the textures that are actually used.