diff --git a/spine-unity/Assets/Examples/Spine/Raptor/raptor.skel.bytes b/spine-unity/Assets/Examples/Spine/Raptor/raptor.skel.bytes new file mode 100644 index 000000000..507d86e2e Binary files /dev/null and b/spine-unity/Assets/Examples/Spine/Raptor/raptor.skel.bytes differ diff --git a/spine-unity/Assets/Examples/Spine/Raptor/raptor.skel.bytes.meta b/spine-unity/Assets/Examples/Spine/Raptor/raptor.skel.bytes.meta new file mode 100644 index 000000000..7dae281bc --- /dev/null +++ b/spine-unity/Assets/Examples/Spine/Raptor/raptor.skel.bytes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5d6edb328bfcef44a9d1bf852e5724bc +timeCreated: 1427642224 +licenseType: Free +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs index 07c439dfd..78c0b8470 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs @@ -455,8 +455,8 @@ public class SkeletonDataAssetInspector : Editor { warnings.Add("Missing Skeleton JSON"); else { - if (SpineEditorUtilities.IsSpineJSON((TextAsset)skeletonJSON.objectReferenceValue) == false) { - warnings.Add("Skeleton JSON is not a Valid JSON file"); + if (SpineEditorUtilities.IsValidSpineData((TextAsset)skeletonJSON.objectReferenceValue) == false) { + warnings.Add("Skeleton data file is not a valid JSON or binary file."); } else { bool detectedNullAtlasEntry = false; List atlasList = new List(); diff --git a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs index 0ee6a02c9..a697c8fc5 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs @@ -251,8 +251,8 @@ public class SpineEditorUtilities : AssetPostprocessor { imagePaths.Add(str); break; case ".json": - TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset)); - if (IsSpineJSON(spineJson)) { + TextAsset spineDataFile = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset)); + if (IsValidSpineData(spineDataFile)) { skeletonPaths.Add(str); } break; @@ -518,6 +518,9 @@ public class SpineEditorUtilities : AssetPostprocessor { public static List GetRequiredAtlasRegions (string jsonPath) { List requiredPaths = new List(); + // FIXME - This doesn't work for a binary skeleton file! + if (jsonPath.Contains(".skel")) return requiredPaths; + TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(jsonPath, typeof(TextAsset)); StringReader reader = new StringReader(spineJson.text); @@ -592,8 +595,14 @@ public class SpineEditorUtilities : AssetPostprocessor { return arr; } - public static bool IsSpineJSON (TextAsset asset) { - object obj = Json.Deserialize(new StringReader(asset.text)); + public static bool IsValidSpineData (TextAsset asset) { + if (asset.name.Contains(".skel")) return true; + + object obj = null; + try { + obj = Json.Deserialize(new StringReader(asset.text)); + } catch (System.Exception) { + } if (obj == null) { Debug.LogError("Is not valid JSON"); return false; diff --git a/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs b/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs index 71b006b93..d82e3eb7c 100644 --- a/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs +++ b/spine-unity/Assets/spine-unity/SkeletonDataAsset.cs @@ -97,31 +97,45 @@ public class SkeletonDataAsset : ScriptableObject { if (skeletonData != null) return skeletonData; - - SkeletonJson json; + + AttachmentLoader attachmentLoader; + float skeletonDataScale; #if !SPINE_TK2D - json = new SkeletonJson(atlasArr); - json.Scale = scale; + attachmentLoader = new AtlasAttachmentLoader(atlasArr); + skeletonDataScale = scale; #else if (spriteCollection != null) { - json = new SkeletonJson(new SpriteCollectionAttachmentLoader(spriteCollection)); - json.Scale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale) * 100f; + attachmentLoader = new SpriteCollectionAttachmentLoader(spriteCollection) + skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale) * 100f; } else { if (atlasArr.Length == 0) { Reset(); - if (!quiet) - Debug.LogError("Atlas not set for SkeletonData asset: " + name, this); + if (!quiet) Debug.LogError("Atlas not set for SkeletonData asset: " + name, this); return null; } - json = new SkeletonJson(atlasArr); - json.Scale = scale; + attachmentLoader = new AtlasAttachmentLoader(atlasArr); + skeletonDataScale = scale; } #endif - try { - skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text)); + //var stopwatch = new System.Diagnostics.Stopwatch(); + if (skeletonJSON.name.ToLower().Contains(".skel")) { + var input = new MemoryStream(skeletonJSON.bytes); + var binary = new SkeletonBinary(attachmentLoader); + binary.Scale = skeletonDataScale; + //stopwatch.Start(); + skeletonData = binary.ReadSkeletonData(input); + } else { + var input = new StringReader(skeletonJSON.text); + var json = new SkeletonJson(attachmentLoader); + json.Scale = skeletonDataScale; + //stopwatch.Start(); + skeletonData = json.ReadSkeletonData(input); + } + //stopwatch.Stop(); + //Debug.Log(stopwatch.Elapsed); } catch (Exception ex) { if (!quiet) Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);