SkeletonDataAsset can now parse binary files.

Left benchmark code commented out.
This commit is contained in:
NathanSweet 2015-03-29 17:54:08 +02:00
parent d0625e06a0
commit 1ccef4f1cf
5 changed files with 49 additions and 18 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5d6edb328bfcef44a9d1bf852e5724bc
timeCreated: 1427642224
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -455,8 +455,8 @@ public class SkeletonDataAssetInspector : Editor {
warnings.Add("Missing Skeleton JSON"); warnings.Add("Missing Skeleton JSON");
else { else {
if (SpineEditorUtilities.IsSpineJSON((TextAsset)skeletonJSON.objectReferenceValue) == false) { if (SpineEditorUtilities.IsValidSpineData((TextAsset)skeletonJSON.objectReferenceValue) == false) {
warnings.Add("Skeleton JSON is not a Valid JSON file"); warnings.Add("Skeleton data file is not a valid JSON or binary file.");
} else { } else {
bool detectedNullAtlasEntry = false; bool detectedNullAtlasEntry = false;
List<Atlas> atlasList = new List<Atlas>(); List<Atlas> atlasList = new List<Atlas>();

View File

@ -251,8 +251,8 @@ public class SpineEditorUtilities : AssetPostprocessor {
imagePaths.Add(str); imagePaths.Add(str);
break; break;
case ".json": case ".json":
TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset)); TextAsset spineDataFile = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset));
if (IsSpineJSON(spineJson)) { if (IsValidSpineData(spineDataFile)) {
skeletonPaths.Add(str); skeletonPaths.Add(str);
} }
break; break;
@ -518,6 +518,9 @@ public class SpineEditorUtilities : AssetPostprocessor {
public static List<string> GetRequiredAtlasRegions (string jsonPath) { public static List<string> GetRequiredAtlasRegions (string jsonPath) {
List<string> requiredPaths = new List<string>(); List<string> requiredPaths = new List<string>();
// FIXME - This doesn't work for a binary skeleton file!
if (jsonPath.Contains(".skel")) return requiredPaths;
TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(jsonPath, typeof(TextAsset)); TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(jsonPath, typeof(TextAsset));
StringReader reader = new StringReader(spineJson.text); StringReader reader = new StringReader(spineJson.text);
@ -592,8 +595,14 @@ public class SpineEditorUtilities : AssetPostprocessor {
return arr; return arr;
} }
public static bool IsSpineJSON (TextAsset asset) { public static bool IsValidSpineData (TextAsset asset) {
object obj = Json.Deserialize(new StringReader(asset.text)); if (asset.name.Contains(".skel")) return true;
object obj = null;
try {
obj = Json.Deserialize(new StringReader(asset.text));
} catch (System.Exception) {
}
if (obj == null) { if (obj == null) {
Debug.LogError("Is not valid JSON"); Debug.LogError("Is not valid JSON");
return false; return false;

View File

@ -97,31 +97,45 @@ public class SkeletonDataAsset : ScriptableObject {
if (skeletonData != null) if (skeletonData != null)
return skeletonData; return skeletonData;
SkeletonJson json; AttachmentLoader attachmentLoader;
float skeletonDataScale;
#if !SPINE_TK2D #if !SPINE_TK2D
json = new SkeletonJson(atlasArr); attachmentLoader = new AtlasAttachmentLoader(atlasArr);
json.Scale = scale; skeletonDataScale = scale;
#else #else
if (spriteCollection != null) { if (spriteCollection != null) {
json = new SkeletonJson(new SpriteCollectionAttachmentLoader(spriteCollection)); attachmentLoader = new SpriteCollectionAttachmentLoader(spriteCollection)
json.Scale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale) * 100f; skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale) * 100f;
} else { } else {
if (atlasArr.Length == 0) { if (atlasArr.Length == 0) {
Reset(); Reset();
if (!quiet) if (!quiet) Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
return null; return null;
} }
json = new SkeletonJson(atlasArr); attachmentLoader = new AtlasAttachmentLoader(atlasArr);
json.Scale = scale; skeletonDataScale = scale;
} }
#endif #endif
try { 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) { } 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);