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

This commit is contained in:
Harald Csaszar 2020-01-27 12:02:16 +01:00
parent d252df7ece
commit ed40731684

View File

@ -161,10 +161,20 @@ namespace Spine.Unity {
#endif #endif
bool isBinary = skeletonJSON.name.ToLower().Contains(".skel"); bool isBinary = skeletonJSON.name.ToLower().Contains(".skel");
SkeletonData loadedSkeletonData; SkeletonData loadedSkeletonData = null;
try {
if (isBinary)
loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.bytes, attachmentLoader, skeletonDataScale);
else
loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.text, attachmentLoader, skeletonDataScale);
} catch (Exception ex) {
if (!quiet)
Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
}
#if UNITY_EDITOR #if UNITY_EDITOR
if (skeletonJSON) { if (loadedSkeletonData == null && !quiet && skeletonJSON != null) {
SkeletonDataCompatibility.VersionInfo fileVersion = SkeletonDataCompatibility.GetVersionInfo(skeletonJSON); SkeletonDataCompatibility.VersionInfo fileVersion = SkeletonDataCompatibility.GetVersionInfo(skeletonJSON);
CompatibilityProblemInfo compatibilityProblemInfo = SkeletonDataCompatibility.GetCompatibilityProblemInfo(fileVersion); CompatibilityProblemInfo compatibilityProblemInfo = SkeletonDataCompatibility.GetCompatibilityProblemInfo(fileVersion);
if (compatibilityProblemInfo != null) { if (compatibilityProblemInfo != null) {
@ -173,20 +183,9 @@ namespace Spine.Unity {
} }
} }
#endif #endif
if (loadedSkeletonData == null)
try {
if (isBinary)
loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.bytes, attachmentLoader, skeletonDataScale);
else
loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.text, attachmentLoader, skeletonDataScale);
} catch (Exception ex) {
if (!quiet)
Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
return null; return null;
}
if (skeletonDataModifiers != null) { if (skeletonDataModifiers != null) {
foreach (var m in skeletonDataModifiers) { foreach (var m in skeletonDataModifiers) {
if (m != null) m.Apply(loadedSkeletonData); if (m != null) m.Apply(loadedSkeletonData);