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");
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<Atlas> atlasList = new List<Atlas>();

View File

@ -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<string> GetRequiredAtlasRegions (string jsonPath) {
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));
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;

View File

@ -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);