Răsfoiți Sursa

WORKAROUND: for "ik" entry missing from exported JSON parsing fail Spine C#

Fenrisul 11 ani în urmă
părinte
comite
a4443caca4
1 a modificat fișierele cu 16 adăugiri și 14 ștergeri
  1. 16 14
      spine-csharp/src/SkeletonJson.cs

+ 16 - 14
spine-csharp/src/SkeletonJson.cs

@@ -120,23 +120,25 @@ namespace Spine {
 			}
 
 			// IK constraints.
-			foreach (Dictionary<String, Object> ikMap in (List<Object>)root["ik"]) {
-				IkConstraintData ikConstraintData = new IkConstraintData((String)ikMap["name"]);
-
-				foreach (String boneName in (List<Object>)ikMap["bones"]) {
-					BoneData bone = skeletonData.FindBone(boneName);
-					if (bone == null) throw new Exception("IK bone not found: " + boneName);
-					ikConstraintData.bones.Add(bone);
-				}
+			if(root.ContainsKey("ik")){
+				foreach (Dictionary<String, Object> ikMap in (List<Object>)root["ik"]) {
+					IkConstraintData ikConstraintData = new IkConstraintData((String)ikMap["name"]);
+
+					foreach (String boneName in (List<Object>)ikMap["bones"]) {
+						BoneData bone = skeletonData.FindBone(boneName);
+						if (bone == null) throw new Exception("IK bone not found: " + boneName);
+						ikConstraintData.bones.Add(bone);
+					}
 
-				String targetName = (String)ikMap["target"];
-				ikConstraintData.target = skeletonData.FindBone(targetName);
-				if (ikConstraintData.target == null) throw new Exception("Target bone not found: " + targetName);
+					String targetName = (String)ikMap["target"];
+					ikConstraintData.target = skeletonData.FindBone(targetName);
+					if (ikConstraintData.target == null) throw new Exception("Target bone not found: " + targetName);
 
-				ikConstraintData.bendDirection = GetBoolean(ikMap, "bendPositive", true) ? 1 : -1;
-				ikConstraintData.mix = GetFloat(ikMap, "mix", 1);
+					ikConstraintData.bendDirection = GetBoolean(ikMap, "bendPositive", true) ? 1 : -1;
+					ikConstraintData.mix = GetFloat(ikMap, "mix", 1);
 
-				skeletonData.ikConstraints.Add(ikConstraintData);
+					skeletonData.ikConstraints.Add(ikConstraintData);
+				}
 			}
 
 			// Slots.