Explorar o código

[lua] Fixed Skin:attachAll, wrong indexing. Fixed MeshAttachment:setParentMesh, didn't set worldVerticesLength

badlogic %!s(int64=8) %!d(string=hai) anos
pai
achega
5c71fcaaf8
Modificáronse 2 ficheiros con 14 adicións e 10 borrados
  1. 13 10
      spine-lua/Skin.lua
  2. 1 0
      spine-lua/attachments/MeshAttachment.lua

+ 13 - 10
spine-lua/Skin.lua

@@ -63,21 +63,24 @@ function Skin:getAttachment (slotIndex, name)
 end
 
 function Skin:attachAll(skeleton, oldSkin)
-	local slotIndex = 0
 	for i, slot in ipairs(skeleton.slots) do
 		local slotAttachment = slot.attachment
-		if slotAttachment and slotIndex <= #oldSkin.attachments then
-			local dictionary = oldSkin.attachments[slotIndex]
-			for key, value in dictionary do
-				local skinAttachment = value
-				if slotAttachment == skinAttachment then
-					local attachment = getAttachment(slotIndex, key)
-					if attachment then slot.attachment = attachment end
-					break
+		if slotAttachment then
+			local dictionary = oldSkin.attachments[i]
+			if (dictionary) then
+				for key, value in pairs(dictionary) do
+					local skinAttachment = value
+					if slotAttachment == skinAttachment then
+						local attachment = self:getAttachment(i, key)
+						if attachment then
+							print("Set attachment " .. attachment.name .. " on slot " .. slot.data.name)
+							slot:setAttachment(attachment) 
+						end
+						break
+					end
 				end
 			end
 		end
-		slotIndex = slotIndex + 1
 	end
 end
 

+ 1 - 0
spine-lua/attachments/MeshAttachment.lua

@@ -103,6 +103,7 @@ function MeshAttachment:setParentMesh (parentMesh)
 	if parentMesh then
 		self.bones = parentMesh.bones
 		self.vertices = parentMesh.vertices
+		self.worldVerticesLength = parentMesh.worldVerticesLength
 		self.regionUVs = parentMesh.regionUVs
 		self.triangles = parentMesh.triangles
 		self.hullLength = parentMesh.hullLength