mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-27 20:21:24 +08:00
SkeletonDataAsset can now parse binary files.
Left benchmark code commented out.
This commit is contained in:
parent
d0625e06a0
commit
1ccef4f1cf
BIN
spine-unity/Assets/Examples/Spine/Raptor/raptor.skel.bytes
Normal file
BIN
spine-unity/Assets/Examples/Spine/Raptor/raptor.skel.bytes
Normal file
Binary file not shown.
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5d6edb328bfcef44a9d1bf852e5724bc
|
||||||
|
timeCreated: 1427642224
|
||||||
|
licenseType: Free
|
||||||
|
TextScriptImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -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>();
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user