Selaa lähdekoodia

[unity] Fixed unnecessary additional GC allocation of JSON deserializer in Editor (always caused allocation for version check). Closes #1608.

Harald Csaszar 5 vuotta sitten
vanhempi
commit
ed40731684

+ 14 - 15
spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataAsset.cs

@@ -114,7 +114,7 @@ namespace Spine.Unity {
 				Clear();
 				Clear();
 				return null;
 				return null;
 			}
 			}
-			
+
 			// Disabled to support attachmentless/skinless SkeletonData.
 			// Disabled to support attachmentless/skinless SkeletonData.
 			//			if (atlasAssets == null) {
 			//			if (atlasAssets == null) {
 			//				atlasAssets = new AtlasAsset[0];
 			//				atlasAssets = new AtlasAsset[0];
@@ -161,31 +161,30 @@ namespace Spine.Unity {
 			#endif
 			#endif
 
 
 			bool isBinary = skeletonJSON.name.ToLower().Contains(".skel");
 			bool isBinary = skeletonJSON.name.ToLower().Contains(".skel");
-			SkeletonData loadedSkeletonData;
-
-			#if UNITY_EDITOR
-			if (skeletonJSON) {
-				SkeletonDataCompatibility.VersionInfo fileVersion = SkeletonDataCompatibility.GetVersionInfo(skeletonJSON);
-				CompatibilityProblemInfo compatibilityProblemInfo = SkeletonDataCompatibility.GetCompatibilityProblemInfo(fileVersion);
-				if (compatibilityProblemInfo != null) {
-					SkeletonDataCompatibility.DisplayCompatibilityProblem(compatibilityProblemInfo.DescriptionString(), skeletonJSON);
-					return null;
-				}
-			}
-			#endif
+			SkeletonData loadedSkeletonData = null;
 
 
 			try {
 			try {
 				if (isBinary)
 				if (isBinary)
 					loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.bytes, attachmentLoader, skeletonDataScale);
 					loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.bytes, attachmentLoader, skeletonDataScale);
 				else
 				else
 					loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.text, attachmentLoader, skeletonDataScale);
 					loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.text, attachmentLoader, skeletonDataScale);
-
 			} catch (Exception ex) {
 			} catch (Exception ex) {
 				if (!quiet)
 				if (!quiet)
 					Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
 					Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
-				return null;
+			}
 
 
+			#if UNITY_EDITOR
+			if (loadedSkeletonData == null && !quiet && skeletonJSON != null) {
+				SkeletonDataCompatibility.VersionInfo fileVersion = SkeletonDataCompatibility.GetVersionInfo(skeletonJSON);
+				CompatibilityProblemInfo compatibilityProblemInfo = SkeletonDataCompatibility.GetCompatibilityProblemInfo(fileVersion);
+				if (compatibilityProblemInfo != null) {
+					SkeletonDataCompatibility.DisplayCompatibilityProblem(compatibilityProblemInfo.DescriptionString(), skeletonJSON);
+					return null;
+				}
 			}
 			}
+			#endif
+			if (loadedSkeletonData == null)
+				return null;
 
 
 			if (skeletonDataModifiers != null) {
 			if (skeletonDataModifiers != null) {
 				foreach (var m in skeletonDataModifiers) {
 				foreach (var m in skeletonDataModifiers) {